ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Problem Listener with [closed]

asked 2017-04-12 09:35:38 -0600

icarold gravatar image

Good morning people

I did a listener for the camera/image_raw node republish (camera/image_test, but the following error appears: Client [/ QR_Listener_5598_1492006578702] wants topic /camera/image_test to have datatype/md5sum [std_msgs /String/992ce8a1687cec8c8bd883ec73ca41d1], but our version has [sensor_msgs/Image/060021388200f6f0f447d0fcd9c64743]. Dropping connection.

Follow the listener code:

#!/usr/bin/env python

import rospy
import cv2
import zbar

from std_msgs.msg import String
from PIL import Image

def callback(data):
    scanner = zbar.ImageScanner()
    scanner.parse_config('enable')

    while not rospy.is_shutdown():
        ret, output = data.read()

        if not ret:
            continue

        gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY, dstCn=0)
        pil = Image.fromarray(gray)
        width, height = pil.size
        raw = pil.tobytes()
        image = zbar.Image(width, height, 'Y800', raw)
        scanner.scan(image)

        qrc = None

        for symbol in image:
            print '"%s"' % symbol.data
            qrc = symbol.data

        qrc

        cv2.imshow("#Qr Code", output)

        if qrc != None:
            rospy.loginfo(rospy.get_caller_id() + "Qr Code %s:", data.data)


def listener():
    rospy.init_node('QR_Listener', anonymous=True)

    rospy.Subscriber("/camera/image_test", String, callback)

    rospy.spin()


if __name__ == '__main__':
    try:
        listener()

    except rospy.ROSInterruptException:
        pass
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by NEngelhard
close date 2017-04-14 09:59:29.534867

1 Answer

Sort by » oldest newest most voted
3

answered 2017-04-12 10:41:49 -0600

NEngelhard gravatar image

updated 2017-04-13 01:44:51 -0600

The answer is already in the error message: You create a std_msgs::String subscriber to listen to an sensor_msgs::Image message.

So it should be

from sensor_msgs.msg import Image
(...)

 rospy.Subscriber("/camera/image_test", Image, callback)
edit flag offensive delete link more

Comments

Many thanks, my friend !! Lack of attention to mine. I'll test here

icarold gravatar image icarold  ( 2017-04-12 11:07:12 -0600 )edit

The command did not work:

from visualization_msgs.msg import Image
ImportError: cannot import name Image
icarold gravatar image icarold  ( 2017-04-12 20:47:35 -0600 )edit

@icarold You should not add an answer that is not really an answer. If you need to add information, please edit your original question. I've moved your answer to be a comment.

jarvisschultz gravatar image jarvisschultz  ( 2017-04-12 22:47:17 -0600 )edit
1

The error described in your comment is because the visualization_msgs package doesn't have a message called Image (it has ImageMarker). My guess is that you are actually looking for the sensor_msgs/Image message type.

jarvisschultz gravatar image jarvisschultz  ( 2017-04-12 22:49:07 -0600 )edit

sorry, it's of course in sensor_msgs, fixed it

NEngelhard gravatar image NEngelhard  ( 2017-04-13 01:46:11 -0600 )edit

I used the sensor_msgs.msg import image as suggested, but now it is giving no error data.read().

File "/home/icaro/catkin_ws/src/tcc/scripts/listener_qr.py", line 14, in callback
     Ret, output = data.read ()
AttributeError: 'Image' object has no attribute 'read'
icarold gravatar image icarold  ( 2017-04-13 09:32:39 -0600 )edit

If I take the read() error in the:

ret, output = data
TypeError: 'Image' object is not iterable
icarold gravatar image icarold  ( 2017-04-13 09:33:05 -0600 )edit
2

why do you think that an Image-object has a read-function? http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython

NEngelhard gravatar image NEngelhard  ( 2017-04-13 15:15:23 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-04-12 09:35:38 -0600

Seen: 1,188 times

Last updated: Apr 13 '17