I am trying to get stereo matching working with artificial depth images. The matching seems to come out good (no occlusions) but inverted( black = close, white = far)
int main()
{
Mat img1, img2, g1, g2;
Mat disp, disp8;
img1 = imread("W:/GoogleDrive/UDK/Croped_left/4.png");
img2 = imread("W:/GoogleDrive/UDK/Croped_left/1.png");
cvtColor(img1, g1, CV_BGR2GRAY);
cvtColor(img2, g2, CV_BGR2GRAY);
StereoBM sbm;
sbm.state->SADWindowSize = 9;
sbm.state->numberOfDisparities = 16;
sbm.state->preFilterSize = 5;
sbm.state->preFilterCap = 61;
sbm.state->minDisparity = -39;
sbm.state->textureThreshold = 507;
sbm.state->uniquenessRatio = 0;
sbm.state->speckleWindowSize = 0;
sbm.state->speckleRange = 8;
sbm.state->disp12MaxDiff = 1;
sbm(g1, g2, disp);
normalize(disp, disp8, 0, 255, CV_MINMAX, CV_8U);
imshow("left", img1);
imshow("right", img2);
imshow("disp", disp8);
waitKey(0);
return(0);
}
These are the images I am using 4.png and 1.png
Am I doing something wrong? Thanks
Well I did a work around using the suggestion by Dainius Ĺ altenis by inverting the image using the bitwise not operator in opencv and the removing all the pure white pixels.
//Bitwise_not to invert the images
bitwise_not(disp8, disp8);
//Loop through the images find all white pixels and replace with black
for (int i = 0; i < disp8.rows; i++)
for (int j = 0; j < disp8.cols; j++)
if (disp8.at<uchar>(i, j) > 254)
disp8.at<uchar>(i, j) = 0;