Skip to content
Advertisement

Fill a rectangle area with an image

I have a code from OpenCV docs regarding template matching as follows:

JavaScript

Right now the rectangle drawn on my image is not filled, I would like to fill the area of the cv2.rectangle with some image. How to achive this?

Advertisement

Answer

If you are filling the rectangle with the template image, then the dimensions of the template are the same as the rectangle and all you need to do is insert it using Numpy. So

JavaScript

That puts the template image into the region of img defined by the rectangle.

Of course you can use any image in place of template, so long as you crop it to the same width and height as defined by left:right and top:bottom.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement