Incorrect camera extrinsics for simulated Gazebo cameras

I am simulating several cameras in Gazebo using the gazebo_ros_camera plugin in the gazebo_plugins package. All of the cameras are defined in the robot's URDF and the corresponding coordinate frames are published by the joint_state_publisher and robot_state_publisher nodes.

When I view frames captured from the simulated cameras, it is clear that they are pointing in roughly the correct direction. If I view the simulated world in RViz, the visualized world renders correctly for horizontal cameras (left), but not for cameras with a non-zero pitch (right):

It appears that the images captured in Gazebo have approximately twice the pitch that is specified in the URDF (note how the ground plane projected by RViz is too high in the right image). Has anyone else run into a similar problem?

edit retag close merge delete

Sort by » oldest newest most voted

Hi,

For pin hole cameras that gazebo is simulating, the equation below holds,

focal_lengtth = image_width / (2*tan(hfov_radian / 2)


One way to avoid inconsistency is to NOT specify <focal_length> tag in your XML. That way, <focal_length> is calculated using the above formula.

In addition, I'll patch gazebo_ros_camera plugin to raise an inconsistency error message when a focal_length is provided that is inconsistent with image_width and hfov.

Will that fix the problem for you?

Thanks, John

more

I found the problem. In the PR2 sample code, there is a a comment above the focal_length element:

<!-- image_width / (2*tan(hfov_radian /2)) -->
<!-- 320 for wide and 772.55 for narrow stereo camera -->
<focal_length>320</focal_length>


I assumed that this was a PR2-specific comment and set focal_length to my camera's actual focal length. It turns out that always uses the value image_width / (2*tan(hfov_radian / 2), and only uses the value of focal_length for publishing camera_info. If focal_length is set to a different value, the focal length used by Gazebo will not match the focal length used by RViz. Making both focal lengths match fixed the rendering differences.

more

please see ticket with patch.

more

Note that this won't fix the problem for you automatically as noted above... should I make the plugin overwrite the incorrect focal_length variable? I thought maybe some users might want the flexibility of specifying an incorrect focal length for testing purposes.

more

I can't think of a situation where specifying an invalid focal length would be useful for testing. Since Gazebo ignores this field, all nodes that use the published camera_info will give incorrect results. Adding a ROS_ERROR or ROS_WARNING sounds like a great solution. Thanks for your help!
( 2011-04-20 16:32:55 -0500 )edit