Reconstruction of three-dimensional point cloud from binocular stereo disparity map with vs+opencv3.1

Source: Internet
Author: User
Fundamentals

For detailed principles, please read this article http://www.360doc.com/content/14/0205/15/10724725_349968116.shtml.



Basic Process

Code

This code run needs to be configured on the VS opencv3.1+openni+pcl,opencv3.1 configuration can find a lot of information on the Internet, Openni and PCL configuration can take a look at a blog post http://blog.csdn.net/ u014283958/article/details/52599457
Here's the code:

by Shuishui Shiwenjun 20160926 #include <pcl/visualization/cloud_viewer.h> #include <iostream> #include &
lt;pcl/io/io.h> #include <pcl/io/pcd_io.h> #include <opencv2/opencv.hpp> usingnamespace CV;
USINGNAMESPACESTD;
 
UsingNamespace PCL;
int user_data;
Camera reference, according to the input changes constdouble u0 = 1329.49/4;//because the back resize into the original 1/4 so some parameters to reduce the same multiple constdouble V0 = 954.485/4;
Constdouble FX = 6872.874/4;
constdouble fy = 6872.874/4;
Constdouble Tx = 174.724;
 
Constdouble doffs = 293.97/4;
 
void Vieweroneoff (visualization::P clvisualizer& Viewer) {viewer.setbackgroundcolor (0.0, 0.0, 0.0);}
   int main () {pointcloud<pointxyzrgb>cloud_a;
    POINTCLOUD&LT;POINTXYZRGB&GT::P tr Cloud (new pointcloud<pointxyzrgb>);
    Mat Color1 = Imread ("Im0.png");
    Mat depth = Imread ("Sword1_perfect_d.png");
    Resize//color1.resize ();
    Mat color;
    Resize (Color1, Color,size (COLOR1.COLS/4,COLOR1.ROWS/4), 0, 0,cv_inter_linear); Imshow ("H",color);
    Waitkey (0);
    int rowNumber = color.rows;
    int colnumber = Color.cols;
    Cloud_a.height = RowNumber;
   Cloud_a.width = Colnumber;
    Cloud_a.points.resize (Cloud_a.width * cloud_a.height);
            for (Unsignedint u = 0, u < rowNumber; ++u) {for (Unsignedint v = 0; v < colnumber; ++v) {
            /*unsigned intnum = rownumber*colnumber-(U*colnumber + V) -1;*/unsignedint num = u*colnumber + V;
 
            Double Xw = 0, Yw = 0, Zw = 0;
            Zw = FX*TX/((double) depth.at<vec3b> (U, v) [0]) + doffs);
            Xw = (v+1-u0) * ZW/FX;
            Yw = (u+1-v0) * ZW/FY;
            Cloud_a.points[num].b =color.at<vec3b> (U, v) [0];
            CLOUD_A.POINTS[NUM].G =color.at<vec3b> (U, v) [1];
            CLOUD_A.POINTS[NUM].R =color.at<vec3b> (U, v) [2];
            Cloud_a.points[num].x =xw;
            Cloud_a.points[num].y =yw;
        Cloud_a.points[num].z =ZW; }} *cloud= cloud_a;
    Visualization::cloudviewerviewer ("Cloud Viewer");
   Viewer.showcloud (Cloud);
    Viewer.runonvisualizationthreadonce (Vieweroneoff);
    while (!viewer.wasstopped ()) {user_data = 9;
} Return0; }
Effect Diagram

Input:
"Im0.png" can be downloaded from http://vision.middlebury.edu/stereo/data/scenes2014/datasets/Sword1-perfect/im0.png;

"Sword1_perfect_d.png"

Output:
Point Cloud screenshot 1

Point Cloud screenshot 2



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: info-contact@alibabacloud.com 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.