Ask Your Question
0

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()
    scanner.parse_config('enable')

    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)
        scanner.scan(image)

        qrc = None

        for symbol in image:
            qrc = symbol.data

        if qrc != None:
            qr_str = qrc
            rospy.loginfo(qr_str)

def qr_main():
    rospy.init_node('qr_listener')

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

    rospy.spin()

if __name__ == '__main__':
    qr_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
3

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

Comments

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

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

Question Tools

1 follower

Stats

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

Seen: 113 times

Last updated: Apr 15 '17