I have a problem, that maybe I can solve here.
I created a model of cameras in gazebo and I need the cameras to generate a topical to get the information from the generated images. But I don't know how to make the camera generate the camera_info.
I have a problem, that maybe I can solve here.
I created a model of cameras in gazebo and I need the cameras to generate a topical to get the information from the generated images. But I don't know how to make the camera generate the camera_info.
Camera info is part of the so called image_pipeline. You should use the image_publisher to fulfill the interface.
The most straight forward way would be to implement / use an image publisher in your node. Check out the API to see whats the interface. You can see a lot of examples checking available drivers. A very good example / reference impmenentation is this implementation (full file):
/** Publish camera stream topics
*
* @pre image_ contains latest camera frame
*/
void publish()
{
image_.header.frame_id = config_.frame_id;
// get current CameraInfo data
cam_info_ = cinfo_->getCameraInfo();
//ROS_INFO_STREAM ("cam: " << cam_info_.width << " x " << cam_info_.height << ", image: " << image_.width << " x " << image_.height);
if (cam_info_.height != image_.height || cam_info_.width != image_.width)
{
// image size does not match: publish a matching uncalibrated
// CameraInfo instead
if (calibration_matches_)
{
// warn user once
calibration_matches_ = false;
ROS_WARN_STREAM("[" << camera_name_
<< "] camera_info_url: " << config_.camera_info_url);
ROS_WARN_STREAM("[" << camera_name_
<< "] calibration (" << cam_info_.width << "x" << cam_info_.height << ") does not match video mode (" << image_.width << "x" << image_.height << ") "
<< "(publishing uncalibrated data)");
}
cam_info_ = sensor_msgs::CameraInfo();
cam_info_.height = image_.height;
cam_info_.width = image_.width;
}
else if (!calibration_matches_)
{
// calibration OK now
calibration_matches_ = true;
ROS_INFO_STREAM("[" << camera_name_
<< "] calibration matches video mode now");
}
cam_info_.header.frame_id = config_.frame_id;
cam_info_.header.stamp = image_.header.stamp;
// @todo log a warning if (filtered) time since last published
// image is not reasonably close to configured frame_rate
// Publish via image_transport
image_pub_.publish(image_, cam_info_);
}