简体   繁体   English

使用Raspberry Pi +网络摄像头以python录制视频,但有时相机无法像我预期的那样打开/关闭

[英]Using Raspberry Pi + Webcam to record video in python, but sometimes camera does not turn on/off as I expected

I am trying to using Raspberry Pi + webcam (logitech) to record video, but there is a problem at the first step... I would like to male the webcam turned on when needed, and turned off otherwise, however when I try 我正在尝试使用Raspberry Pi +网络摄像头(logitech)录制视频,但是第一步存在问题...我想在需要时打开网络摄像头的电源,然后在尝试时关闭网络摄像头的电源。

cap = cv2.VideoCapture(0)
if cap.isOpened() != True:
    cap.open(0)

the webcam still didn't turn on sometimes... so I would like to know if someone knows the solution, I will appreciate you! 网络摄像头有时仍然无法打开...所以我想知道是否有人知道解决方案,我将不胜感激! Thanks! 谢谢!

try releasing it first, before opening it: 尝试先释放它,然后再打开它:

cap = cv2.VideoCapture(0)
if cap.isOpened() != True:
    cap.release()
    cap.open(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Raspberry Pi +网络摄像头以python录制视频总是会得到空视频或仅一帧视频 - Using Raspberry Pi + Webcam to record video in python always gets an empty video or only one frame video Raspberry Pi CSI 摄像头到 USB 网络摄像头 Python - Raspberry Pi CSI camera to USB webcam in Python 如何使用 python 和树莓派使用按钮打开和关闭 LED? - How do I use a button to turn an LED on and off using python and a raspberry pi? 将记录插入Raspberry Pi上的MySQL数据库时打开/关闭LED - Turn LED on/ off when inserting a record into a MySQL database on a Raspberry Pi 将 Raspberry Pi 摄像头用于具有下三分之一覆盖的网络摄像头 - Using Raspberry Pi Camera for Webcam with Lower Third Overlay python opencv找不到树莓派相机 - python opencv does not find raspberry pi camera 使用Raspberry Pi和Bluemix的IoT Python应用程序:无法打开/关闭灯光并使用按钮发送消息 - IoT Python app with a Raspberry Pi and Bluemix: Cannot turn on/off lights and send message using the button 如何使用 USB 网络摄像头在树莓派上拍摄视频 - How to take video on a raspberry pi with a usb webcam 使用树莓派,Pi相机,Python和Open Cv进行人脸识别 - Face recognition using raspberry pi, pi camera,python and Open Cv 使用python录制网络摄像头视频 - Record a Webcam video with python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM