How to insert an image to inside of Circle with OpenCV Python

I have a circle like this:

and I want to insert an image to inside of this circle. I have checked most of the contents regarding this subject in the internet but I couldn’t find anything.

Do you know how to do this? thank you.

you can use cv.copyTo with a mask

1 Like

@laurent.berger , “Is there any sample code that would guide me about how to apply such feature in opencv python”?

Because I couldn’t find a solid example that will help me to understand and apply this feature with a sample example, thank you.

You can find issue here

and example

import numpy as np
import cv2 as cv

lena = cv.imread('g:/lib/opencv/samples/data/lena.jpg')
mask = np.zeros(shape=(lena.shape[0], lena.shape[1]),dtype=np.uint8)
mask =,(250,250),40,255,-1)
dst = cv.copyTo(lena,mask)

1 Like

so we are not directly insert an external image (like overlay) to the background, but getting that position only.

@laurent.berger friend, what if I want to add an external (2nd image) inside of the circle (something similar to addweight function but with a better way, or what ever way is better and possible) while keeping the background image still, how would we achieve such feature? thank you very much.

as already directed, please look at the documentation for cv::Mat::copyTo. you will see that you can use it to copy parts of one image into another as well.

1 Like