python-3.x - OpenCV 代码打开一个视频,但显示一个被阻止的摄像头
问题描述
我正在学习如何使用 python 3 和 OpenCV 显示视频。我将 PyCharm 用于我的 IDE。当我运行代码以显示来自我的网络摄像头的连续视频时,它只是给了我一个被阻止的网络摄像头的符号。后来,那个“视频”的保存文件在我的文档中,但没用。我只需要在某处更改相机设置吗?
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
# Define the codec and create VideoWriter object
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
while(cap.isOpened()):
ret, frame = cap.read()
if ret==True:
frame = cv2.flip(frame,0)
# write the flipped frame
out.write(frame)
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
# Release everything if job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
解决方案
我也是这个情况,好像是系统自动修改了设置?
我发现 Lenovo Vantage 硬件设置中相机的“隐私模式”已激活,停用它即可解决问题。
推荐阅读
- apache-spark - 如何从 spark sql databricks 中的临时视图或等效视图中删除?
- animation - 如何使用 ArcHandles 和 Handles 旋转/移动包含 Motor6D 的对象?
- python - 为什么我在 Python3 中收到此错误:IndexError: list index out of range
- javascript - 更改 element.style.display ="none" 后如何保持相同的 d-grid 间隙
- algorithm - 区分负循环中的节点和负循环可达的节点
- .net-core - ProjectTo Jsonb 列类型 EF Core 和 automapper 配置
- php - 如何使用 Laravel 将选定的值传递给创建表单?
- go - 什么时候使用嵌入?
- c++ - V8 - 向 Javascript 代码公开一个非 void C++ 函数
- jupyter-notebook - Jupyter Notebook:直接将 html 下载到我的下载文件夹(Windows)