python - 在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)
解决方案
推荐阅读
- python - 逻辑回归成本函数中的两种不同成本
- html - 使用 MongoDB 在 HTML 上显示图像,但没有显示
- java-8 - DataFlow 管道卡在初始化 tempLocation 上?
- c++ - 我是否应该期望 GMP 的 mpf_class 比原始数据类型 double 慢得多?
- c# - 了解编译器优化
- excel - 有没有办法让 VBA excel 在文件中找到一个单词/字符串并返回它旁边的单元格中的值?
- python - 如何接受 ModelForm 中的数据并在同一网页中显示来自 DB 的数据
- batch-file - 只需在文件中打印 13 到 16 个字符(数字/字母)并将其存储为变量以供以后使用批处理文件调用
- python - Python:初始化模块后,不再可以导入函数
- python - 来自 YAML 的 Numpy 数组