将图像的区域复制到另一个图像中的另一个区域 [英] Copying Region of an Image to another Region in another Image

查看:154
本文介绍了将图像的区域复制到另一个图像中的另一个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一个非常简单的事情:将图像内的区域复制到新图像中的新区域.在OpenCV 2.3速查表中,他们提出以下解决方案:

I would like to do a very simple thing: copy an area inside an image into a new area in a new image. In the OpenCV 2.3 cheatsheet, they suggest the following solution:

示例3.通过转换将图像ROI复制到另一幅图像中"

"Example 3. Copy image ROI to another image with conversion"

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).
任何人都可以告诉我为什么它不起作用吗?

I just want to copy the image frameO in output at the location Rect(20,20, frameO.cols, frameO.rows).
Anyone can tell me why this is not working?

推荐答案

实际上,这些命令在OpenCV 2.3中不起作用,但现在在2.4版本中可以正常使用以下命令:

Actually these commands were not working in OpenCV 2.3 but now the following works fine with the 2.4 release:

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中.

This will copy frame1 in output as long as the type agree so be careful when you create output. frame1 will be copied in a ROI in output defined by Rect(0, 0, frame1.cols, frame1.rows).

这篇关于将图像的区域复制到另一个图像中的另一个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆