IplImage inside IplImage

本小妞迷上赌 提交于 2019-12-02 20:54:26

问题


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.

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.

Thx in advance


回答1:


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)

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)

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

Demo output:

blue:

red:

combined:



来源:https://stackoverflow.com/questions/10055535/iplimage-inside-iplimage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!