mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge branch 4.x
This commit is contained in:
@@ -226,7 +226,7 @@ static void saveCameraParams( const string& filename,
|
||||
|
||||
if( flags != 0 )
|
||||
{
|
||||
sprintf( buf, "flags: %s%s%s%s",
|
||||
snprintf( buf, sizeof(buf), "flags: %s%s%s%s",
|
||||
flags & CALIB_USE_INTRINSIC_GUESS ? "+use_intrinsic_guess" : "",
|
||||
flags & CALIB_FIX_ASPECT_RATIO ? "+fix_aspectRatio" : "",
|
||||
flags & CALIB_FIX_PRINCIPAL_POINT ? "+fix_principal_point" : "",
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/imgcodecs.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
int main(int /*argc*/, const char** /* argv */ )
|
||||
{
|
||||
Mat framebuffer( 160 * 2, 160 * 5, CV_8UC3, cv::Scalar::all(255) );
|
||||
|
||||
Mat img( 160, 160, CV_8UC3, cv::Scalar::all(255) );
|
||||
|
||||
// Create test image.
|
||||
{
|
||||
const Point center( img.rows / 2 , img.cols /2 );
|
||||
|
||||
for( int radius = 5; radius < img.rows ; radius += 3 )
|
||||
{
|
||||
cv::circle( img, center, radius, Scalar(255,0,255) );
|
||||
}
|
||||
cv::rectangle( img, Point(0,0), Point(img.rows-1, img.cols-1), Scalar::all(0), 2 );
|
||||
}
|
||||
|
||||
// Draw original image(s).
|
||||
int top = 0; // Upper images
|
||||
{
|
||||
for( int left = 0 ; left < img.rows * 5 ; left += img.rows ){
|
||||
Mat roi = framebuffer( Rect( left, top, img.rows, img.cols ) );
|
||||
img.copyTo(roi);
|
||||
|
||||
cv::putText( roi, "original", Point(5,15), FONT_HERSHEY_SIMPLEX, 0.5, Scalar::all(0), 2, 4, false );
|
||||
}
|
||||
}
|
||||
|
||||
// Draw lossy images
|
||||
top += img.cols; // Lower images
|
||||
{
|
||||
struct test_config{
|
||||
string comment;
|
||||
uint32_t sampling_factor;
|
||||
} config [] = {
|
||||
{ "411", IMWRITE_JPEG_SAMPLING_FACTOR_411 },
|
||||
{ "420", IMWRITE_JPEG_SAMPLING_FACTOR_420 },
|
||||
{ "422", IMWRITE_JPEG_SAMPLING_FACTOR_422 },
|
||||
{ "440", IMWRITE_JPEG_SAMPLING_FACTOR_440 },
|
||||
{ "444", IMWRITE_JPEG_SAMPLING_FACTOR_444 },
|
||||
};
|
||||
|
||||
const int config_num = 5;
|
||||
|
||||
int left = 0;
|
||||
|
||||
for ( int i = 0 ; i < config_num; i++ )
|
||||
{
|
||||
// Compress images with sampling factor parameter.
|
||||
vector<int> param;
|
||||
param.push_back( IMWRITE_JPEG_SAMPLING_FACTOR );
|
||||
param.push_back( config[i].sampling_factor );
|
||||
vector<uint8_t> jpeg;
|
||||
(void) imencode(".jpg", img, jpeg, param );
|
||||
|
||||
// Decompress it.
|
||||
Mat jpegMat(jpeg);
|
||||
Mat lossy_img = imdecode(jpegMat, -1);
|
||||
|
||||
// Copy into framebuffer and comment
|
||||
Mat roi = framebuffer( Rect( left, top, lossy_img.rows, lossy_img.cols ) );
|
||||
lossy_img.copyTo(roi);
|
||||
cv::putText( roi, config[i].comment, Point(5,155), FONT_HERSHEY_SIMPLEX, 0.5, Scalar::all(0), 2, 4, false );
|
||||
|
||||
left += lossy_img.rows;
|
||||
}
|
||||
}
|
||||
|
||||
// Output framebuffer(as lossless).
|
||||
imwrite( "imgcodecs_jpeg_samplingfactor_result.png", framebuffer );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -470,7 +470,7 @@ int main(int argc, char** argv)
|
||||
outbarename = strrchr(outprefix.c_str(), '/');
|
||||
const char* tmp = strrchr(outprefix.c_str(), '\\');
|
||||
char cmd[1000];
|
||||
sprintf(cmd, "mkdir %s", outprefix.c_str());
|
||||
snprintf(cmd, sizeof(cmd), "mkdir %s", outprefix.c_str());
|
||||
if( tmp && tmp > outbarename )
|
||||
outbarename = tmp;
|
||||
if( outbarename )
|
||||
@@ -569,7 +569,7 @@ int main(int argc, char** argv)
|
||||
char path[1000];
|
||||
for(;frameIdx < maxFrameIdx;frameIdx++)
|
||||
{
|
||||
sprintf(path, "%s%04d.jpg", outprefix.c_str(), frameIdx);
|
||||
snprintf(path, sizeof(path), "%s%04d.jpg", outprefix.c_str(), frameIdx);
|
||||
FILE* f = fopen(path, "rb");
|
||||
if( !f )
|
||||
break;
|
||||
|
||||
@@ -60,7 +60,7 @@ int main( void )
|
||||
|
||||
//![create_trackbar]
|
||||
char TrackbarName[50];
|
||||
sprintf( TrackbarName, "Alpha x %d", alpha_slider_max );
|
||||
snprintf( TrackbarName, sizeof(TrackbarName), "Alpha x %d", alpha_slider_max );
|
||||
createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar );
|
||||
//![create_trackbar]
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ int main( int argc, char** argv )
|
||||
|
||||
/// Create Trackbars for Thresholds
|
||||
char thresh_label[50];
|
||||
sprintf( thresh_label, "Thres: %d + input", min_threshold );
|
||||
snprintf( thresh_label, sizeof(thresh_label), "Thres: %d + input", min_threshold );
|
||||
|
||||
namedWindow( standard_name, WINDOW_AUTOSIZE );
|
||||
createTrackbar( thresh_label, standard_name, &s_trackbar, max_trackbar, Standard_Hough);
|
||||
|
||||
@@ -110,9 +110,18 @@ void poseEstimationFromCoplanarPoints(const string &imgPath, const string &intri
|
||||
|
||||
//! [polar-decomposition-of-the-rotation-matrix]
|
||||
cout << "R (before polar decomposition):\n" << R << "\ndet(R): " << determinant(R) << endl;
|
||||
Mat W, U, Vt;
|
||||
Mat_<double> W, U, Vt;
|
||||
SVDecomp(R, W, U, Vt);
|
||||
R = U*Vt;
|
||||
double det = determinant(R);
|
||||
if (det < 0)
|
||||
{
|
||||
Vt.at<double>(2,0) *= -1;
|
||||
Vt.at<double>(2,1) *= -1;
|
||||
Vt.at<double>(2,2) *= -1;
|
||||
|
||||
R = U*Vt;
|
||||
}
|
||||
cout << "R (after polar decomposition):\n" << R << "\ndet(R): " << determinant(R) << endl;
|
||||
//! [polar-decomposition-of-the-rotation-matrix]
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
int main()
|
||||
{
|
||||
VideoCapture obsensorCapture(0, CAP_OBSENSOR);
|
||||
if(!obsensorCapture.isOpened()){
|
||||
std::cerr << "Failed to open obsensor capture! Index out of range or no response from device";
|
||||
return -1;
|
||||
}
|
||||
|
||||
double fx = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_FX);
|
||||
double fy = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_FY);
|
||||
double cx = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_CX);
|
||||
double cy = obsensorCapture.get(CAP_PROP_OBSENSOR_INTRINSIC_CY);
|
||||
std::cout << "obsensor camera intrinsic params: fx=" << fx << ", fy=" << fy << ", cx=" << cx << ", cy=" << cy << std::endl;
|
||||
|
||||
Mat image;
|
||||
Mat depthMap;
|
||||
Mat adjDepthMap;
|
||||
while (true)
|
||||
{
|
||||
// Grab depth map like this:
|
||||
// obsensorCapture >> depthMap;
|
||||
|
||||
// Another way to grab depth map (and bgr image).
|
||||
if (obsensorCapture.grab())
|
||||
{
|
||||
if (obsensorCapture.retrieve(image, CAP_OBSENSOR_BGR_IMAGE))
|
||||
{
|
||||
imshow("RGB", image);
|
||||
}
|
||||
|
||||
if (obsensorCapture.retrieve(depthMap, CAP_OBSENSOR_DEPTH_MAP))
|
||||
{
|
||||
normalize(depthMap, adjDepthMap, 0, 255, NORM_MINMAX, CV_8UC1);
|
||||
applyColorMap(adjDepthMap, adjDepthMap, COLORMAP_JET);
|
||||
imshow("DEPTH", adjDepthMap);
|
||||
}
|
||||
|
||||
// depth map overlay on bgr image
|
||||
static const float alpha = 0.6f;
|
||||
if (!image.empty() && !depthMap.empty())
|
||||
{
|
||||
normalize(depthMap, adjDepthMap, 0, 255, NORM_MINMAX, CV_8UC1);
|
||||
cv::resize(adjDepthMap, adjDepthMap, cv::Size(image.cols, image.rows));
|
||||
for (int i = 0; i < image.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < image.cols; j++)
|
||||
{
|
||||
cv::Vec3b& outRgb = image.at<cv::Vec3b>(i, j);
|
||||
uint8_t depthValue = 255 - adjDepthMap.at<uint8_t>(i, j);
|
||||
if (depthValue != 0 && depthValue != 255)
|
||||
{
|
||||
outRgb[0] = (uint8_t)(outRgb[0] * (1.0f - alpha) + depthValue * alpha);
|
||||
outRgb[1] = (uint8_t)(outRgb[1] * (1.0f - alpha) + depthValue * alpha);
|
||||
outRgb[2] = (uint8_t)(outRgb[2] * (1.0f - alpha) + depthValue * alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
imshow("DepthToColor", image);
|
||||
}
|
||||
image.release();
|
||||
depthMap.release();
|
||||
}
|
||||
|
||||
if (pollKey() >= 0)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace {
|
||||
case 27: //escape key
|
||||
return 0;
|
||||
case ' ': //Save an image
|
||||
sprintf(filename,"filename%.3d.jpg",n++);
|
||||
snprintf(filename,sizeof(filename),"filename%.3d.jpg",n++);
|
||||
imwrite(filename,frame);
|
||||
cout << "Saved " << filename << endl;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user