简体   繁体   English

使用 python 使用 IP 摄像头捕获单个图像

[英]Capture a single image with IP camera using python

I just want to capture a single image from IP camera using python.我只想使用 python 从 IP 摄像头捕获单个图像。 I had this below sample code:我有以下示例代码:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):

    ret, frame = cap.read()
    cv2.imshow('frame',frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

But I don't need to show preview, also no need of capturing frame by frame..It should be like when program starts it just take a picture and save it in some folder and stop execution.但是我不需要显示预览,也不需要逐帧捕获..应该像程序启动时只是拍照并将其保存在某个文件夹中并停止执行。

If saving the first frame is the only thing you need...如果您只需要保存第一帧...

import cv2

cap = cv2.VideoCapture(0)
if cap.isOpened():
    ret, frame = cap.read()
    if ret:
        cv2.imwrite('frame.png', frame)

cap.release()

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

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