Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Plane Gray Disparity Map by StereoSGBM

Hey there,

I am moving my code from python to C++ but run into troubles when computing a disparity map with StereoSGBM -from my python version I do know its not that smooth at all.

Here is some code:

const std::string filename_1 = "i1.png";
const std::string filename_2 = "i2.png";
cv::Mat image_1_grayscale;
cv::cvtColor(cv::imread(filename_1), image_1_grayscale, cv::COLOR_BGR2GRAY);
cv::Mat image_2_grayscale;
cv::cvtColor(cv::imread(filename_2), image_2_grayscale, cv::COLOR_BGR2GRAY);

cv::Ptr<cv::StereoSGBM> sgbm = cv::StereoSGBM::create();

cv::Mat disp;
sgbm->compute(image_1_grayscale, image_2_grayscale, disp);

if (!disp.empty()){
    printf("%i", disp.cols);
    printf("%i", disp.rows);
    printf("%d", disp.at<double>(0, 0));
    printf("%d", disp.at<double>(1, 1));
    cv::imshow("normal", disp);
    cv::waitKey();
    cv::destroyAllWindows();
   }

I checked size of disp after computation and it does change to the size of the images, but with odd values (-983056) written in it.

Whats wrong in this snippet?

Plane Gray Disparity Map by StereoSGBM

Hey there,

I am moving my code from python to C++ but run into troubles when computing a disparity map with StereoSGBM . THe map is all the same value -from my python version I do know its not that smooth at all.

Here is some code:

const std::string filename_1 = "i1.png";
const std::string filename_2 = "i2.png";
cv::Mat image_1_grayscale;
cv::cvtColor(cv::imread(filename_1), image_1_grayscale, cv::COLOR_BGR2GRAY);
cv::Mat image_2_grayscale;
cv::cvtColor(cv::imread(filename_2), image_2_grayscale, cv::COLOR_BGR2GRAY);

cv::Ptr<cv::StereoSGBM> sgbm = cv::StereoSGBM::create();

cv::Mat disp;
sgbm->compute(image_1_grayscale, image_2_grayscale, disp);

if (!disp.empty()){
    printf("%i", disp.cols);
    printf("%i", disp.rows);
    printf("%d", disp.at<double>(0, 0));
    printf("%d", disp.at<double>(1, 1));
    cv::imshow("normal", disp);
    cv::waitKey();
    cv::destroyAllWindows();
   }

I checked size of disp after computation and it does change to the size of the images, but with odd values (-983056) written in it.

Whats wrong in this snippet?

Plane Gray Disparity Map by StereoSGBM

Hey there,

I am moving my code from python to C++ but run into troubles when computing a disparity map with StereoSGBM. THe The map is all the same value -from my python version I do know its not that smooth at all.

Here is some code:

const std::string filename_1 = "i1.png";
const std::string filename_2 = "i2.png";
cv::Mat image_1_grayscale;
cv::cvtColor(cv::imread(filename_1), image_1_grayscale, cv::COLOR_BGR2GRAY);
cv::Mat image_2_grayscale;
cv::cvtColor(cv::imread(filename_2), image_2_grayscale, cv::COLOR_BGR2GRAY);

cv::Ptr<cv::StereoSGBM> sgbm = cv::StereoSGBM::create();

cv::Mat disp;
sgbm->compute(image_1_grayscale, image_2_grayscale, disp);

if (!disp.empty()){
    printf("%i", disp.cols);
    printf("%i", disp.rows);
    printf("%d", disp.at<double>(0, 0));
    printf("%d", disp.at<double>(1, 1));
    cv::imshow("normal", disp);
    cv::waitKey();
    cv::destroyAllWindows();
   }

I checked size of disp after computation and it does change to the size of the images, but with odd values (-983056) written in it.

Whats wrong in this snippet?

Plane Gray Disparity Map by StereoSGBM

Hey there,

I am moving my code from python to C++ but run into troubles when computing a disparity map with StereoSGBM. The map is all has the same value values everywhere -from my python version I do know its not that smooth at all.

Here is some code:

const std::string filename_1 = "i1.png";
const std::string filename_2 = "i2.png";
cv::Mat image_1_grayscale;
cv::cvtColor(cv::imread(filename_1), image_1_grayscale, cv::COLOR_BGR2GRAY);
cv::Mat image_2_grayscale;
cv::cvtColor(cv::imread(filename_2), image_2_grayscale, cv::COLOR_BGR2GRAY);

cv::Ptr<cv::StereoSGBM> sgbm = cv::StereoSGBM::create();

cv::Mat disp;
sgbm->compute(image_1_grayscale, image_2_grayscale, disp);

if (!disp.empty()){
    printf("%i", disp.cols);
    printf("%i", disp.rows);
    printf("%d", disp.at<double>(0, 0));
    printf("%d", disp.at<double>(1, 1));
    cv::imshow("normal", disp);
    cv::waitKey();
    cv::destroyAllWindows();
   }

I checked size of disp after computation and it does change to the size of the images, but with odd values (-983056) written in it. is of type CV_16SC1 and every value is -16.

Whats wrong in this snippet?