简体   繁体   English

如何在 python 中使用 opencv 在实时视频中保存帧?

[英]How can i save a frame in a live video using opencv in python?

How to grab a fram from a live video using opencv?如何使用 opencv 从实时视频中获取帧?

I created a face recognition program using opencv and i want to capture an image when the confidence > 0.8 this is the code for initializing the liveVideo我使用opencv创建了一个人脸识别程序,我想在置信度> 0.8时捕获图像这是初始化liveVideo的代码

 LiveVideo = VideoStream(src=0).start()
    while True:
        frame = LiveVideo.read()
    frame = imutils.resize(frame, width=1000)
     ....

if anyone knows how to grab a frame from the live video and save it please tell me how to do so如果有人知道如何从实时视频中抓取一帧并保存,请告诉我该怎么做

You can use imwrite function from your opencv to extract the current frame.您可以使用 opencv 中的imwrite函数来提取当前帧。

You can also add time and convert it to string for naming purpose for the output file.您还可以添加时间并将其转换为字符串,以便为输出文件命名。

import time as t
LiveVideo = VideoStream(src=0).start()
        while True:
            frame = LiveVideo.read()
            timestr = t.strftime("%Y%m%d-%H%M%S")
            cv2.imwrite("frame%s.jpg" % timestr, frame )

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

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