0
$\begingroup$

Rosanswers logo

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

Originally posted by icarold on ROS Answers with karma: 5 on 2017-04-12

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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)

Originally posted by NEngelhard with karma: 3519 on 2017-04-12

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by icarold on 2017-04-12:
Many thanks, my friend !! Lack of attention to mine. I'll test here

Comment by icarold on 2017-04-12:
The command did not work:

from visualization_msgs.msg import Image
ImportError: cannot import name Image

Comment by jarvisschultz on 2017-04-12:
@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.

Comment by jarvisschultz on 2017-04-12:
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.

Comment by NEngelhard on 2017-04-13:
sorry, it's of course in sensor_msgs, fixed it

Comment by icarold on 2017-04-13:
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'

Comment by icarold on 2017-04-13:
If I take the read() error in the:

ret, output = data
TypeError: 'Image' object is not iterable

Comment by NEngelhard on 2017-04-13:
why do you think that an Image-object has a read-function? http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython

Comment by icarold on 2017-04-13:
Thanks friends for the help!! NEngelhard, this link that you sent helped me and it worked, I managed to do !! Thank you

Comment by NEngelhard on 2017-04-13:
great! then please mark the answer as correct so that the question can be closed

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.