我正在尝试使用这个库。特别是以下三行代码:
但它可以在真实文件上运行。这里有什么需要修复的地方。
image_stream = io.BytesIO(image_bytes)
frame = cv2.imread(image_stream)
我遇到了一个异常:
Traceback (most recent call last):
File "/home/a/Pictures/pycharm-community-2018.3.2/helpers/pydev/pydevd.py", line 1741, in <module>
main()
File "/home/a/Pictures/pycharm-community-2018.3.2/helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/home/a/Pictures/pycharm-community-2018.3.2/helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/home/a/Pictures/pycharm-community-2018.3.2/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/a/Documents/wiker/main.py", line 13, in <module>
if __name__ == '__main__': main()
File "/home/a/Documents/wiker/main.py", line 10, in main
article['video'] = video.make_video_from_article(article)
File "/home/a/Documents/wiker/video.py", line 15, in make_video_from_article
frame = cv2.imread(image_stream)
TypeError: bad argument type for built-in operation
但它可以在真实文件上运行。这里有什么需要修复的地方。
print(type(image_stream))
,您会得到什么? - Employeeimread
的第一个参数需要是文件名,而不是流。它只能从文件中读取。如果你想要从内存中解码数据,你需要使用imdecode
。 - Dan Mašekimage_bytes
是否已经编码? - Ulrich Sternimage_content = get("https://" + image_url).content
,需要引入模块from requests import get
。 - user10886181