首页 > 解决方案 > 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()

在此处输入图像描述提前致谢。

标签: python-3.xopencvpycharmwebcam-capture

解决方案


我也是这个情况,好像是系统自动修改了设置?

我发现 Lenovo Vantage 硬件设置中相机的“隐私模式”已激活,停用它即可解决问题。


推荐阅读