ros订阅图片python_ROS与Python入门教程-CompressedImage类型的订阅器和发布器

这篇教程介绍了如何在ROS中订阅和发布CompressedImage类型的主题,使用Python将接收到的压缩图像转换为numpy数组,进行特征检测并重新发布。通过创建一个名为image_feature的类,实现了从/camera/image/compressed主题订阅图像,使用OpenCV进行特征检测,并将结果以CompressedImage形式发布到/output/image_raw/compressed主题。
摘要由CSDN通过智能技术生成

ROS与Python入门教程-CompressedImage类型的订阅器和发布器

说明

这一节介绍订阅包含sensor_msgs::CompressedImage的主题,转换CompressedImage为numpy.ndarray,从而做检测和标记,再发布为CompressedImage类型的主题。

实现

在beginner_tutorials/scripts目录,新建subscriber_publisher_CompressedImage.py

$ roscd beginner_tutorials/scripts/

$ touch subscriber_publisher_CompressedImage.py

$ chmod +x subscriber_publisher_CompressedImage.py

$ rosed beginner_tutorials subscriber_publisher_CompressedImage.py

手工输入如下完整示例代码:(忽略注释部分)

#!/usr/bin/env python

"""OpenCV feature detectors with ros CompressedImage Topics in python.

This example subscribes to a ros topic containing sensor_msgs

CompressedImage. It converts the CompressedImage into a numpy.ndarray,

then detects and marks features in that image. It finally displays

and publishes the new image - again as CompressedImage topic.

"""

__author__ = 'Simon Haller '

__version__= '0.1'

__license__ = 'BSD'

# Python libs

import sys, time

# numpy and scipy

import numpy as np

from scipy.ndimage import filters

# OpenCV

import cv2

# Ros libraries

import roslib

import rospy

# Ros Messages

from sensor_msgs.msg import CompressedImage

# We do not use cv_bridge it does not support Compresse

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值