@@ -251,24 +251,30 @@ void acquisition::Capture::load_cameras() {
251251 // camera_info_pubs.push_back(nh_.advertise<sensor_msgs::CameraInfo>("camera_array/"+cam_names_[j]+"/camera_info", 1));
252252
253253 img_msgs.push_back (sensor_msgs::ImagePtr ());
254+
255+ sensor_msgs::CameraInfoPtr ci_msg (new sensor_msgs::CameraInfo ());
256+ int image_width = 0 ;
257+ int image_height = 0 ;
258+ std::string distortion_model = " " ;
259+ nh_pvt_.getParam (" image_height" , image_height);
260+ nh_pvt_.getParam (" image_width" , image_width);
261+ nh_pvt_.getParam (" distortion_model" , distortion_model);
262+ ci_msg->header .frame_id = " cam_" +to_string (j)+" _optical_frame" ;
263+ // full resolution image_size
264+ ci_msg->height = image_height;
265+ ci_msg->width = image_width;
266+ // distortion
267+ ci_msg->distortion_model = distortion_model;
268+ // binning
269+ ci_msg->binning_x = binning_;
270+ ci_msg->binning_y = binning_;
271+
254272 if (PUBLISH_CAM_INFO_){
255- sensor_msgs::CameraInfoPtr ci_msg (new sensor_msgs::CameraInfo ());
256- int image_width = 0 ;
257- int image_height = 0 ;
258- std::string distortion_model = " " ;
259- nh_pvt_.getParam (" image_height" , image_height);
260- nh_pvt_.getParam (" image_width" , image_width);
261- nh_pvt_.getParam (" distortion_model" , distortion_model);
262- ci_msg->header .frame_id = " cam_" +to_string (j)+" _optical_frame" ;
263- // full resolution image_size
264- ci_msg->height = image_height;
265- ci_msg->width = image_width;
266- // distortion
267- ci_msg->distortion_model = distortion_model;
268273 ci_msg->D = distortion_coeff_vec_[j];
269274 // intrinsic coefficients
270- for (int count = 0 ; count<intrinsic_coeff_vec_[j].size ();count++)
275+ for (int count = 0 ; count<intrinsic_coeff_vec_[j].size ();count++){
271276 ci_msg->K [count] = intrinsic_coeff_vec_[j][count];
277+ }
272278 // Rectification matrix
273279 if (!rect_coeff_vec_.empty ())
274280 ci_msg->R = {
@@ -287,7 +293,8 @@ void acquisition::Capture::load_cameras() {
287293 proj_coeff_vec_[j][8 ], proj_coeff_vec_[j][9 ],
288294 proj_coeff_vec_[j][10 ], proj_coeff_vec_[j][11 ]};
289295 }
290- else if (numCameras_ == 1 ){
296+ // else if(numCameras_ == 1){
297+ else if (cam_ids_.size () == 1 ){
291298 // for case of monocular camera, P[1:3,1:3]=K
292299 ci_msg->P = {
293300 intrinsic_coeff_vec_[j][0 ], intrinsic_coeff_vec_[j][1 ],
@@ -297,19 +304,23 @@ void acquisition::Capture::load_cameras() {
297304 intrinsic_coeff_vec_[j][6 ], intrinsic_coeff_vec_[j][7 ],
298305 intrinsic_coeff_vec_[j][8 ], 0 };
299306 }
300- // binning
301- ci_msg->binning_x = binning_;
302- ci_msg->binning_y = binning_;
303-
304- cam_info_msgs.push_back (ci_msg);
305307 }
308+
309+ cam_info_msgs.push_back (ci_msg);
310+
306311 cam_counter++;
312+
307313 }
308314 }
309315 if (!current_cam_found) ROS_WARN_STREAM (" Camera " <<cam_ids_[j]<<" not detected!!!" );
310316 }
311317 ROS_ASSERT_MSG (cams.size ()," None of the connected cameras are in the config list!" );
312318 ROS_ASSERT_MSG (master_set," The camera supposed to be the master isn't connected!" );
319+ // Setting numCameras_ variable to reflect number of camera objects used.
320+ // numCameras_ variable is used in other methods where it means size of cams list.
321+ numCameras_ = cams.size ();
322+ // setting PUBLISH_CAM_INFO_ to true so export to ros method can publish it_.advertiseCamera msg with zero intrisics and distortion coeffs.
323+ PUBLISH_CAM_INFO_ = true ;
313324}
314325
315326
@@ -558,7 +569,7 @@ void acquisition::Capture::read_parameters() {
558569 if (PUBLISH_CAM_INFO_)
559570 ROS_INFO (" Camera coeffs provided, camera info messges will be published." );
560571 else
561- ROS_INFO (" Camera coeffs not provided correctly, camera info messges will not be published." );
572+ ROS_WARN (" Camera coeffs not provided correctly, camera info messges intrinsics and distortion coeffs will be published with zeros ." );
562573
563574// ROS_ASSERT_MSG(my_list.getType()
564575// int num_ids = cam_id_vec.size();
0 commit comments