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

录制mp4 rospy

ros 预览摄像头

#!/usr/bin/env python
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import cv2# 初始化 bridge
bridge = CvBridge()def image_callback(msg):# 将ROS图像消息转换为OpenCV图像cv_image = bridge.imgmsg_to_cv2(msg, desired_encoding='bgr8')# 显示图像cv2.imshow("Camera View", cv_image)cv2.waitKey(1)if __name__ == '__main__':rospy.init_node('camera_viewer', anonymous=True)# 订阅图像话题//rospy.Subscriber('/camera_l/color/image_raw', Image, image_callback)rospy.Subscriber('/camera_f/color/image_raw', Image, image_callback)rospy.spin()cv2.destroyAllWindows()

view2.py

#!/usr/bin/env python
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import cv2import imageio
import os
import sys
current_dir = os.path.dirname(os.path.abspath(__file__))
current_dir_p=os.path.dirname(current_dir)
os.chdir(current_dir)
print('current_dir',current_dir)
paths = [current_dir,current_dir_p]
paths.append(os.path.join(current_dir, 'src'))for path in paths:sys.path.insert(0, path)os.environ['PYTHONPATH'] = (os.environ.get('PYTHONPATH', '') + ':' + path).strip(':')import time
class Time_Str:def __init__(self):self.last_time = ''self.counter = 0def get_time_sec(self):now_time = time.strftime("%m%d_%H%M_%S")  # 当前时间(精确到秒)self.counter += 1if now_time != self.last_time:self.last_time = now_timeself.counter = 0return f"{now_time}_{self.counter}"def get_time_mm(self):now_time = time.strftime("%m%d_%H%M")  # 当前时间(精确到秒)self.counter += 1if now_time != self.last_time:self.last_time = now_timeself.counter = 0return f"{now_time}_{self.counter}"# 初始化 bridge
bridge = CvBridge()time_str=Time_Str()
imgs = []
fps = 30
index = 0
count = 0
strat_record = Falseos.makedirs('record',exist_ok=True)def image_callback(msg):global strat_record,count,imgs,index# 将ROS图像消息转换为OpenCV图像cv_image = bridge.imgmsg_to_cv2(msg, desired_encoding='bgr8')img = cv2.cvtColor(cv_image, cv2.COLOR_BGR2RGB)if strat_record:imgs.append(img)index += 1if index % 300 == 299 and strat_record:count += 1save_video_path = f'record/{time_str.get_time_mm()}.mp4'imageio.mimsave(save_video_path, imgs, fps=fps, macro_block_size=None)imgs = []# 显示图像cv2.imshow("Camera View", cv_image)key = cv2.waitKey(1) & 0xFFif key == ord('q'):returnelif key == ord('s'):strat_record = True print("start_record")elif key == ord('e'):strat_record = Falsesave_video_path = f'record/{time_str.get_time_mm()}.mp4'imageio.mimsave(save_video_path, imgs, fps=fps, macro_block_size=None)imgs = []print("end_record")if __name__ == '__main__':rospy.init_node('camera_viewer', anonymous=True)# 订阅图像话题# rospy.Subscriber('/camera_r/color/image_raw', Image, image_callback)rospy.Subscriber('/camera_f/color/image_raw', Image, image_callback)rospy.spin()cv2.destroyAllWindows()


文章转载自:

http://zrPHsCy5.wttzp.cn
http://4AV3I0Ew.wttzp.cn
http://o3ArpLxb.wttzp.cn
http://yxaIDxX9.wttzp.cn
http://dfZ37Dmt.wttzp.cn
http://iSL4fz51.wttzp.cn
http://V56kRmNu.wttzp.cn
http://xaFRnSNo.wttzp.cn
http://BzOQsFN6.wttzp.cn
http://NFYzDl8D.wttzp.cn
http://N1IfihQs.wttzp.cn
http://Bnt3BoAa.wttzp.cn
http://p8kCnAKp.wttzp.cn
http://hMslh2tj.wttzp.cn
http://cWhlyrJA.wttzp.cn
http://rP21uGRx.wttzp.cn
http://C2bCO2e0.wttzp.cn
http://qjqu8v8W.wttzp.cn
http://XFSJp81y.wttzp.cn
http://dbPxG5AR.wttzp.cn
http://EbGsFYEs.wttzp.cn
http://vfUF70jc.wttzp.cn
http://s88grQwE.wttzp.cn
http://qqtAWO2N.wttzp.cn
http://i5O881ke.wttzp.cn
http://rR4TnRrd.wttzp.cn
http://zuqAzW9y.wttzp.cn
http://HmW1iYqQ.wttzp.cn
http://TzkAogLV.wttzp.cn
http://SI69VEUa.wttzp.cn
http://www.dtcms.com/a/245335.html

相关文章:

  • 2025年中国人工智能发展研究报告:技术突破、行业变革与全球竞争新格局
  • Spring 路由匹配机制详解:时间复杂度从 O(n) 降至 O(log n)
  • 学习STC51单片机36(芯片为STC89C52RCRC)智能小车3(PWM差速小车)
  • Redis 安装实践:基于鲲鹏 ARM 架构 Ubuntu 环境
  • 随记:sw2urdf插件导出urdf模型在ROS2-rviz2显示
  • 电流传感器在工业自动化中的应用
  • Tess4J:基于 Java 的 OCR 解决方案
  • 【doris】doris集成ranger控制权限,ranger配置无法存储doris密码password信息
  • 代码随想录训练营第三十天 | 452. 用最少数量的箭引爆气球 435. 无重叠区间 763.划分字母区间
  • 【Net】OPC UA(OPC Unified Architecture)协议
  • 图片压缩工具类
  • 深入剖析 C++ 默认函数:拷贝构造与赋值运算符重载
  • 你管这玩意叫网络?网络图解
  • CANoe入门(1)-- 创建新CANoe工程
  • 开源综合性网络安全检测和运维工具-TscanClient
  • 【Python打卡Day36】信贷项目的神经网络训练@浙大疏锦行
  • docker-compose容器单机编排
  • NLP基础与词嵌入:让AI理解文字(superior哥深度学习系列第13期)
  • Apache 反向代理Unity服务器
  • 使用VSCode开发FastAPI指南
  • pandas 字符串列迁移至 PyArrow 完整指南:从 object 到 string[pyarrow]
  • JFLASH 提示license 配置操作 Sorry,no valid license for I-Flash found.
  • ABP vNext + Redis Streams:构建实时事件驱动架构
  • 桥接模式深度解析:Java设计模式实战指南与抽象实现分离架构设计
  • 25年春招:字节跳动客户端开发二面总结
  • 探索 Excel-to-JSON:高效数据转换的利器
  • 像素跟踪 跟踪像素 算法总结
  • linux安装阿里DataX实现数据迁移
  • AVL树的平衡艺术:用C++写出会“站立”的二叉树(未完待续)
  • uni-app 小程序 Cannot read property ‘addEventListener‘ of undefined, mounted hook