pointcloud生成的问题

时间:2014-04-25 08:27:44

标签: java opencv computer-vision

在我的结构形式运动方法中,我在从视差图像创建点云时遇到一些奇怪的问题(我猜这也不正确)

在我向您展示源代码之前,这里是输入图像,校正后的图像,视差图像和点云。

左图 Left image

正确的形象 Right image

左转 enter image description here

纠正权利 enter image description here

视差图像 enter image description here

点云 https://drive.google.com/file/d/0Bx9OKnxaua8kcGFULW5raE1pdVU/edit?usp=sharing

由于经过纠正的图像非常安静(imho),我不打算发布整改代码。 以下是我创建视差图像的方法:

private Mat createDisparityMap(Mat rectLeft, Mat rectRight){    

    // Converts the images to a proper type for stereoMatching
    Mat left = new Mat();
    Mat right = new Mat();

    Imgproc.cvtColor(rectLeft, left, Imgproc.COLOR_BGR2GRAY);
    Imgproc.cvtColor(rectRight, right, Imgproc.COLOR_BGR2GRAY);

    // Create a new image using the size and type of the left image
    Mat disparity = new Mat(left.size(), left.type());

    int numDisparity = (int)(left.size().width/8); 

    StereoSGBM stereoAlgo = new StereoSGBM(
            0,    // min DIsparities
            numDisparity, // numDisparities
            11,   // SADWindowSize
            2*11*11,   // 8*number_of_image_channels*SADWindowSize*SADWindowSize   // p1
            5*11*11,  // 8*number_of_image_channels*SADWindowSize*SADWindowSize  // p2

            -1,   // disp12MaxDiff
            63,   // prefilterCap
            10,   // uniqueness ratio
            0, // sreckleWindowSize
            32, // spreckle Range
            false); // full DP
    // create the DisparityMap - SLOW: O(Width*height*numDisparity)
    stereoAlgo.compute(left, right, disparity);

    Core.normalize(disparity, disparity, 0, 256, Core.NORM_MINMAX);

    return disparity;
}

以下是我如何使用reprojectImageTo3D创建pointcloud,然后将其另存为obj文件。

private Mat reprojectDisparityImageTo3D(Mat disparity, Mat Q){
    publishProgress("reprojecting");
    Mat outputImage = new Mat();        
    Calib3d.reprojectImageTo3D(disparity, outputImage, Q);
    return outputImage;
}


private void savePointCloud(Mat pcl){
    publishProgress("Saving .obj file");
    try {
        // open the file for writing to (.obj file)
        File datei = new File(activity.getProjectFolder()+"/../", "poincloud.obj");
        if(!datei.exists())
                datei.createNewFile();

        FileOutputStream outStream = new FileOutputStream(datei);
        OutputStreamWriter oStream = new OutputStreamWriter(outStream);

        for(int w = 0; w < pcl.size().width; w++){
            for(int h = 0; h < pcl.size().height; h++){
                double[] values = new double[1];
                values = pcl.get(w, h);
                if(values != null)
                    if(values.length >= 3)
                        oStream.append("v " + String.valueOf(values[0]) + " " +String.valueOf(values[1]) + " " +String.valueOf(values[2]) + " " +  "\n");
            }
        }
        oStream.close();
        outStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }


}

有人可以帮助我,并指出为什么结果看起来像?我假设了以下内容:

  • 视差图更密集,错误更少。看起来像相机附近的物体正在产生较小的差异......

  • 重新投影的图片/ pointcloud应代表场景,以便我能够看到&#34;瓶子或者&#34; oster-minis&#34;不同的深度。

0 个答案:

没有答案