opencv:将图像缝合在一起

opencv:将图像缝合在一起,opencv,Opencv,我试图将两幅图像缝合在一起,但在最终图像中只能看到第一幅。 这是我的密码: Mat result(1000, 1000, CV_8UC3); Mat firstPart = result(Rect(0, 0, image1.cols, image1.rows)); Mat secondPart = result(Rect(deltaX, deltaY, image2.cols+deltaX, image2.rows+deltaY)); image1.copyTo(firstPart); imag

我试图将两幅图像缝合在一起,但在最终图像中只能看到第一幅。 这是我的密码:

Mat result(1000, 1000, CV_8UC3);
Mat firstPart = result(Rect(0, 0, image1.cols, image1.rows));
Mat secondPart = result(Rect(deltaX, deltaY, image2.cols+deltaX, image2.rows+deltaY));
image1.copyTo(firstPart);
image2.copyTo(secondPart);
imshow("result", result);

image2仅在结果中可见,如果deltaX和deltaY为零,我无法找出原因(image2+deltaX<1000,deltaY也一样)。

来自android,我假设Rect的参数为左、上、右、下,但它们是左,上与宽度和高度配对。因此,这是必须的

Rect(deltaX, deltaY, image2.cols, image2.rows)
而不是

Rect(deltaX, deltaY, image2.cols+deltaX, image2.rows+deltaY)

.

您是否检查了image2是否复制到image1上?如果是这种情况,您必须复制带有偏移量的image2到Resulties,我将image1注释掉。deltaX和deltaY设置为0时,图像2显示在左上角,其中一个不等于零。请尝试注释图像2,查看结果中是否有图像1,然后发回。结果图像总是可能不够大,无法存储图像1和2。我只是再次尝试,以确定:)deltaX=0,deltaY=0;Mat secondPart=结果(Rect(deltaX,deltaY,image2.cols+deltaX,image2.rows+deltaY));图2.复印件(第二部分);imshow(“结果”,result);工作正常,如果我设置deltaX=1,结果为空/黑色。