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

zbar_ros does not detect QR codes from Gazebo camera sensor

asked 2017-01-31 05:40:34 -0500

Cees gravatar image

I would like to detect QR codes in my gazebo simulation. To do this, I would like to use the zbar_ros package, since it is fast and has a small footprint. While I was able to detect QR codes using a real camera (simple usb camera), I cannot get it working with the virtual Gazebo camera sensor.

I expect that the problem is in the encoding of the image, but I am not sure: I do not see the flaw in the configuration (and I tried a lot of different configurations already). Any ideas?

To be clear: the node does not crash. It just detects zero codes.

Sensor section in my URDF

    <camera name='__default__'>
      <horizontal_fov>1.047</horizontal_fov>
      <image>
        <width>1280</width>
        <height>720</height>
        <format>B8G8R8</format>
      </image>
      <clip>
        <near>0.1</near>
        <far>100</far>
      </clip>
    </camera>

Some lines from my version of zbar_ros barcode_reader_nodelet.cpp

void BarcodeReaderNodelet::imageCb(const sensor_msgs::ImageConstPtr &image)
{
cv_bridge::CvImageConstPtr cv_image;
cv_image = cv_bridge::toCvShare(image, "bgr8");

zbar::Image zbar_image(cv_image->image.cols, cv_image->image.rows, "GREY", cv_image->image.data,
    cv_image->image.cols * cv_image->image.rows);

And some proof that is really should be able to detect the code: Code in virtual image

For the sake of completeness:

  • The default second argument for toCvShare() was mono16. That did not work for my webcam as well, mono8 did.
  • I matched the second argument of toCvShare() to the configuration in my URDF: B8G8R8.
  • zbar_image can also be initialized with the format "Y800" instead of "GREY". If I understand correctly, zbar_image does some conversion itself, so I prefer to do everything in grayscale.
  • Making the QR code bigger does not help.
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-02-15 05:03:13 -0500

Cees gravatar image

So, I figured out why this is not working.

My initial approach was to revert to the settings of the real camera (since detection worked for this camera), and check the encoding by examining the messages on the camera topic. Turned out the encoding was RGB8. So: I changed my Gazebo camera settings to R8G8B8, and indeed: the encoding on the virtual topic was now RGB8. However: QR Codes were still not detected.

I changed the zbar_ros nodes a little bit to show an OpenCV window to make sure the translation to OpenCV images was going well. This was the case, so the problem was still unknown.

While on the verge of a mental breakdown, desperately staring at my screen, I noticed a difference between the QR code in simulation and the physical code on my desk: it was mirrored! Apparently, the QR code reader on my phone allows for mirrored QR codes, and was able to recognize it in the simulation, while zbar_ros does not support mirrored QR codes.

So, in short: mirroring my textures solved everything.

edit flag offensive delete link more

Comments

I feel this might be nice to document somewhere (other than here on ROS Answers), but I don't really know where would be the best place for this.

re: mirorred: have you verified that Gazebo renders everything correctly? There have been problems with the simulated camera in the past.

gvdhoorn gravatar image gvdhoorn  ( 2017-02-15 05:20:53 -0500 )edit

I am not sure either: It is not related to zbar_ros, not really to Gazebo as well, but to Ogre3D if I understand correctly. I feel I do not know enough about how Ogre3D applies texture to recognize if this is a bug or not. If there is anything I can do to validate if the camera works correctly, lmk.

Cees gravatar image Cees  ( 2017-02-15 05:57:15 -0500 )edit
1

nice find! Feel free to add a gazebo-related note to the zbar_ros wiki.

paulbovbel gravatar image paulbovbel  ( 2017-02-17 07:27:40 -0500 )edit

Will do somewhere the coming weeks, but first I'd like to validate if it has anything to do with this: http://answers.ros.org/question/23253...

Cees gravatar image Cees  ( 2017-02-17 12:31:51 -0500 )edit
0

answered 2017-02-04 00:19:07 -0500

paulbovbel gravatar image

updated 2017-02-04 00:19:23 -0500

Definitely never tried this out with gazebo. Mea culpa for not breaking those configs out in rosparam to being with.

Between the supported formats on input ( http://docs.ros.org/jade/api/sensor_m... ) and zbar ( http://stackoverflow.com/questions/33... ), these settings are likely to be application specific.

edit flag offensive delete link more

Comments

Thank you for your response! What would you expect to work in my situation? One of the things that came to mind was trying to use "mono8" with "GREY", because that seems an obvious match. No success, however...

Cees gravatar image Cees  ( 2017-02-04 03:27:32 -0500 )edit

I honestly have no idea, I've never dealt with image formats.

paulbovbel gravatar image paulbovbel  ( 2017-02-07 13:36:56 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-01-31 05:40:34 -0500

Seen: 976 times

Last updated: Feb 15 '17