简体   繁体   English

使用 python 静默捕获网络摄像头快照

[英]Capturing webcam snapshot with python silently

How is it possible to capture a snapshot of webcam or stream webcam in python without popping up windows?如何在 python 中捕获网络摄像头或 stream 网络摄像头的快照而不弹出 windows?

Using opencv-python package, the following piece of code momentarily captures the webcam information and saves the image in the directory specified.使用 opencv-python package,以下代码会瞬间捕获网络摄像头信息并将图像保存在指定目录中。 Note: The webcam indicator does light up for a fraction of second.注意:网络摄像头指示灯会在几分之一秒内亮起。 I am not sure how that can be avoided as of now.我不确定到目前为止如何避免这种情况。

import cv2
webcam = cv2.VideoCapture(1) # Number which capture webcam in my machine
# try either VideoCapture(0) or (1) based on your camera availability
# in my desktop it works with (1)
check, frame = webcam.read()
cv2.imwrite(filename=r'<Your Directory>\saved_img.jpg', img=frame)
webcam.release()

This piece of code can be written in a bat file and you can trigger this for what ever event you are looking for (like startup security)这段代码可以写在一个 bat 文件中,你可以为你正在寻找的任何事件触发它(比如启动安全)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM