将图像的区域复制到另一个图像中的另一个区域

问题描述:

我想做一件非常简单的事情:将图像内的区域复制到新图像中的新区域。在OpenCV的2.3的cheatsheet,他们建议如下解决方案:将图像的区域复制到另一个图像中的另一个区域

“实施例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); 

我的代码如下:

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); 

我只是想复制图像frameO输出的位置Rect(20,20, frameO.cols, frameO.rows)
任何人都可以告诉我为什么这不起作用?

+0

您提供的代码片段不完整。您能否发布整个代码,包括您实际执行副本的操作。 – ypnos 2012-04-13 09:03:13

+0

[如何在OpenCV中设置ROI?](http://*.com/questions/8206466/how-to-set-roi-in-opencv) – karlphillip 2012-04-13 13:00:42

+0

以及http:// *的可能重复.com/questions/6566295/opencv -c-getting-region-of-interest-roi-using-cvmat – karlphillip 2012-04-13 13:00:58

其实这些命令的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))); 

这将在输出复制frame1只要类型一致,当你创建的输出,所以要小心。 frame1将被复制到由Rect(0, 0, frame1.cols, frame1.rows)定义的输出中的ROI中。