Skip to content

Commit fd3d35e

Browse files
author
Vikrant Shah
authored
Merge pull request #17 from utkarshjp7/master
Publish camera info topic with complete information.
2 parents d9a0527 + f4fe280 commit fd3d35e

File tree

4 files changed

+84
-10
lines changed

4 files changed

+84
-10
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,19 @@ This is the names that would be given to the cameras for filenames and rostopics
8989
Secs to wait in the deinit/init sequence
9090

9191
### Camera info message details
92+
* ~image_width (int)
93+
* ~image_height (int)
9294
* ~distortion_model (string)
9395
Distortion model for the camera calibration. Typical is 'plumb_bob'
9496
* ~distortion_coeffs (array of arrays)
9597
Distortion coefficients of all the cameras in the array. Must match the number of cam_ids provided.
9698
* ~intrinsic_coeff (array of arrays)
9799
Intrinsic coefficients of all the cameras in the array. Must match the number of cam_ids provided.
98-
Specified as [fx 0 cx 0 fy cy 0 0 1]
100+
Specified as [fx 0 cx 0 fy cy 0 0 1]
101+
* ~projection_coeffs (array of arrays)
102+
Projection coefficients of all the cameras in the array. Must match the number of cam_ids provided.
103+
* ~rectification_coeffs (array of arrays)
104+
Rectification coefficients of all the cameras in the array. Must match the number of cam_ids provided.
99105

100106
## Multicamera Master-Slave Setup
101107
When using multiple cameras, we have found that the only way to keep images between different cameras synched is by using a master-slave setup using the GPIO connector. So this is the only way we support multicamera operation with this code. A general guide for multi camera setup is available at https://www.ptgrey.com/tan/11052, however note that we use a slightly different setup with our package.

include/spinnaker_sdk_camera_driver/capture.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ namespace acquisition {
7575
vector< vector<Mat> > mem_frames_;
7676
vector<vector<double>> intrinsic_coeff_vec_;
7777
vector<vector<double>> distortion_coeff_vec_;
78+
vector<vector<double>> rect_coeff_vec_;
79+
vector<vector<double>> proj_coeff_vec_;
7880
vector<string> imageNames;
7981

8082
string path_;

params/multi-cam_example.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ skip: 5
2121

2222
#Camera info message details
2323
distortion_model: plumb_bob
24+
image_height: 1536
25+
image_width: 2048
2426
distortion_coeffs:
2527
- [-0.021141875266089592, -0.3733872931278025, 2.385982550579459, 3.2824571732099725]
2628
- [-0.06001035588294054, 0.3466585291091072, -1.0932356940133992, 3.4511959617065253]
@@ -35,3 +37,18 @@ intrinsic_coeffs:
3537
- [1872.6246599679714, 0.0, 594.706935782809, 0.0, 1873.4112078551445, 497.511707550892, 0.0, 0.0, 1.0]
3638
- [1867.922201234431, 0.0, 565.5570110679519, 0.0, 1868.1730959576214, 485.76092237501405, 0.0, 0.0, 1.0]
3739
- [1880.7646202582603, 0.0, 582.3098456998288, 0.0, 1883.4340813437482, 483.8937525066349, 0.0, 0.0, 1.0]
40+
41+
rectification_coeffs:
42+
- [1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000]
43+
- [1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000]
44+
- [1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000]
45+
- [1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000]
46+
- [1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000]
47+
48+
projection_coeffs:
49+
- [913.700317, 0.000000, 953.448302, 0.000000, 0.000000, 1063.296631, 777.871993, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]
50+
- [703.910323, 0.000000, 815.113302, 0.000000, 0.000000, 958.319231, 636.871993, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]
51+
- [913.700317, 0.000000, 953.448302, 0.000000, 0.000000, 911.742312, 811.121993, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]
52+
- [923.700443, 0.000000, 973.847232, 0.000000, 0.000000, 1100.763631, 832.341983, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]
53+
- [800.784635, 0.000000, 983.78252, 0.000000, 0.000000, 903.736234, 798.561973, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000]
54+

src/capture.cpp

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,32 @@ void acquisition::Capture::load_cameras() {
162162

163163
if (PUBLISH_CAM_INFO_){
164164
sensor_msgs::CameraInfo ci_msg;
165-
166-
ci_msg.height = 1024;
167-
ci_msg.width = 1280;
168-
ci_msg.distortion_model = "plumb_bob";
169-
ci_msg.D = distortion_coeff_vec_[j];
165+
int image_width = 0;
166+
int image_height = 0;
167+
std::string distortion_model = "";
168+
nh_pvt_.getParam("image_height", image_height);
169+
nh_pvt_.getParam("image_width", image_width);
170+
nh_pvt_.getParam("distortion_model", distortion_model);
171+
172+
ci_msg.header.frame_id = "cam_"+to_string(j)+"_optical_frame";
173+
ci_msg.width = image_width;
174+
ci_msg.height = image_height;
175+
ci_msg.distortion_model = distortion_model;
170176
ci_msg.binning_x = binning_;
171177
ci_msg.binning_y = binning_;
178+
179+
ci_msg.D = distortion_coeff_vec_[j];
172180
for (int count = 0; count<intrinsic_coeff_vec_[j].size();count++)
173181
ci_msg.K[count] = intrinsic_coeff_vec_[j][count];
174-
ci_msg.header.frame_id = "cam_"+to_string(j)+"_optical_frame";
175-
ci_msg.P = {intrinsic_coeff_vec_[j][0], intrinsic_coeff_vec_[j][1],intrinsic_coeff_vec_[j][2], 0,
176-
intrinsic_coeff_vec_[j][3],intrinsic_coeff_vec_[j][4],intrinsic_coeff_vec_[j][5],0,
177-
intrinsic_coeff_vec_[j][6],intrinsic_coeff_vec_[j][7],intrinsic_coeff_vec_[j][8],0};
182+
183+
if (!rect_coeff_vec_.empty())
184+
ci_msg.R = {rect_coeff_vec_[j][0], rect_coeff_vec_[j][1], rect_coeff_vec_[j][2],
185+
rect_coeff_vec_[j][3], rect_coeff_vec_[j][4], rect_coeff_vec_[j][5],
186+
rect_coeff_vec_[j][6], rect_coeff_vec_[j][7], rect_coeff_vec_[j][8]};
187+
if (!proj_coeff_vec_.empty())
188+
ci_msg.P = {proj_coeff_vec_[j][0], proj_coeff_vec_[j][1], proj_coeff_vec_[j][2], proj_coeff_vec_[j][3],
189+
proj_coeff_vec_[j][4], proj_coeff_vec_[j][5], proj_coeff_vec_[j][6], proj_coeff_vec_[j][7],
190+
proj_coeff_vec_[j][8], proj_coeff_vec_[j][9], proj_coeff_vec_[j][10], proj_coeff_vec_[j][11]};
178191

179192
cam_info_msgs.push_back(ci_msg);
180193
}
@@ -386,6 +399,42 @@ void acquisition::Capture::read_parameters() {
386399
distort_list_provided = true;
387400
}
388401
}
402+
403+
XmlRpc::XmlRpcValue rect_list;
404+
405+
if (nh_pvt_.getParam("rectification_coeffs", rect_list)) {
406+
ROS_INFO(" Camera Rectification Paramters:");
407+
ROS_ASSERT_MSG(rect_list.size() == num_ids,"If rectification_coeffs are provided, they should be the same number as cam_ids and should correspond in order!");
408+
for (int i=0; i<rect_list.size(); i++){
409+
std::vector<double> rect;
410+
String rect_str="";
411+
for (int j=0; j<rect_list[i].size(); j++){
412+
ROS_ASSERT_MSG(rect_list[i][j].getType()== XmlRpc::XmlRpcValue::TypeDouble,"Make sure all numbers are entered as doubles eg. 0.0 or 1.1");
413+
rect.push_back(static_cast<double>(rect_list[i][j]));
414+
rect_str = rect_str +to_string(rect[j])+" ";
415+
}
416+
rect_coeff_vec_.push_back(rect);
417+
ROS_INFO_STREAM(" "<< rect_str );
418+
}
419+
}
420+
421+
XmlRpc::XmlRpcValue proj_list;
422+
423+
if (nh_pvt_.getParam("projection_coeffs", proj_list)) {
424+
ROS_INFO(" Camera Projection Paramters:");
425+
ROS_ASSERT_MSG(proj_list.size() == num_ids,"If projection_coeffs are provided, they should be the same number as cam_ids and should correspond in order!");
426+
for (int i=0; i<proj_list.size(); i++){
427+
std::vector<double> proj;
428+
String proj_str="";
429+
for (int j=0; j<proj_list[i].size(); j++){
430+
ROS_ASSERT_MSG(proj_list[i][j].getType()== XmlRpc::XmlRpcValue::TypeDouble,"Make sure all numbers are entered as doubles eg. 0.0 or 1.1");
431+
proj.push_back(static_cast<double>(proj_list[i][j]));
432+
proj_str = proj_str +to_string(proj[j])+" ";
433+
}
434+
proj_coeff_vec_.push_back(proj);
435+
ROS_INFO_STREAM(" "<< proj_str );
436+
}
437+
}
389438

390439
PUBLISH_CAM_INFO_ = intrinsics_list_provided && distort_list_provided;
391440
if (PUBLISH_CAM_INFO_)

0 commit comments

Comments
 (0)