首页 > 解决方案 > 在python中获取图像的大小

问题描述

我需要获取图像的大小,但是要调用我不使用的图像,而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)

标签: pythonimage

解决方案


推荐阅读