Insert an image in a particular position, python

963 Views Asked by At

Good morning, I need to insert dynamically in image in a particular place in a background image, for example, I calculate the coordination of a rectangle and then I want to place a picture in the exact place of that rectangle. Parts of my code :

filename = askopenfilename(filetypes=[("image","*.png")])
image=cv2.imread(filename,1)
filename1 = askopenfilename(filetypes=[("image","*.png")]) #Inserted img
img=cv2.imread(filename1,1)

#to calculate the cordination/width and height of the rectangle
x,y,w,h = cv2.boundingRect(c)

offset = np.array((x,y))
image[offset[0]:offset[0]+img.shape[0],offset[1]:offset[1]+img.shape[1]] = img

I'm not very familiar with the way offset works, So can you please help me understand it in order to achieve my goal.

Thank you.

0

There are 0 best solutions below