How to use camera_info_manager to publish camera_info
I am trying to calibrate my ov7251 camera using the camera_calibration package. I adapted a sample camera driver that I found which use the UV4L API so that I can try to publish images to the ROS topic /camera/image. I am also publishing to /camera/camera_info. However, what I need now is to be able to run the /camera/set_camera_info service so that I can use the calibration package.
Here is my code for publishing to /camera/image and /camera/camera_info:
int main(int argc, char **argv) {
dev_name = "/dev/video2";
namedWindow( "Camera Preview", WINDOW_AUTOSIZE );// Create a window for display.
ros::init(argc, argv, "image_publisher");
ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::Publisher pub = it.advertise("camera/image", 1);
ros::Publisher pub_info = nh.advertise<sensor_msgs::CameraInfo>("camera/camera_info", 100);
sensor_msgs::CameraInfo cam_info;
open_device();
init_device();
start_capturing();
while (nh.ok()) {
read_frame();
if (!prev.empty()) {
cv::Mat image = prev;
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();
ros::Rate loop_rate(5);
cam_info.header.stamp = ros::Time::now();
pub_info.publish(cam_info);
pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
}
}
...
return 0;
}
When I ran rostopic list, this is what I get:
/camera/camera_info
/camera/image
/camera/image/compressed
/camera/image/compressed/parameter_descriptions
/camera/image/compressed/parameter_updates
/camera/image/compressedDepth
/camera/image/compressedDepth/parameter_descriptions
/camera/image/compressedDepth/parameter_updates
/camera/image/theora
/camera/image/theora/parameter_descriptions
/camera/image/theora/parameter_updates
/camera/image_raw
/rosout
/rosout_agg
/statistics
/svo/dense_input
/svo/image
/svo/image/compressed
/svo/image/compressed/parameter_descriptions
/svo/image/compressed/parameter_updates
/svo/image/compressedDepth
/svo/image/compressedDepth/parameter_descriptions
/svo/image/compressedDepth/parameter_updates
/svo/image/theora
/svo/image/theora/parameter_descriptions
/svo/image/theora/parameter_updates
/svo/info
/svo/keyframes
/svo/points
/svo/pose
/svo/remote_key
/tf
And when I run rosservice list:
/camera/image/compressed/set_parameters
/camera/image/compressedDepth/set_parameters
/camera/image/theora/set_parameters
/image_publisher/get_loggers
/image_publisher/set_logger_level
/rosout/get_loggers
/rosout/set_logger_level
/rqt_gui_py_node_13721/get_loggers
/rqt_gui_py_node_13721/set_logger_level
/rqt_gui_py_node_13807/get_loggers
/rqt_gui_py_node_13807/set_logger_level
/svo/get_loggers
/svo/image/compressed/set_parameters
/svo/image/compressedDepth/set_parameters
/svo/image/theora/set_parameters
/svo/set_logger_level
As you can see, I don't have a /set_camera_info service, which I think is the main problem I am having with trying to run the camera_calibration package. If anyone can please provide me with a simple sample code for using the camera_info_manager, it would be much appreciated.
EDIT: For now, I wish to simply initialize a camera_info_manager object so that I can use its functions to run the set_camera_info service, but I am not well-versed with C++ so I am having some problems understanding the tutorial for camera_info_manager.
EDIT2: I added these two lines in, based on @joq's comments:
boost::shared_ptr<camera_info_manager::CameraInfoManager> cinfo;
cinfo(new camera_info_manager::CameraInfoManager(nh));
but I only get this error:
no match for call to ‘(boost::shared_ptr<camera_info_manager::CameraInfoManager>) (camera_info_manager::CameraInfoManager*)’
cinfo(new camera_info_manager::CameraInfoManager(nh));
As a separate approach, I have also tried to simply do this to instantiate a camera info manager:
camera_info_manager::CameraInfoManager cinfo(nh, "camera","");
but then I get this error:
CMakeFiles/vga_cam_publisher.dir/src/vga_cam_publisher.cpp.o: In function ...
Have you tried usb_cam package. It will automatically start the required service for camera calibration.
Yes, I have. But the main problem with the drivers that I looked through was that they did not give me the option to enter a "device_id", just the "device_name". Although I can set the param as "/dev/videoN", I think I need to be able to set the "device_id" to 0 or 1.
The error that I would get is
[ERROR] [1515087853.012401358]: VIDIOC_S_FMT error 22, Invalid argument