Skip to content

Commit 8ee3779

Browse files
Vikrant Shahmithundiddi
authored andcommitted
Feature/roi2 (#42)
* Adding settings for ROI specified via a dictionary * Updating Readme
1 parent f16e6c0 commit 8ee3779

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ All the parameters can be set via the launch file or via the yaml config_file.
9595
Flag to flip image horizontally on camera itself, this is not a rotate only a mirror image. This setting does enumeration: "reverseX". It should be specified for all cameras or can be left unspecified for all cameras for default behaviour.
9696
* ~flip_vertical (bool, default: false)
9797
Flag to flip image vertically on camera itself, this is not a rotate only a mirror image. This setting does enumeration: "reverseY". It should be specified for all cameras or can be left unspecified for all cameras for default behaviour.
98-
99-
If both horizontal and vertical flags are true, then it is equivalent to rotating 180deg.
98+
If both horizontal and vertical flags are true, then it is equivalent to rotating 180deg.
99+
* ~region_of_interest (dict, default = { width: 0, height: 0, x_offset: 0, y_offset: 0 }
100+
Specify the region of interest in the camera image as dict with width, height, x_offset and y_offset. Width and height specify size of the final image (should be smaller than sensor size). X and Y offsets specify the image origin. The offset plus image size should be smaller than the sensor size.
100101

101102
### node/nodelet Specific Parameters
102103
* ~tf_prefix (string, default: "")

include/spinnaker_sdk_camera_driver/capture.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ namespace acquisition {
132132
bool PUBLISH_CAM_INFO_;
133133
bool VERIFY_BINNING_;
134134
uint64_t SPINNAKER_GET_NEXT_IMAGE_TIMEOUT_;
135+
136+
bool region_of_interest_set_;
137+
int region_of_interest_width_;
138+
int region_of_interest_height_;
139+
int region_of_interest_x_offset_;
140+
int region_of_interest_y_offset_;
135141

136142
// grid view related variables
137143
bool GRID_CREATED_;

params/test_params.yaml

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

2020
#Camera info message details
2121
distortion_model: plumb_bob
22-
image_height: 1536
23-
image_width: 2048
22+
image_height: 1080
23+
image_width: 1440
2424
distortion_coeffs:
2525
- [-0.021141875266089592, -0.3733872931278025, 2.385982550579459, 3.2824571732099725]
2626

@@ -40,3 +40,9 @@ flip_horizontal:
4040

4141
flip_vertical:
4242
- false
43+
44+
region_of_interest:
45+
width: 0
46+
height: 0
47+
x_offset: 0
48+
y_offset: 0

src/capture.cpp

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ acquisition::Capture::Capture(): it_(nh_), nh_pvt_ ("~") {
7878
nframes_ = -1;
7979
FIXED_NUM_FRAMES_ = false;
8080
MAX_RATE_SAVE_ = false;
81+
region_of_interest_set_ = false;
8182
skip_num_ = 20;
8283
init_delay_ = 1;
8384
master_fps_ = 20.0;
@@ -159,7 +160,8 @@ acquisition::Capture::Capture(ros::NodeHandle nodehandl, ros::NodeHandle private
159160
SAVE_BIN_ = false;
160161
nframes_ = -1;
161162
FIXED_NUM_FRAMES_ = false;
162-
MAX_RATE_SAVE_ = false;
163+
MAX_RATE_SAVE_ = false;
164+
region_of_interest_set_ = false;
163165
skip_num_ = 20;
164166
init_delay_ = 1;
165167
master_fps_ = 20.0;
@@ -187,7 +189,7 @@ acquisition::Capture::Capture(ros::NodeHandle nodehandl, ros::NodeHandle private
187189

188190
GRID_CREATED_ = false;
189191
VERIFY_BINNING_ = false;
190-
192+
191193

192194
//read_settings(config_file);
193195
read_parameters();
@@ -276,6 +278,14 @@ void acquisition::Capture::load_cameras() {
276278
// binning
277279
ci_msg->binning_x = binning_;
278280
ci_msg->binning_y = binning_;
281+
282+
if (region_of_interest_set_ && (region_of_interest_width_!=0 || region_of_interest_height_!=0)){
283+
ci_msg->roi.do_rectify = true;
284+
ci_msg->roi.width = region_of_interest_width_;
285+
ci_msg->roi.height = region_of_interest_height_;
286+
ci_msg->roi.x_offset = region_of_interest_x_offset_;
287+
ci_msg->roi.y_offset = region_of_interest_y_offset_;
288+
}
279289

280290
if (PUBLISH_CAM_INFO_){
281291
ci_msg->D = distortion_coeff_vec_[j];
@@ -545,8 +555,26 @@ void acquisition::Capture::read_parameters() {
545555
}
546556
else ROS_WARN(" 'tf_prefix' Parameter not set, using default behavior tf_prefix=" " ");
547557

548-
549-
558+
if (nh_pvt_.hasParam("region_of_interest")){
559+
region_of_interest_set_ = true;
560+
if (!nh_pvt_.getParam("region_of_interest/width", region_of_interest_width_)){
561+
region_of_interest_set_ = false;
562+
}
563+
if (!nh_pvt_.getParam("region_of_interest/height", region_of_interest_height_)){
564+
region_of_interest_set_ = false;
565+
}
566+
if (!nh_pvt_.getParam("region_of_interest/x_offset", region_of_interest_x_offset_)){
567+
region_of_interest_set_ = false;
568+
}
569+
if (!nh_pvt_.getParam("region_of_interest/y_offset", region_of_interest_y_offset_)){
570+
region_of_interest_set_ = false;
571+
}
572+
573+
if (region_of_interest_set_){
574+
ROS_INFO(" Region of Interest set to width: %d\theight: %d\toffset_x: %d offset_y: %d",
575+
region_of_interest_width_, region_of_interest_height_, region_of_interest_x_offset_, region_of_interest_y_offset_);
576+
} else ROS_ERROR(" 'region_of_interest' Parameter found but not configured correctly, NOT BEING USED");
577+
} else ROS_INFO_STREAM(" 'region of interest' not set using full resolution");
550578

551579
bool intrinsics_list_provided = false;
552580
XmlRpc::XmlRpcValue intrinsics_list;
@@ -677,11 +705,20 @@ void acquisition::Capture::init_cameras(bool soft = false) {
677705

678706
cams[i].set_color(color_);
679707
cams[i].setIntValue("BinningHorizontal", binning_);
680-
cams[i].setIntValue("BinningVertical", binning_);
708+
cams[i].setIntValue("BinningVertical", binning_);
681709
cams[i].setEnumValue("ExposureMode", "Timed");
682710
cams[i].setBoolValue("ReverseX", flip_horizontal_vec_[i]);
683711
cams[i].setBoolValue("ReverseY", flip_vertical_vec_[i]);
684712

713+
if (region_of_interest_set_){
714+
if (region_of_interest_width_ != 0)
715+
cams[i].setIntValue("Width", region_of_interest_width_);
716+
if (region_of_interest_height_ != 0)
717+
cams[i].setIntValue("Height", region_of_interest_height_);
718+
cams[i].setIntValue("OffsetX", region_of_interest_x_offset_);
719+
cams[i].setIntValue("OffsetY", region_of_interest_y_offset_);
720+
}
721+
685722
if (exposure_time_ > 0) {
686723
cams[i].setEnumValue("ExposureAuto", "Off");
687724
cams[i].setFloatValue("ExposureTime", exposure_time_);
@@ -967,7 +1004,9 @@ void acquisition::Capture::run_soft_trig() {
9671004
// Gets called only once, when first image is being triggered
9681005
for (unsigned int i = 0; i < numCameras_; i++) {
9691006
//verify if binning is set successfully
970-
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_);
1007+
if (!region_of_interest_set_){
1008+
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_);
1009+
}
9711010
// warn if full sensor resolution is not same as calibration resolution
9721011
cams[i].calibrationParamsTest(image_width_,image_height_);
9731012
}

0 commit comments

Comments
 (0)