ank*_*kit 20 opencv image-processing computer-vision visual-c++ image-stitching
我已经计算出单应性,取出了透视变换.我能够在一个窗口中显示两个图像,但无法合并它们.这是我的示例图像 - >


我正在使用此代码的代码 - >
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);
Run Code Online (Sandbox Code Playgroud)
我认为问题出在我给予roiImgResult_right的坐标中.
输出图像是 - >
如你所见,图像没有正确合并,右侧有黑色区域.如何删除它?
eri*_*eed 17
OpenCV已经实现了图像拼接.如果使用"-D BUILD_EXAMPLES"进行编译,则可以使用binary stitching_detailed.用法很简单:./stitching_detailed img1 img2 ...
或者,您可以使用拼接器类(此处的示例):
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"
using namespace std;
using namespace cv;
bool try_use_gpu = false;
string result_name = "result.jpg";
int main(int argc, char* argv[])
{
vector<Mat> imgs;
// add images...
Mat pano;
Stitcher stitcher = Stitcher::createDefault(try_use_gpu);
stitcher.stitch(imgs, pano);
imwrite(result_name, pano);
}
Run Code Online (Sandbox Code Playgroud)