奇怪的OpenCV .read()挂起没有错误 [英] Weird OpenCV .read() hangs with no error
问题描述
f = request.FILES ['video']
f_temp = open('/ path / to / video / dir /'+ f.name,'wb +')
在f.chunks()中的块:
f_temp.write(chunk)
f_temp.close()
cap = cv2.VideoCapture('/ path / to / video / dir /'+ f.name)
nothing,img = cap.read()
cv2。 imwrite('/ path / to / thumbnail / dir /'+ f.name.split('。')[0] +'.png',img)
目前,视频保存正常。但是,创建缩略图时,该脚本将挂起在 cap.read()
并且不会抛出错误。
现在这里是奇怪的部分 - 如果我记得最后3行,所以所有这一切是上传视频,不创建缩略图,我可以SSH到服务器,直接运行最后3行,一切都正常工作。脚本只在网站上正在运行时挂起...
我不知道为什么只有通过Web请求调用代码时才会发生这种情况
我尝试切换 cap.read()
到 cap.grab()
with img = cap.retrieve()
,但它只是挂在 .retrieve()
通过从OpenCV 3.0.0降级到OpenCV 2.4.0来解决。当使用Python 2.7
运行时,2.4.0以上的任何内容都会出现此问题
I have a website that allows users to upload videos. During this process there is a script that automatically creates a thumbnail. Here is the code I am using to accomplish this:
f = request.FILES['video']
f_temp = open('/path/to/video/dir/' + f.name, 'wb+')
for chunk in f.chunks():
f_temp.write(chunk)
f_temp.close()
cap = cv2.VideoCapture('/path/to/video/dir/' + f.name)
nothing, img = cap.read()
cv2.imwrite('/path/to/thumbnail/dir/' + f.name.split('.')[0] + '.png', img)
Currently, the video is saved properly. However, when creating the thumbnail, the script hangs at cap.read()
and never throws an error.
Now here's the weird part - if I remeve the last 3 lines so all it does is upload the video and doesn't create the thumbnail, I can SSH to the server and run the last 3 lines directly and everything works exactly as it should. The script only hangs when it is running live on the website ...
I have no clue as to why this would only happen when the code is called through a web request.
I tried switching cap.read()
to cap.grab()
with img = cap.retrieve()
, but then it just hangs on .retrieve()
instead.
Solved by downgrading from OpenCV 3.0.0 to OpenCV 2.4.0. Anything above 2.4.0 has this issue when running with Python 2.7
这篇关于奇怪的OpenCV .read()挂起没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!