我试图找到相机和物体之间的距离,所以我使用两个不同的相机(立体声)。我在opencv样本中使用该程序。
#include "opencv2/core/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv2/contrib/contrib.hpp"
#include <stdio.h>
#include <string.h>
#include<iostream>
using namespace cv;
const char *windowDisparity = "Disparity";
int main( )
{
Size S(640,360);
Mat threshold2,threshold1;
Mat imgLeft = imread( "lift.jpg", CV_LOAD_IMAGE_GRAYSCALE );
Mat imgRight = imread("right.jpg", CV_LOAD_IMAGE_GRAYSCALE );
resize(imgLeft,imgLeft,S);
Mat imgDisparity16S = Mat( imgLeft.rows, imgLeft.cols, CV_16S );
Mat imgDisparity8U = Mat( imgRight.rows, imgRight.cols, CV_8UC1 );
int ndisparities = 16*5;
int SADWindowSize = 21;
StereoBM sbm( StereoBM::BASIC_PRESET,ndisparities,SADWindowSize );
sbm( imgLeft, imgRight, imgDisparity16S, CV_16S );
double minVal; double maxVal;
minMaxLoc( imgDisparity16S, &minVal, &maxVal );
printf("Min disp: %f Max value: %f \n", minVal, maxVal);
imgDisparity16S.convertTo( imgDisparity8U, CV_8UC1, 255/(maxVal - minVal));
namedWindow( windowDisparity, WINDOW_NORMAL );
imshow( windowDisparity, imgDisparity8U );
imshow( "left", imgLeft );
imshow( "right", imgRight );
imwrite("SBM_sample.png", imgDisparity16S);
waitKey(0);
return 0;
}
我的问题是我无法找到物体和相机之间的深度Z