我已经计算出单应性矩阵,进行了透视变换。我能够在一个窗口中显示两个图像,但无法将它们合并。这是我的样例图像:
我正在使用的代码是这个:
cv::warpPerspective(image2,warpresult2,homography,cv::Size(2*image2.cols,image2.rows));
Mat imgResult(image1.rows,2*image1.cols,image1.type());
Mat roiImgResult_Left = imgResult(Rect(0,0,image1.cols,image1.rows));
Mat roiImgResult_Right = imgResult(Rect(image1.cols,0,image2.cols,image2.rows));
Mat roiImg1 = image1(Rect(0,0,image1.cols,image1.rows));
Mat roiImg2 = warpresult2(Rect(0,0,image2.cols,image2.rows));
roiImg1.copyTo(roiImgResult_Left); //Img1 will be on the left of imgResult
roiImg2.copyTo(roiImgResult_Right); //Img2 will be on the right of imgResult
imshow("Finalimg",imgResult);
imwrite("C:\\OpenCv_Projects\\outputimage.jpg",imgResult);
cvWaitKey(0);
我认为问题在于我给定的roiImgResult_right坐标。
输出图像如下-> 正如您所看到的,图像没有正确合并,并且右侧有黑色区域。如何去除它?