拓竹打印机获取相机图片

目录

每隔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
相关推荐
燃烧的枫2 小时前
Windows 下 YOLO11 Pose 的 TensorRT C++ 部署
windows·yolo·tensorrt·1024程序员节·yolo11-pose
磁场转动100万匹3 小时前
道路巡检系统检测案例:YOLOv5 + Flask + PyQt 全栈实现
python·yolo
alwaysrun3 小时前
YOLOv8n INT8量化实战
yolo·模型量化
城南皮卡丘1 天前
苹果果实成熟度检测数据集 4195张+YOLO格式
深度学习·yolo·目标检测·计算机视觉·数据集
微尘hjx1 天前
【数据集 11】面向城市道路的坑洞检测数据集(含8760张,已按比例划分训练、验证、测试集,支持YOLO全系列训练)
人工智能·yolo·目标检测·数据集·道路坑洞·路坑数据集·路坑
联泰科技3D打印3 天前
增材制造技术优势解析:设计自由度高/材料利用率90%+,接骨板、新能源治具、军工发动机罩案例
3d打印·增材制造·联泰科技
William一直在路上3 天前
把轻量化 YOLO 模型部署到你的手机上
yolo·智能手机
迪菲赫尔曼4 天前
【基础篇 11】把官方源码放到服务器:版本、解压层级和安装位置,一次弄清楚
运维·服务器·开发语言·人工智能·python·yolo·目标检测
迪菲赫尔曼4 天前
【基础篇 12】把环境与源码接起来:检查 GPU,再安装服务器上的项目
运维·服务器·开发语言·人工智能·python·yolo·目标检测
yyk333244 天前
YOLOv4算法
人工智能·yolo·目标跟踪