【发布时间】:2020-01-05 11:23:13
【问题描述】:
#!/usr/bin/env python
'''
Usage:
./ssearch.py input_image (f|q)
f=fast, q=quality
Use "l" to display less rects, 'm' to display more rects, "q" to quit.
'''
import sys
import cv2
if __name__ == '__main__':
# If image path and f/q is not passed as command
# line arguments, quit and display help message
if len(sys.argv) < 3:
print(__doc__)
sys.exit(1)
# speed-up using multithreads
cv2.setUseOptimized(True);
cv2.setNumThreads(4);
# read image
im = cv2.imread(sys.argv[1])
# resize image
newHeight = 200
newWidth = int(im.shape[1]*200/im.shape[0])
im = cv2.resize(im, (newWidth, newHeight))
这里出错了
AttributeError Traceback (most recent call last)
<ipython-input-7-b88f466ecb3b> in <module>
25 # resize image
26 newHeight = 200
---> 27 newWidth = int(im.shape[1]*200/im.shape[0])
28 im = cv2.resize(im, (newWidth, newHeight))
29
AttributeError: 'NoneType' object has no attribute 'shape'
并解释 cv2.imread(sys,argv[1]) 行
(2)第二个问题是我如何得到非类型错误,因为我没有 从我的命令行传递了我的图像路径 (3) cmd line没有提示,因为程序没有执行错误
很抱歉,我无法放置完整的代码
【问题讨论】:
-
"如果无法读取图像(由于缺少文件、权限不正确、格式不支持或无效),该函数将返回一个空矩阵( Mat::data==NULL )。" docs.opencv.org/master/d4/da8/…
-
你检查图像的路径是否有效?在阅读图像之前,请尝试
os.path.exists(sys.argv[1])