我需要获取图片的大小,但要调用图片我没有使用img=open'rectangle.png'
,而是使用filename1 = askopenfilename(filetypes=[("image","*.png")])
但我得到这个错误:
width, height = background.size
TypeError: 'int' object is not iterable
这是我的代码:
import tkFileDialog
from tkFileDialog import askopenfilename # Open dialog box
from PIL import Image
import cv2
import numpy
filename1 = askopenfilename(filetypes=[("image","*.png")])
filename2 = askopenfilename(filetypes=[("image","*.png")])
img=cv2.imread(filename1,1)
background=cv2.imread(filename2,1)
offset = numpy.array((10,10))
background[offset[0]:offset[0]+img.shape[0],offset[1]:offset[1]+img.shape[1]]=img
width, height = background.size
print('width = ', width)
print('height = ',height)
cv2.imshow("Added Image", background)
cv2.waitKey(0)