Scale distortion factors by the image diagonal
Before, we divided avg_distance by width * height,
which would have resulted in a distortion factor of units 1/px.
Scale by the norm of width and height instead so we get a unitless
scalar. Also change the max expected distortion to reflect this.
Signed-off-by: milind-u <milind.upadhyay@gmail.com>
Change-Id: Icd29a4ee251519977fca8d8f6ff0c1ee7ae24ca1
diff --git a/y2023/vision/aprilrobotics.cc b/y2023/vision/aprilrobotics.cc
index bd1c5fd..45b0cf9 100644
--- a/y2023/vision/aprilrobotics.cc
+++ b/y2023/vision/aprilrobotics.cc
@@ -11,7 +11,7 @@
DEFINE_int32(pixel_border, 10,
"Size of image border within which to reject detected corners");
DEFINE_double(
- max_expected_distortion, 0.0005,
+ max_expected_distortion, 0.314,
"Maximum expected value for unscaled distortion factors. Will scale "
"distortion factors so that this value (and a higher distortion) maps to "
"1.0.");
@@ -158,11 +158,11 @@
}
avg_distance /= corners.size();
- // Normalize avg_distance by dividing by the image size, and then the maximum
- // expected distortion
+ // Normalize avg_distance by dividing by the image diagonal,
+ // and then the maximum expected distortion
double distortion_factor =
avg_distance /
- static_cast<double>(image_size_.width * image_size_.height);
+ cv::norm(cv::Point2d(image_size_.width, image_size_.height));
return std::min(distortion_factor / FLAGS_max_expected_distortion, 1.0);
}