0

早上好,我需要在背景图像中的特定位置动态插入图像,例如,我计算矩形的坐标,然后我想将图片放置在该矩形的确切位置。 我的部分代码:

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

我对offset工作方式不是很熟悉,所以请你帮我理解它以实现我的目标。

谢谢你。

4

0 回答 0