Skip to content

Commit

Permalink
rework how integer locations are detected in image_to_sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
dicengine committed Jul 22, 2021
1 parent 5a5c85a commit 1a0115a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/core/DICe_Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,7 @@ Camera::image_to_sensor(
const std::vector<scalar_t> & image_x,
const std::vector<scalar_t> & image_y,
std::vector<scalar_t> & sen_x,
std::vector<scalar_t> & sen_y,
const bool integer_locs) {
std::vector<scalar_t> & sen_y) {
camera_info_.check_valid();
prep_lens_distortion();

Expand All @@ -586,6 +585,17 @@ Camera::image_to_sensor(
TEUCHOS_TEST_FOR_EXCEPTION(sen_x.size()!=vec_size,std::runtime_error,"");
TEUCHOS_TEST_FOR_EXCEPTION(sen_y.size()!=vec_size,std::runtime_error,"");

// check for integer locations
scalar_t intpart;
bool integer_locs = true;
for (size_t i = 0; i < vec_size; i++) {
if(std::modf(image_x[i], &intpart) != 0.0 || std::modf(image_y[i], &intpart) != 0.0){ // see if there is a fractional part to the input coordinates
integer_locs = false;
break;
}
}
DEBUG_MSG("Camera::image_to_sensor(): integer locations is " << integer_locs);

//transformation from distorted image locations to undistorted sensor locations
int_t index;
int_t index00;
Expand Down
4 changes: 1 addition & 3 deletions src/core/DICe_Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,11 @@ Camera {
/// \param image_y y location after applied lens distortion
/// \param sen_x projected x sensor location
/// \param sen_y projected y sensor location
/// \param integer_locs if all image points are integers setting this flag avoids interpolation overhead
void image_to_sensor(
const std::vector<scalar_t> & image_x,
const std::vector<scalar_t> & image_y,
std::vector<scalar_t> & sen_x,
std::vector<scalar_t> & sen_y,
const bool integer_locs = true);
std::vector<scalar_t> & sen_y);

/// helper function to convert image coordinates to world coordinates
/// \param image_x x location after applied lens distortion
Expand Down
2 changes: 1 addition & 1 deletion tests/component/DICe_TestCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ int main(int argc, char *argv[]) {
img_y[i] = rand() % (image_height * 100);
img_y[i] = img_y[i] / 100.0;
}
test_cam.image_to_sensor(img_x, img_y, sen_x, sen_y, false);
test_cam.image_to_sensor(img_x, img_y, sen_x, sen_y);
test_cam.sensor_to_image(sen_x, sen_y, ret_x, ret_y);
for (int_t i = 0; i < num_points; i++) {
if (max_deviation < abs(ret_x[i] - img_x[i])) max_deviation = abs(ret_x[i] - img_x[i]);
Expand Down

0 comments on commit 1a0115a

Please sign in to comment.