import cv2
import numpy as np
import sys
import pytesseract
from PIL import Image
reload(sys)
sys.setdefaultencoding('utf-8')
# Read image with opencv
img = cv2.imread("T.jpg")
print img.size
width , height = img.size
(C:\Users\SACHIN\Anaconda2) D:\>python R6extractor.py
6220800
Traceback (most recent call last):
File "R6extractor.py", line 14, in <module>
width , height = img.size
TypeError: 'int' object is not iterable
但是当我用谷歌搜索如何获得图像的宽度和高度时。几乎每个例子都显示使用width,height = image.size。然后我就去了。但是我收到这个错误所以我检查了图像的内容.size,我得到了6220800。所以我在这里做错了什么
答案 0 :(得分:1)
正如@ theWanderer4865在评论中所说,img.size
返回一个整数,你无法解压缩它。
您需要做的是:
height, width, channels = img.shape
修改强>
如果您想使用Image
库打开它,代码将如下:
from PIL import Image
# Read image with Image
img = Image('T.jpg')
img = cv2.imread("T.jpg")
width, height = img.size