我已经计算了单应性,去掉了透视变换,.I能够在一个窗口中显示两个图像,但无法合并them.Here是我的示例图像->
我使用的代码是->
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的坐标上。
输出图像为->
如你所见,图像没有正确合并,右侧side.how上有黑色区域,是否也要删除?
发布于 2016-06-25 16:15:52
您可以使用addWeighted()
函数轻松地混合两个图像。但要求是你必须制作相同大小的图像。
如果图像大小不同,首先调整两个图像的大小。然后调用以下函数。
addWeighted(src1, alpha, src2, beta, 0.0, dst);
声明两个Mat
文件
src1 = imread("c://test//blend1.jpg");
src2 = imread("c://test//blend2.jpg");
还要声明alpha
和beta
,然后将结果保存到Mat dst
。
您还可以在此处获取详细信息Blending of Images using Opencv
https://stackoverflow.com/questions/10256802
复制相似问题