当前位置: 首页 > news >正文

域名申请到网站上传全过程今日国内新闻头条

域名申请到网站上传全过程,今日国内新闻头条,网站 空间 是什么,网站需求分析怎么写摄像头监视脚本,若检测到摄像头画面有变化,保存这一段视频 一、使用方法 1.运行脚本 默认参数Threshold3, Period3, path./recordings python cam.py --threshold30 --period3 --path./recordings 2.参数说明 threshold:摄像头捕获到的画面变化量阈值…

摄像头监视脚本,若检测到摄像头画面有变化,保存这一段视频

一、使用方法

1.运行脚本
默认参数Threshold=3, Period=3, path=./recordings

python cam.py --threshold=30 --period=3 --path=./recordings
2.参数说明
threshold:摄像头捕获到的画面变化量阈值,阈值越小越敏感
period:摄像头捕获周期,单位秒
path:捕获图片保存路径


import cv2
import numpy as np
import time
import argparse
import osdef detect_motion(img1, img2, threshold=25):"""检测两帧之间的变化区域:param img1: 当前帧:param img2: 上一帧:param threshold: 像素差异阈值:return: 变化区域掩码和是否检测到变化"""# 转换为灰度图gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)# 计算差异frame_diff = cv2.absdiff(gray1, gray2)# 应用阈值_, thresh = cv2.threshold(frame_diff, threshold, 255, cv2.THRESH_BINARY)# 应用形态学操作去噪kernel = np.ones((5, 5), np.uint8)thresh = cv2.dilate(thresh, kernel, iterations=2)thresh = cv2.erode(thresh, kernel, iterations=1)# 找到轮廓contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)# 判断是否检测到显著变化has_motion = Falsemin_area = 500  # 最小变化区域面积for contour in contours:if cv2.contourArea(contour) > min_area:has_motion = Truebreakreturn thresh, has_motiondef camera_monitor(period=3, video_duration=5):"""监视程序入口:param period: 检查周期(秒):param video_duration: 录制视频长度(秒)"""print(f'监视器启动!\nParams:\nThreshold={args.threshold}, Period={period}, Save Path={args.path}')# 构建RTSP URLrtsp_url = f'rtsp://{args.username}:{args.password}@{args.ip}:{args.port}{args.channel}'print(f'连接到 RTSP 流: {rtsp_url}')# 设置RTSP连接cap = cv2.VideoCapture(rtsp_url)# 设置RTSP缓冲区大小cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)if not cap.isOpened():print('错误:无法连接到 RTSP 流')return# 获取视频参数frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))fps = 20.0# 读取第一帧_, last_frame = cap.read()while True:ret, current_frame = cap.read()if not ret:print('错误:无法读取帧')break# 检测变化motion_mask, has_motion = detect_motion(current_frame, last_frame, args.threshold)if has_motion:print("检测到运动!录制视频...")# 创建视频写入器,修改为MP4格式timestamp = time.strftime('%Y_%m_%d_%H_%M_%S', time.localtime())video_path = os.path.join(args.path, f'motion_{timestamp}.mp4')# 使用H.264编码器if os.name == 'nt':  # Windows系统video_writer = cv2.VideoWriter(video_path,cv2.VideoWriter_fourcc(*'H264'),fps,(frame_width, frame_height))else:  # Linux/Mac系统video_writer = cv2.VideoWriter(video_path,cv2.VideoWriter_fourcc(*'avc1'),fps,(frame_width, frame_height))# 记录检测到运动的时间点start_time = time.time()# 录制视频片段while time.time() - start_time < video_duration:ret, frame = cap.read()if not ret:break# 标记变化区域motion_mask, _ = detect_motion(frame, last_frame, args.threshold)contours, _ = cv2.findContours(motion_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)# 在原图上画出变化区域frame_marked = frame.copy()for contour in contours:if cv2.contourArea(contour) > 500:cv2.drawContours(frame_marked, [contour], -1, (0, 255, 0), 2)video_writer.write(frame_marked)last_frame = frame.copy()video_writer.release()print(f'视频保存到: {video_path}')last_frame = current_frame.copy()time.sleep(period)cap.release()# 参数设置
parser = argparse.ArgumentParser(description='移动侦测摄像机监视器')
parser.add_argument('--threshold', type=int, default=3, help='移动侦测阈值')
parser.add_argument('--period', type=int, default=1, help='监控周期(秒)')
parser.add_argument('--path', type=str, default='./recordings', help='保存录制文件的路径')# 添加RTSP相关参数
parser.add_argument('--ip', type=str, default='192.168.11.23', help='摄像机的 IP 地址')
parser.add_argument('--port', type=str, default='554', help='RTSP 端口(默认值:554)')
parser.add_argument('--username', type=str, default='admin', help='RTSP 用户名')
parser.add_argument('--password', type=str, default='admin123', help='RTSP 密码')
parser.add_argument('--channel', type=str, default='/cam/realmonitor?channel=1&subtype=1', help='RTSP 通道或流路径')args = parser.parse_args()# 确保存储目录存在
if not os.path.exists(args.path):os.makedirs(args.path)if __name__ == '__main__':try:camera_monitor(period=args.period)except KeyboardInterrupt:print("\n用户停止的监控")finally:cv2.destroyAllWindows()
http://www.yidumall.com/news/5701.html

相关文章:

  • 网站免费模板app注册推广任务平台
  • 自己做公众号引流到其他电影网站可以东莞网站制作十年乐云seo
  • 网站 费用关键词搜索排名推广
  • 广州网站建设模板制作联盟营销平台
  • 做户外照明有哪些网站手机百度app下载
  • 查看网站百度排名站长工具大全
  • 福田网站开发seo广告优化
  • 国外做任务网站有哪些线上推广渠道有哪些方式
  • 国土资源集约化网站群建设通知网络营销推广渠道
  • 武汉p2p网站建设价格广州王牌seo
  • 网站后台管理模板psd成都百度seo推广
  • 网站建设优化新疆梧州网站seo
  • 做网站及APP品牌营销策划与管理
  • 中国企业500强第一名是谁成都seo培
  • 腾讯网站开发长沙seo网站优化
  • 网络规划的内容优化大师的优化项目有哪7个
  • 做個app网站价格武汉seo优
  • wordpress换链接木卢seo教程
  • 平台营销型网站建设扬州seo
  • 做物流的网站都有什么企业查询宝
  • 网站开发 竞拍网站网站设计公司官网
  • 企业网站 建设流程seo文章优化技巧
  • 深圳罗湖做网站公司哪家好手机app免费制作平台
  • 就业网站哪个靠谱付费推广平台有哪些
  • 带动画的网站模板怎样在百度上发布自己的信息
  • 手机做网站过程今日热点新闻一览
  • 临海如何制作公司网站框架免费seo教程资源
  • 商城网站开发技术有哪些影视后期哪个培训靠谱
  • 今天北京感染了多少人优化视频
  • 饮水机企业网站模板做销售怎么和客户聊天