IplImage内的IplImage [英] IplImage inside IplImage

查看:99
本文介绍了IplImage内的IplImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用OpenCv(JavaCv)将图像放置在图像中. 例如我有一个1000x1000的图像和一个100x100的图像.而且我想将600x600的位置放置在较大的图像内.

Is it possible to place an image inside an image with OpenCv (JavaCv). For example i have a 1000x1000 image and a 100x100 image. And at position 600x600 i would like to place the smaller image inside the larger image.

让我们说蓝色框是1000x1000 IplImage,红色框是100x100 IplImage. 是否可以将红色框放在蓝色框中.由于它必须实时工作,因此最好在计算上比较有效.

lets say the blue box is the 1000x1000 IplImage and the red one is the 100x100 IplImage. Is it possible to put the red box in the blue box. Preferably computational rather efficient because it has to work in real time.

提前谢谢

推荐答案

这是在Python中进行的,但是向Java的转换将非常容易.使用GetSubRect()Copy(). GetSubRect()返回感兴趣的矩形子数组(指定感兴趣的左上角点以及宽度和高度).然后只需使用Copy()复制图像即可.

This is in Python, but conversion to Java is going to be real easy. Use GetSubRect(), and Copy(). GetSubRect() returns a rectangular subarray of interest (specify top left point of interest, and the width and height). Then just copy over the image using Copy().

import cv
blue = cv.LoadImage("blue.jpg")
red = cv.LoadImage("red.jpg")

sub = cv.GetSubRect(blue, (100, 100, 50, 50))
cv.Copy(red,sub)

cv.ShowImage('blue_red', blue)
cv.WaitKey(0)

或者,正如卡尔菲利普建议的那样,您可以使用SetImageROI()指定感兴趣的区域",并做同样的事情:

Alternatively, as karlphillip suggests you could specify the 'region of interest' using SetImageROI(), and do much the same thing:

cv.SetImageROI(blue,(100,100,50,50))
cv.Copy(red, blue)
cv.ResetImageROI(blue)

重置ROI非常重要,ResetImageROI,否则您将只显示/保存ROI,而不显示/保存整个图像.

Its very important to reset the ROI, ResetImageROI, otherwise you will only display/save the ROI, and not the whole image.

演示输出:

蓝色:红色:组合:

这篇关于IplImage内的IplImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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