This weekend I wanted to see if I could calibrate the camera for ROS. I’ve done this before on a different robot in the past (during a course I took). Ultimately I was not successful. But figured I’d document a few things here for the sake of others.
- The raspicam_node by default only publishes compressed images. Turns out you can’t run the calibration program with compressed images.
- You can change the flag in the launch file so that it will publish raw images.
- I ran the calibration program on my laptop (see the camera calibration tutorial for steps). I got a very distorted image.
- Running rqt_image_view I was not getting an image when subscribed to the raspicam_node/image topic (whereas the picture looked fine subscribed to image/compressed). In the shell I was getting error messages
ImageView.callback_image() while trying to convert image from 'bgr8' to 'rgb8' an exception was thrown (Image is wrongly formed: height * step != size or 308 * 1230 != 399360)
A couple hours of googling and looking at ROS answers did not find a solution.
So no joy there. But…
- the raspicam_node actually comes with calibration .yaml files. I don’t know how good these generic files are, versus calibrating for one’s specific camera. Perhaps the Raspberry Pi cameras are consistent enough that this suffice’s. I hope so since that’s what I’m stuck with for now. These files are in the raspicam_node/camera_info folder
- the launch file has a url that ostensibly points to the appropriate file, but it doesn’t seem to be configured correctly - I’d always get messages that the file wasn’t found. I changed the line to
<param name="camera_info_url" value="file://$(find raspicam_node)/camera_info/camerav2_410x308.yaml"/>
that seemed to work OK - the startup [INFO] messages would say the file was found and the camera was calibrated
- even after that, the startup would still go on to say that it was looking for the default URL for a calibration file. I ended up copying all of the generic calibration files to /home/pi/.ros/camera_info. With that done, I no longer got messages saying that the calibration files couldn’t be found.
I don’t know yet if the generic calibration files are good enough. I want to use the camera to recognize AprilTags. Will update this thread once I’ve tried.