【问题标题】:Weird OpenCV .read() hangs with no error奇怪的 OpenCV .read() 挂起,没有错误
【发布时间】:2014-02-05 23:23:36
【问题描述】:

我有一个允许用户上传视频的网站。在此过程中,有一个脚本会自动创建缩略图。这是我用来完成此操作的代码:

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)

目前,视频已正确保存。但是,在创建缩略图时,脚本会在 cap.read() 处挂起并且永远不会引发错误。

现在这是奇怪的部分 - 如果我删除最后 3 行,那么它所做的只是上传视频而不创建缩略图,我可以 SSH 到服务器并直接运行最后 3 行,一切正常它应该。该脚本仅在网站上实时运行时才会挂起...

我不知道为什么只有在通过网络请求调用代码时才会发生这种情况。

我尝试使用img = cap.retrieve()cap.read() 切换到cap.grab(),但它只是挂在.retrieve() 上。

【问题讨论】:

    标签: python django opencv


    【解决方案1】:

    通过从 OpenCV 3.0.0 降级到 OpenCV 2.4.0 解决。使用 Python 2.7 运行时,任何高于 2.4.0 的版本都会出现此问题

    【讨论】:

    • 降级到 OpenCV2.4.0。在我的电脑上运行 Python 2.7 时,这解决了同样的问题。
    猜你喜欢
    • 2018-01-22
    • 2019-05-31
    • 1970-01-01
    • 1970-01-01
    • 2013-11-15
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 2015-11-09
    相关资源
    最近更新 更多