[英]OpenCV stereo matching inverted output
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 这些是我正在使用的图像4.png和1.png
And the output I get is this: 我得到的输出是这样的:
Am I doing something wrong? 难道我做错了什么? Thanks
谢谢
I suppose you confused left and right. 我想你左右混淆了。 4.png should be right/img2 and 1.png left/img1.
4.png应该在右边/ img2,而1.png在左边/ img1。 (The picture with the object to the right is as seen from the left camera and vice versa.)
(带有右侧对象的图片是从左侧相机看到的,反之亦然。)
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. 好吧,我通过使用DainiusŠaltenis的建议进行了工作,方法是在opencv中使用按位not运算符反转图像,并删除所有纯白色像素。
//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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.