我正在尝试制作一个程序,该程序可以从两张相同的图片中查找同构坐标,但是要旋转或平移对象,然后拍摄第一张图片并将其覆盖在第二张图片上。

问题是,我遇到矩阵错误,因为我具有不同的矩阵大小。

我已经找到了解决方案,我需要将其应用于旋转和平移以在第二张图片上获得第一张图片(值,我必须将其应用于第二张矩阵)

这是我的代码:

    Size size(image2.cols, image2.rows);

    Mat dest = cv::Mat::zeros(image2.rows, image2.cols, CV_32FC2);

    warpAffine(image2, dest, t, size);

    namedWindow("manipulated img", CV_WINDOW_NORMAL);
    imshow("manipulated img", dest);

    Mat output;

    cout << image1.size() << endl;
    cout << dest.size() << endl;

    bitwise_and(dest, image1, output);

    //subtract(dest, image1, output);
    namedWindow("output img", CV_WINDOW_NORMAL);
    imshow("output img", output);

我收到以下错误:
> [3722 x 2937]
> [3722 x 2932]
> OpenCV Error: Sizes of input arguments do
> not match (The operation is neither 'a rray op array' (where arrays
> have the same size and type), nor 'array op scalar' , nor 'scalar op
> array') in cv::binary_op, file C:\builds\master_PackSlave-win32
> -vc12-shared\opencv\modules\core\src\arithm.cpp, line 1573

我想我知道问题是什么,但我不知道解决方案是什么。

矩阵大小不同
image1.size() = [3722 x 2937]
dest.size() = [3722 x 2932]

我该怎么办才能解决这个问题?

最佳答案

我怀疑您只需要使dest等于image1的大小,而不是image2warpAffine有很好的机会应对。

09-30 15:33
查看更多