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

Listener does not update [closed]

asked 2017-04-15 11:45:29 -0500

icarold gravatar image

updated 2017-04-15 12:12:18 -0500

Good afternoon friends

I can get an image of the camera from the gazebo: /camera/image_raw. But if you change the qr code, the listener does not update.

Can anyone help me with this?

#! /usr/bin/python

import rospy
import numpy as np
import cv2
import cv
import zbar

from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge

bridge = CvBridge()

def callback(msg):
    cv2_img = bridge.imgmsg_to_cv2(msg, "bgr8")
    scanner = zbar.ImageScanner()

    while not rospy.is_shutdown():
        gray = cv2.cvtColor(cv2_img, cv2.COLOR_BGR2GRAY, dstCn=0)

        frame = np.array(gray)
        width, height = frame.shape[1], frame.shape[0]

        raw = frame.tostring()

        image = zbar.Image(width, height, 'Y800', raw)

        qrc = None

        for symbol in image:
            qrc =

        if qrc != None:
            qr_str = qrc

def qr_main():

    rospy.Subscriber("/camera/image_raw", Image, callback)


if __name__ == '__main__':
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-16 03:47:46.775999

1 Answer

Sort by ยป oldest newest most voted

answered 2017-04-15 12:46:32 -0500

NEngelhard gravatar image

updated 2017-04-15 13:19:39 -0500

The problem is that your callback does not terminate. This function is called whenever new data arrives. You however, have in infinite loop within your callback so that you look for the qr-code in the first image over an over again. You somehow assume that your cv2_img-variable gets somehow updated. Wouldn't it be extremely inconvenient if one of your variable changes suddenly why you process it?

edit flag offensive delete link more


Great, my friend!! The problem was the loop!!! Thanks alot for the help!!

icarold gravatar image icarold  ( 2017-04-15 13:30:07 -0500 )edit

Question Tools

1 follower


Asked: 2017-04-15 11:45:29 -0500

Seen: 504 times

Last updated: Apr 15 '17