简体   繁体   English

带有openCV的立体声

[英]Stereo with openCV

I try to find the distance between camera and an object,so I use two different cameras (stereo). 我试图找到相机和物体之间的距离,所以我使用了两个不同的相机(立体声)。 I use the program in opencv samples . 我在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;
}

my problem is that I can't find the depth Z between object and camera 我的问题是我找不到物体和相机之间的深度Z

也许尝试使用cv :: reprojectImageTo3D()cv :: perspectiveTransform()将视差转换为3D点以获取稀疏点集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM