zbar_ros does not detect QR codes from Gazebo camera sensor
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:
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.