我正在尝试使用人工深度图像进行立体匹配。 匹配似乎很好(没有遮挡)但反转(黑色=近,白=远)
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);
}
我做错了吗? 感谢
答案 0 :(得分:0)
我想你左右混淆了。 4.png应该是正确的/ img2和1.png左/ img1。 (右侧对象的图片从左侧相机看,反之亦然。)
答案 1 :(得分:0)
我做了一个工作,使用DainiusŠaltenis的建议,通过在opencv中使用按位非运算符反转图像并删除所有纯白像素。
//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;