首先根据下面这个文件,修改相应的参数,与自己的摄像头地址,制作topic并发布,使用python编译器运行这个文件

python3 xxx.py
#!/usr/bin/env python
import sys
import cv2
import rospy
from sensor_msgs.msg import Image
from cv_bridge import CvBridge
import os
import numpy as npdef read_cam():cap = cv2.VideoCapture("v4l2src device=/dev/video0 ! video/x-raw, width=640, height=512 ! videoconvert ! video/x-raw,format=BGR ! appsink")if cap.isOpened():while True:ret_val, img = cap.read()# print(ret_val, img)else:print("camera open failed")def videocapture():cap=cv2.VideoCapture("v4l2src device=/dev/video0 ! video/x-raw, width=640, height=512 ! videoconvert ! video/x-raw,format=BGR ! appsink")     #生成读取摄像头对象width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))  #获取视频的宽度height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))  #获取视频的高度fps = cap.get(cv2.CAP_PROP_FPS) #获取视频的帧率fourcc = int(cap.get(cv2.CAP_PROP_FOURCC))    #视频的编码print(fourcc)#定义视频对象输出writer = cv2.VideoWriter("video_result.mp4", fourcc, fps, (width, height))while cap.isOpened():ret, frame = cap.read() #读取摄像头画面cv2.imshow('teswell', frame) #显示画面key = cv2.waitKey(24)writer.write(frame)  #视频保存# 按Q退出if key == ord('q'):breakcap.release()         #释放摄像头cv2.destroyAllWindows() #释放所有显示图像窗口class ImagePublisher(object):def __init__(self):# self.image = Noneself.br = CvBridge()# Node cycle rate (in Hz)self.loop_rate = rospy.Rate(20)# Publishersimage_topic = rospy.get_param("~topic_name","image_IR")# the topic name is defined in the private namespaceself.pub = rospy.Publisher(image_topic,Image,queue_size=1) # always publish the latest# video device to captureself.device_type = rospy.get_param("~device_type","GMSL")self.device = rospy.get_param("~device",'/dev/video0') # get the deviceself.width = rospy.get_param("~width",'640')self.height = rospy.get_param("~height",'512')self.fps = rospy.get_param("~fps",'30')self.frame_id = rospy.get_param("~frame_id","camera_link_0")self.to_push_stream = rospy.get_param("~to_push_stream","True")self.cap = cv2.VideoCapture("v4l2src device=/dev/video0 ! video/x-raw, width=640, height=512 ! videoconvert ! video/x-raw,format=BGR ! appsink")     #生成读取摄像头对象def run(self):while not rospy.is_shutdown():ret, frame = self.cap.read()now = rospy.get_rostime()if ret:image_msg = self.br.cv2_to_imgmsg(frame)image_msg.header.stamp.secs = now.secsimage_msg.header.stamp.nsecs = now.nsecsimage_msg.header.frame_id = self.frame_idself.pub.publish(image_msg)else:breakself.loop_rate.sleep()self.cap.release()if __name__ == '__main__':rospy.init_node("image_publisher",anonymous=True)publisher = ImagePublisher()publisher.run()       

使用以下命令录制数据:

rosbag record -o xxx  /**1  /**2

xxx为希望保存话题的路径和名字
/**1 /**2 为希望录制的话题

但是这种情况很有可能出现以下错误

rosbag record buffer exceeded. Dropping oldest queued message

即录制的话题数太多了,处理器处理不过来,因此我们可以参考一下链接解决
http://wiki.ros.org/rosbag/Commandline#record

我的处理命令是:

resbag record -O xxx -b 4096 /**1 /**2

这样就会增大我的缓存空间,减少丢帧的可能

读取gmsl接口数据,rosbag录制话题相关推荐

  1. 使用JS实现无刷新读取json接口数据

    使用JS实现无刷新读取json接口数据 Ajax方法 //ajax function ajax(method, url, asy, fn) {//创建Ajax对象if (window.XMLHttpR ...

  2. rosbag录制话题、播放话题多种模式

    录制所有话题 rosbag record -a 录制多个话题 rosbag record -a //录制所有话题,并以当前时间截为文件名称 rosbag record /topic1 /topic2 ...

  3. rosbag录制数据与解包

    文章目录 一.rosbag录制数据 二.bag数据播放 三.bag解包出图像数据(三种方式) 1.ROS Wiki提供的roslaunch文件解包 2.python解包 3.用kalibr的一个工具解 ...

  4. python接口自动化参数化_Python读取txt文件数据的方法(用于接口自动化参数化数据)...

    小试牛刀: 1.需要python如何读取文件 2.需要python操作list 3.需要使用split()对字符串进行分割 代码运行截图 : 代码(copy) #encoding=utf-8 #1.r ...

  5. 读取EXCEL文件数据,再调用第三方接口,将第三方数据重新写入到EXCEL文件

    读取EXCEL文件数据,再调用第三方接口,将第三方数据重新写入到EXCEL文件 工作中涉及很多提供文档数据,少则几条,多则上万,少的可以自己编辑一个,静态final来自己定义,一旦数太多得话,就得使用 ...

  6. KETTLE读取api接口(rest接口)数据

    KETTLE读取api接口(rest接口)数据

  7. python读取txt文件并求和,Python读取txt文件数据的方法(用于接口自动化参数化数据)...

    小试牛刀: 1.需要python如何读取文件 2.需要python操作list 3.需要使用split()对字符串进行分割 代码运行截图 : 代码(copy) #encoding=utf-8 #1.r ...

  8. Andorid手机从Type-C接口读取U盘数据

    最近,公司的一个项目用到了一项比较新的技术,就是使用android手机,从Type-C接口读取Type-c接口的U盘数据.于是根据新的需求做了一系列的实验,其中遇到了不少的坑,于是记录如下: 1.首先 ...

  9. rosbag录制和回放

    rosbag录制和回放 1. 录制 2. 回放 3. 参考 本博客参照一位大佬YongqiangGao的博客实现仿真环境中一个 7 轴机械臂画圆时的 joint_states 数据,在此记录以供自己加 ...

最新文章

  1. python并发与并行_python多进程,多线程分别是并行还是并发
  2. sort +awk+uniq 统计文件中出现次数最多的前10个单词yes3
  3. Python小游戏(打乒乓)
  4. Qt文档阅读笔记-隐式共享(Implicit Sharing)深入研究(理论及实例)
  5. WIndows thinpc 精简版的WIN7
  6. 关于cocos2d-js中使用 ClippingNode 以及 BlendFunc 来实现遮罩
  7. getBoundingClientRect()
  8. 不设置DIV的宽高,让它相对于页面水平垂直居中
  9. 《Essential C++》笔记之(static)静态类成员
  10. 频繁使用花呗、借呗、微粒贷、京东白条会影响在银行的信用吗?
  11. Mysql 监控性能状态 QPS/TPS
  12. python复杂网络库networkx:算法
  13. Linux中/etc/fstab /etc/mtab /proc/mounts这三个文件的分析与比较
  14. TurboFan-Sea of Nodes概念讲解
  15. Atitit mybatis3 注解模式使用总结 目录 1. mybatisdemo 1 1.1. /ormMybatis3demo/src/db.properties 1 1.2. /ormMyb
  16. Vissim与python(IntelliJ IDEA )联调环境配置
  17. windows”出现身份验证错误,要求的函数不正确“的解决方法
  18. 一个骨灰级塞班开发者的自白
  19. 前端html网站的发布过程
  20. 新贵 轻雅 100 数字键 numlock问题

热门文章

  1. 类的继承编程训练1—储蓄卡与信用卡
  2. Linux安装Docker CE
  3. # Linux学习笔记
  4. HTML页面刷新方法
  5. 天玑9200搭载Arm最新旗舰GPU,性能爆表!支持移动端硬件光追
  6. 【算法】倒水游戏(BFS|C++)
  7. 温度传感器Pt100 热电阻的原理
  8. 安居客 楼盘信息 项目代码-
  9. Android MVVM封装,MVVM: 这是一个android MVVM 框架,基于谷歌dataBinding技术实现
  10. Sqli-labs Less7