首页 > 解决方案 > cv2.VideoCapture 冻结了我的整个计算机

问题描述

我对 cv2.VideoCapture() 方法有疑问。每当我想处理一些视频时,它只会冻结我的整个计算机,我唯一能做的就是使用按钮手动关闭计算机。我刚买了新电脑,这在旧电脑上从未发生过。所以我试图简化问题,只是抓取了一些用于视频捕获的示例代码并得到了相同的行为,计算机全部冻结,我只能手动关闭它。

我正在使用 Python 3.6 和 PyCharm,我的新计算机是 Intel NUC 7i3BNK。

我真的找不到任何解决方案。感谢您的回答!

我的示例代码:

import numpy as np
import cv2 as cv

if __name__ == '__main__':

    cap = cv.VideoCapture("mizuno-cam1.mp4")
    if not cap.isOpened():
        print("Cannot open camera")
        exit()
    while True:
        # Capture frame-by-frame
        ret, frame = cap.read()
        # if frame is read correctly ret is True
        if not ret:
            print("Can't receive frame (stream end?). Exiting ...")
            break
        # Our operations on the frame come here
        gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
        # Display the resulting frame
        cv.imshow('frame', gray)
        if cv.waitKey(1) == ord('q'):
            break
    # When everything done, release the capture
    cap.release()
    cv.destroyAllWindows()

标签: pythonopencvcv2

解决方案


好的,问题解决了,我刚刚重新安装了opencv的所有依赖项,安装了FFmpeg包并重新安装了opencv。我不知道什么具体操作帮助我解决了这个问题,但如果你有同样的问题,试着做所有的事情:)

感谢阅读我希望这篇文章能帮助遇到类似问题的人/


推荐阅读