Tul*_*kas 7 c++ opencv computer-vision
我想做一件非常简单的事情:将图像中的区域复制到新图像中的新区域.在OpenCV 2.3备忘单中,他们建议以下解决方案:
"示例3.通过转换将图像ROI复制到另一个图像"
Rect r(1, 1, 10, 20);
Mat dstroi = dst(Rect(0,10,r.width,r.height));
src(r).convertTo(dstroi, dstroi.type(), 1, 0);
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
Mat frameO, frameS;
original >> frameO;
stabilized >> frameS;
Mat output(frameO.rows+40, frameO.cols*2+60, CV_32FC3);
output.setTo(0);
Rect r(0,0, frameO.cols, frameO.rows);
Mat destROI = output(Rect(20,20, frameO.cols, frameO.rows));
frameO(r).copyTo(destROI);
Run Code Online (Sandbox Code Playgroud)
我只想frameO在该位置的输出中复制图像Rect(20,20, frameO.cols, frameO.rows).
任何人都可以告诉我为什么这不起作用?
Tul*_*kas 14
实际上这些命令在OpenCV 2.3中不起作用,但现在以下版本在2.4版本中运行良好:
Mat frame1 = imread(nameReading1);
Mat output(frame1.rows*2, frame1.cols*2, frame1.type());
output.setTo(0);
frame1.copyTo(output(Rect(0, 0, frame1.cols, frame1.rows)));
Run Code Online (Sandbox Code Playgroud)
frame1只要类型一致,这将在输出中复制,因此在创建输出时要小心.frame1将被复制到由定义的输出的ROI中Rect(0, 0, frame1.cols, frame1.rows).