我正在尝试将较小的图像复制到较大的图像。我这样做时会出错。我不想使用ROI方法,因为我将使用此代码进行多次迭代,并且每次为图像选择ROI都不有效,并且ROI每次都会改变。我不想使用copyTo()功能复制图像,因为下一步是检查图像像素是否为0(即黑色),如果不是,则不进行复制。我可以读取像素的值,但是当我尝试将其复制到另一张图像时出现错误。我研究了以前的所有文章,并尝试进行更改,但是没有一个起作用。我将附加我的代码以及我收到的错误。
#include<opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img1, img2, output;
img1 = imread("E:/Image2.jpg", 1);
img2 = imread("E:/Marker2.PNG", 1);
int startrow, startcol;
startrow = 20;
startcol = 20;
int rows, cols,i,j,r=1,c;
cv::Size s = img2.size();
rows = s.height;
cols = s.width;
for (i = startrow; i <= startrow + rows; i++)
{
c = 1;
for (j = startcol; j <= startcol + cols; j++)
{
output.at<uchar>(i, j) = img2.at<uchar>(r, c);
c++;
}
r++;
}
imshow("Output", output); …Run Code Online (Sandbox Code Playgroud)