python - cv2.VideoCapture卡住了我的整个计算机

标签 python opencv cv2

我对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()

最佳答案

好的,问题解决了,我只是重新安装了opencv的所有依赖项,安装了FFmpeg软件包,然后重新安装了opencv。我不知道什么特定的操作可以帮助我解决此问题,但是如果您遇到相同的问题,请尝试全部解决:)
感谢您的阅读,我希望这篇文章能对遇到类似问题的人有所帮助/

关于python - cv2.VideoCapture卡住了我的整个计算机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63228036/

相关文章:

python - keras.callbacks 中 Tensorboard 导入错误

Python3 argparse : When passing string as arg run funcA, 如果虚线 arg 运行另一个函数

opencv - 使用cmd时Opencv安装错误

python - 增加帧数会减少opencv videowriter中视频的持续时间吗?

c++ - 从opencv中的每一行矩阵中减去一个 vector ?

python - '函数 imshow 中的 libpng 错误 : Invalid IHDR data' and cpp:331: error: (-215) size. width>0 && size.height>0

python-3.x - Python CV2 按键响应时间慢

python - Numpy 矩阵到 tkinter Canvas

python - 我无法在 PyCharm 下运行 Django Python pytest

opencv - 立体相机校准错误