Simple binocular vision test

Source: Internet
Author: User

Opencv provides a function for binocular vision to detect distance information. We tried to use two cameras to obtain two sets of images for testing. When the background is simple and the target is small, the results are better. (They are the left image and the right image respectively, and the obtained depth image)

Using a long object to test the depth is ineffective. As follows:

The difficulty is that the two cameras, even in the same model and lens, have slight differences in the color of the images, resulting in poor performance.

However, using a camera to pan the left and right results in better results. As an image provided by opencv, the effect is better.


# Include "stdafx. H"
# Include <iostream>
# Include <string. h>
# Include <cxcore. h>
# Include <cv. h>
# Include <cvaux. h>
# Include # Include <fstream>

Iplimage * image = 0; // Original Image

Using namespace STD;

Int main (INT argc, char * argv [])

Iplimage * srcleft = cvloadimage ("left.jpg", 1 );
Iplimage * srcright = cvloadimage ("right.jpg", 1 );
Iplimage * leftimage = cvcreateimage (cvgetsize (srcleft), ipl_depth_8u, 1 );
Iplimage * rightimage = cvcreateimage (cvgetsize (srcright), ipl_depth_8u, 1 );
Iplimage * depthimage = cvcreateimage (cvgetsize (srcright), ipl_depth_8u, 1 );

Cvcvtcolor (srcleft, leftimage, cv_bgr2gray );
Cvcvtcolor (srcright, rightimage, cv_bgr2gray );

Cvfindstereocorresponsor (leftimage, rightimage, cv_disparity_birchfield, depthimage, 50, 15, 3, 6, 8, 15 );

Cvnamedwindow ("win1", 1 );
Cvnamedwindow ("win2", 1 );
Cvnamedwindow ("win3", 1 );

Cvnormalize (depthimage, depthimage, 0,255, cv_minmax, 0 );

For (;;)
Cvshowimage ("win1", depthimage );
Cvshowimage ("win2", srcleft );
Cvshowimage ("win3", srcright );
If (cvwaitkey (20) = 27) break;

Return 0;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.