Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在特定位置插入图像,python_Python_Insert Image - Fatal编程技术网

在特定位置插入图像,python

在特定位置插入图像,python,python,insert-image,Python,Insert Image,早上好, 我需要在背景图像中的特定位置动态插入图像,例如,我计算一个矩形的坐标,然后我想在该矩形的确切位置放置一张图片。 我的部分代码: filename = askopenfilename(filetypes=[("image","*.png")]) image=cv2.imread(filename,1) filename1 = askopenfilename(filetypes=[("image","*.png")]) #Inserted img img=cv2.imread(filena

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

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
我不太熟悉偏移量的工作方式,所以为了实现我的目标,你能帮我理解一下吗


谢谢。

什么是
c
变量?
c
变量来自我为了进行形状检测而创建的for循环(我想这与我的图像定位问题无关!!)我应该把
offset=np.array((y,x))
而不是
offset=np.array((x,y))
谢谢