添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I am new to ROS. I am playing with integrating OpenCV and ROS. The code I am using is inspired from the ROS tutorial on converting ROS messages to CV::mat and back.

I am subscribing to the topic /raspicam_node/image/compressed published by the raspicam node. I have no problem getting the topic, converting it to CV:mat, and modifying it with OpenCV. Line 32 opens a window and shows me the modified CV:mat image.

My issue comes at Line 36. I can see the topic using rostopic list but when I echo it nothing comes up. Same if I use rqt_image_view .

Any thoughts on what I am missing? Thank you!

#!/usr/bin/env python
from __future__ import print_function
import roslib
roslib.load_manifest('comp_vision')
import sys
import rospy
import cv2
from std_msgs.msg import String
from sensor_msgs.msg import Image, CompressedImage
from cv_bridge import CvBridge, CvBridgeError
class ImageConverter:
    def __init__(self):
        self.image_pub = rospy.Publisher("modified_image", CompressedImage, queue_size=10)
        self.brige = CvBridge()
        self.image_sub = rospy.Subscriber("/raspicam_node/image/compressed", CompressedImage, self.callback)
    def callback(self,data):
            cv_image = self.brige.compressed_imgmsg_to_cv2(data, "passthrough")
        except CvBridgeError as e:
            print(e)
        (rows, cols, channels) = cv_image.shape
        if cols > 60 and rows > 60:
            cv2.circle(cv_image, (50,50), 10, 255)
        cv2.imshow("Image Window", cv_image)
        cv2.waitKey(3)
            self.image_pub.publish(self.brige.cv2_to_compressed_imgmsg(cv_image))
        except CvBridgeError as e:
            print(e)
def main(args):
    ic = ImageConverter()
    rospy.init_node("image_converter", anonymous=True)
        rospy.spin()
    except KeyboardInterrupt:
        print("shutting down")
    cv2.destroyAllWindows()
if __name__ == '__main__':
    main(sys.argv)
                check returned .cv2_to_compressed_imgmsg() type with CompressedImage message, that both must be same type message.
– Benyamin Jafari
                Aug 5, 2018 at 20:10

If you check rostopic echo /modified_image you can see that your topic is successfully published.

rqt_image_view will display it if you call your published topic modified_image/compressed.

From the compressed_image_transport wiki:

publish it on a topic of the form image_raw/compressed. Then any ROS node using image_transport can subscribe to image_raw with transport compressed, just as if image_transport were used on the publisher side

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.