python - 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()
解决方案
好的,问题解决了,我刚刚重新安装了opencv的所有依赖项,安装了FFmpeg包并重新安装了opencv。我不知道什么具体操作帮助我解决了这个问题,但如果你有同样的问题,试着做所有的事情:)
感谢阅读我希望这篇文章能帮助遇到类似问题的人/
推荐阅读
- android - Android动作布局无法相应地工作
- diff - 如何运行包含多个差异的 .patch 文件
- javascript - 围绕其中心点
- javascript - 如何使用 jQuery 添加重复的 div?
- php - PHP浮点乘法和比较问题
- java - 从 InputStream 创建 java.util.stream.Stream 的最佳方法是什么?
- postgresql - 无法使用 IntelliJ IDEA 的 ssl 连接到 Postgresql
- python - python 3布尔逻辑快捷方式
- python - 从 scipy csr 稀疏矩阵中选择行子集的最有效方法
- python - 将我的程序转换为 pip 模块时出现问题