Skip to content

Commit 0261b67

Browse files
authored
Feature/cam info msg fix (#39)
* minor changes to adding camerainfo header in export_to_ros method * will handle if binning is set properly and wwarn if camera is not calibrated at full resolution
1 parent 45e72d5 commit 0261b67

File tree

6 files changed

+49
-26
lines changed

6 files changed

+49
-26
lines changed

include/spinnaker_sdk_camera_driver/camera.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ namespace acquisition {
6464
bool is_master() { return MASTER_; }
6565
void set_color(bool flag) { COLOR_ = flag; }
6666
void setGetNextImageTimeout(uint64_t get_next_image_timeout) { GET_NEXT_IMAGE_TIMEOUT_ = get_next_image_timeout; }
67+
bool verifyBinning(int binningDesired);
68+
void calibrationParamsTest(int calibrationWidth, int calibrationHeight);
6769

6870
private:
6971

include/spinnaker_sdk_camera_driver/capture.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ namespace acquisition {
110110

111111
int MASTER_CAM_;
112112
int CAM_; // active cam during live
113+
int image_width_;
114+
int image_height_;
113115

114116
bool FIXED_NUM_FRAMES_;
115117
bool TIME_BENCHMARK_;
@@ -126,6 +128,7 @@ namespace acquisition {
126128
bool EXPORT_TO_ROS_;
127129
bool MAX_RATE_SAVE_;
128130
bool PUBLISH_CAM_INFO_;
131+
bool VERIFY_BINNING_;
129132
uint64_t SPINNAKER_GET_NEXT_IMAGE_TIMEOUT_;
130133

131134
// grid view related variables

params/stereo_camera_example.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ delay: 1.0
2121

2222
#Camera info message details
2323
distortion_model: plumb_bob
24-
image_height: 1536
25-
image_width: 2048
24+
image_height: 1024 #1536
25+
image_width: 1280 #2048
2626
distortion_coeffs:
2727
- [-0.021141875266089592, -0.3733872931278025, 2.385982550579459, 3.2824571732099725]
2828
- [-0.021141875266089592, -0.3733872931278025, 2.385982550579459, 3.2824571732099725]

params/test_params.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
cam_ids:
2-
- 17197559
2+
- 18080146
33
cam_aliases:
44
- cam0
5-
master_cam: 17197559
5+
master_cam: 18080146
66
skip: 20
77
delay: 1.0
88

src/camera.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,16 @@ void acquisition::Camera::exposureTest() {
316316
ROS_DEBUG_STREAM("Exposure Time: "<<expTime<<endl);
317317

318318
}
319+
bool acquisition::Camera::verifyBinning(int binningDesired) {
320+
int actualBinningX = (pCam_ ->SensorWidth())/(pCam_ ->Width());
321+
int actualBinningY = (pCam_ ->SensorHeight())/(pCam_ ->Height());
322+
if (binningDesired == actualBinningX) return true;
323+
else return false;
324+
}
325+
326+
void acquisition::Camera::calibrationParamsTest(int calibrationWidth, int calibrationHeight) {
327+
if ( (pCam_ ->SensorWidth()) != calibrationWidth )
328+
ROS_WARN_STREAM(" Looks like your calibration is not done at full Sensor Resolution for cam_id = "<<get_id()<<" , Sensor_Width = "<<(pCam_ ->SensorWidth()) <<" given cameraInfo params:width = "<<calibrationWidth);
329+
if ( (pCam_ ->SensorHeight()) != calibrationHeight )
330+
ROS_WARN_STREAM(" Looks like your calibration is not done at full Sensor Resolution for cam_id = "<<get_id()<<" , Sensor_Height= "<<(pCam_ ->SensorHeight()) <<" given cameraInfo params:height = "<<calibrationHeight);
331+
}

src/capture.cpp

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ acquisition::Capture::Capture(): it_(nh_), nh_pvt_ ("~") {
104104
CAM_DIRS_CREATED_ = false;
105105

106106
GRID_CREATED_ = false;
107+
VERIFY_BINNING_ = false;
107108

108109

109110
//read_settings(config_file);
@@ -185,6 +186,7 @@ acquisition::Capture::Capture(ros::NodeHandle nodehandl, ros::NodeHandle private
185186
CAM_DIRS_CREATED_ = false;
186187

187188
GRID_CREATED_ = false;
189+
VERIFY_BINNING_ = false;
188190

189191

190192
//read_settings(config_file);
@@ -227,7 +229,6 @@ void acquisition::Capture::load_cameras() {
227229
bool master_set = false;
228230
int cam_counter = 0;
229231

230-
231232
for (int j=0; j<cam_ids_.size(); j++) {
232233
bool current_cam_found=false;
233234
for (int i=0; i<numCameras_; i++) {
@@ -260,16 +261,16 @@ void acquisition::Capture::load_cameras() {
260261
img_msgs.push_back(sensor_msgs::ImagePtr());
261262

262263
sensor_msgs::CameraInfoPtr ci_msg(new sensor_msgs::CameraInfo());
263-
int image_width = 0;
264-
int image_height = 0;
264+
//int image_width = 0;
265+
//int image_height = 0;
266+
nh_pvt_.getParam("image_height", image_height_);
267+
nh_pvt_.getParam("image_width", image_width_);
268+
// full resolution image_size
269+
ci_msg->height = image_height_;
270+
ci_msg->width = image_width_;
271+
265272
std::string distortion_model = "";
266-
nh_pvt_.getParam("image_height", image_height);
267-
nh_pvt_.getParam("image_width", image_width);
268273
nh_pvt_.getParam("distortion_model", distortion_model);
269-
ci_msg->header.frame_id = "cam_"+to_string(j)+"_optical_frame";
270-
// full resolution image_size
271-
ci_msg->height = image_height;
272-
ci_msg->width = image_width;
273274
// distortion
274275
ci_msg->distortion_model = distortion_model;
275276
// binning
@@ -316,13 +317,13 @@ void acquisition::Capture::load_cameras() {
316317
cam_info_msgs.push_back(ci_msg);
317318

318319
cam_counter++;
319-
320+
320321
}
321322
}
322323
if (!current_cam_found) ROS_WARN_STREAM(" Camera "<<cam_ids_[j]<<" not detected!!!");
323324
}
324325
ROS_ASSERT_MSG(cams.size(),"None of the connected cameras are in the config list!");
325-
326+
326327
ROS_ASSERT_MSG(master_set,"The camera supposed to be the master isn't connected!");
327328
// Setting numCameras_ variable to reflect number of camera objects used.
328329
// numCameras_ variable is used in other methods where it means size of cams list.
@@ -813,23 +814,15 @@ void acquisition::Capture::export_to_ROS() {
813814

814815
for (unsigned int i = 0; i < numCameras_; i++) {
815816
img_msg_header.frame_id = frame_id_prefix + "cam_"+to_string(i)+"_optical_frame";
817+
cam_info_msgs[i]->header = img_msg_header;
816818

817819
if(color_)
818820
img_msgs[i]=cv_bridge::CvImage(img_msg_header, "bgr8", frames_[i]).toImageMsg();
819821
else
820822
img_msgs[i]=cv_bridge::CvImage(img_msg_header, "mono8", frames_[i]).toImageMsg();
821823

822-
if (PUBLISH_CAM_INFO_){
823-
cam_info_msgs[i]->header.stamp = mesg.header.stamp;
824-
cam_info_msgs[i]->header.frame_id = frame_id_prefix + "cam_"+to_string(i)+"_optical_frame";
825-
}
826824
camera_image_pubs[i].publish(img_msgs[i],cam_info_msgs[i]);
827-
/*
828-
if (PUBLISH_CAM_INFO_){
829-
cam_info_msgs[i].header.stamp = mesg.header.stamp;
830-
camera_info_pubs[i].publish(cam_info_msgs[i]);
831-
}
832-
*/
825+
833826
}
834827
export_to_ROS_time_ = ros::Time::now().toSec()-t;;
835828
}
@@ -940,6 +933,18 @@ void acquisition::Capture::run_soft_trig() {
940933
save_mat_frames(0);
941934
}
942935

936+
if(!VERIFY_BINNING_){
937+
// Gets called only once, when first image is being triggered
938+
for (unsigned int i = 0; i < numCameras_; i++) {
939+
//verify if binning is set successfully
940+
ROS_ASSERT_MSG(cams[i].verifyBinning(binning_), " Failed to set Binning= %d, could be either due to Invalid binning value, try changing binning value or due to spinnaker api bug - failing to set lower binning than previously set value - solution: unplug usb camera and re-plug it back and run to node with desired valid binning", binning_);
941+
// warn if full sensor resolution is not same as calibration resolution
942+
cams[i].calibrationParamsTest(image_width_,image_height_);
943+
}
944+
VERIFY_BINNING_ = true;
945+
}
946+
947+
943948
ros::Rate ros_rate(soft_framerate_);
944949
try{
945950
while( ros::ok() ) {
@@ -1018,7 +1023,7 @@ void acquisition::Capture::run_soft_trig() {
10181023
break;
10191024
}
10201025
}
1021-
1026+
10221027
if (EXPORT_TO_ROS_) export_to_ROS();
10231028
//cams[MASTER_CAM_].targetGreyValueTest();
10241029
// ros publishing messages

0 commit comments

Comments
 (0)