拓竹打印机获取相机图片

目录

每隔3秒截取一张图片:

截图命令:


每隔3秒截取一张图片:

python 复制代码
import cv2
import time
import os


def capture_rtsp_frames(rtsp_url, output_dir="captures", interval=3):
   
    # 创建输出目录
    os.makedirs(output_dir, exist_ok=True)

    # 打开RTSP流
    cap = cv2.VideoCapture(rtsp_url, cv2.CAP_FFMPEG)

    if not cap.isOpened():
        print("无法打开RTSP流")
        return

    # 设置RTSP传输协议为TCP
    cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)  # 减少缓冲

    frame_count = 0
    last_capture_time = time.time()

    print(f"开始捕获,间隔{interval}秒...")
    print("按 Ctrl+C 停止捕获")

    try:
        while True:
            ret, frame = cap.read()

            if not ret:
                print("无法读取帧,尝试重新连接...")
                cap.release()
                time.sleep(1)
                cap = cv2.VideoCapture(rtsp_url, cv2.CAP_FFMPEG)
                continue

            current_time = time.time()

            # 检查是否到达捕获间隔
            if current_time - last_capture_time >= interval:
                # 保存图片
                timestamp = time.strftime("%Y%m%d_%H%M%S")
                filename = f"{output_dir}/capture_{timestamp}_{frame_count}.jpg"
                cv2.imwrite(filename, frame)
                print(f"捕获: {filename}")

                frame_count += 1
                last_capture_time = current_time

            # 添加小延时避免CPU占用过高
            time.sleep(0.01)

    except KeyboardInterrupt:
        print("\n用户中断捕获")
    finally:
        cap.release()
        print(f"捕获完成,共保存 {frame_count} 张图片")


if __name__ == "__main__":
    # RTSP配置
    rtsp_url = "rtsps://bblp:xxx0@192.168.8.201/streaming/live/1"

    # 开始捕获(无限循环,直到按Ctrl+C)
    capture_rtsp_frames(rtsp_url, interval=3)

截图命令:

复制代码
ffmpeg -rtsp_transport tcp -i "rtsps://bblp:xxxx@192.168.8.201/streaming/live/1" -y -frames:v 1 capture1.jpg
相关推荐
羊羊小栈1 天前
基于「YOLO目标检测 + 多模态AI分析」的水稻病害智能检测分析预警系统(LangChain框架)
人工智能·yolo·目标检测·毕业设计·创业创新·大作业
YOLO_DATA2 天前
遥感滑坡检测的数据集 2299 张 1类 yolo格式 遥感滑坡检测数据集
人工智能·深度学习·yolo·计算机视觉·无人机·yolo数据集·ai数据集
计算机编程-吉哥2 天前
YOLO26 vs YOLO11 vs YOLOv8:深度学习咖啡果实成熟度分割系统【计算机毕业设计选题推荐】
人工智能·python·深度学习·yolo·django·毕业设计
西西弗Sisyphus3 天前
YOLO26 图像分割 - 训练的数据加载:取图、在线增强与标签缓存
yolo·yolo26
YOLO_DATA3 天前
无人机高速公路道路缺陷数据集 道路损伤数据集 公路裂缝识别 AI大疆数据集 10798期
人工智能·深度学习·yolo·机器学习·cnn
YOLO数据集集合4 天前
小目标无人机、飞机、直升机检测数据集 | 小目标检测 无人机检测 空中目标识别 低空安防 反无人机9090期
深度学习·yolo·目标检测·无人机·飞机·小目标·直升机
YOLO数据集集合4 天前
全球无人机航拍树冠覆盖数据集 | 树冠分割 语义分割 无人机航拍 全球森林监测 GeoTIFF 生态恢复9083期
深度学习·yolo·目标检测·无人机·无人机视角·全球森林
Python图像识别4 天前
10-【2027毕设】YOLO11PCB缺陷检测识别系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·深度学习·yolo·毕业设计·毕设
YOLO数据集集合4 天前
无人机树木识别检测数据集 | 树木检测 树种分类 无人机航拍 林业调查9082期
深度学习·yolo·目标检测·无人机·无人机视角·树冠识别·树冠
qq7422349844 天前
YOLO 之外的另一半:RF-DETR 检测实战
yolo