Note that there are some explanatory texts on larger screens.

plurals
  1. PODisparity map opencv
    text
    copied!<p>I am trying to make disparity map. I saw the sample code provided by opencv 'stereo_match.cpp' and I wrote the following code. But when I display the left and right image after rectification and remapping the image is black. Can anybody tell me where am I doing wrong?</p> <pre><code>int main(int argc, char* argv[]) { Mat img1, img2, g1, g2; Mat disp, disp8; char* method ="SGBM"; float scale = 1.f; // don't know why //img1 = imread(argv[1]); //img2 = imread(argv[2]); img1=imread("l1.jpg"); img2=imread("r1.jpg"); cvtColor(img1, g1, CV_BGR2GRAY); cvtColor(img2, g2, CV_BGR2GRAY); Size img_size = img1.size(); Rect roi1, roi2; Mat Q; /*reading parameters of ectrinssic &amp; intrinssic file*/ const char* intrinsic_filename="intrinsics"; Mat img1r, img2r; if( intrinsic_filename ) { FileStorage fs("intrinsics.yml", cv::FileStorage::READ); if(!fs.isOpened()) { printf("Failed to open file %s\n"); return -1; } Mat M1, D1, M2, D2; fs["M1"] &gt;&gt; M1; fs["D1"] &gt;&gt; D1; fs["M2"] &gt;&gt; M2; fs["D2"] &gt;&gt; D2; M1 *= scale; M2 *= scale; fs.open("extrinsics.yml", cv::FileStorage::READ); if(!fs.isOpened()) { printf("Failed to open file %s\n"); return -1; } Mat R, T, R1, P1, R2, P2; fs["R"] &gt;&gt; R; fs["T"] &gt;&gt; T; stereoRectify( M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q, CALIB_ZERO_DISPARITY, -1, img_size, &amp;roi1, &amp;roi2 ); Mat map11, map12, map21, map22; initUndistortRectifyMap(M1, D1, R1, P1, img_size, CV_16SC2, map11, map12); initUndistortRectifyMap(M2, D2, R2, P2, img_size, CV_16SC2, map21, map22); remap(img1, img1r, map11, map12, INTER_LINEAR); remap(img2, img2r, map21, map22, INTER_LINEAR); // img1 = img1r; // img2 = img2r; imshow("left1", img1r); imshow("left2", img2r); } } </code></pre> <p><img src="https://i.stack.imgur.com/MBdlt.png" alt="output left image">} <img src="https://i.stack.imgur.com/DSgd0.png" alt="output right image"> ![original left image][3]</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload