Bring back use_outdoors flag
In the cafeteria the lighting is very different, and color filters and
exposure need to be changed to lower noise.
Signed-off-by: Milind Upadhyay <milind.upadhyay@gmail.com>
Change-Id: I2aa3aefd5832d336737b7b0df7b8fd940a69b80f
diff --git a/y2022/vision/blob_detector.cc b/y2022/vision/blob_detector.cc
index efe7961..9800ace 100644
--- a/y2022/vision/blob_detector.cc
+++ b/y2022/vision/blob_detector.cc
@@ -11,15 +11,30 @@
#include "opencv2/imgproc.hpp"
#include "y2022/vision/geometry.h"
+DEFINE_bool(
+ use_outdoors, false,
+ "If set, use the color filters and exposure for an outdoor setting.");
DEFINE_int32(red_delta, 50, "Required difference between green pixels vs. red");
DEFINE_int32(blue_delta, -20,
"Required difference between green pixels vs. blue");
+DEFINE_int32(outdoors_red_delta, 70,
+ "Required difference between green pixels vs. red when using "
+ "--use_outdoors");
+DEFINE_int32(outdoors_blue_delta, -10,
+ "Required difference between green pixels vs. blue when using "
+ "--use_outdoors");
namespace y2022 {
namespace vision {
cv::Mat BlobDetector::ThresholdImage(cv::Mat bgr_image) {
cv::Mat binarized_image(cv::Size(bgr_image.cols, bgr_image.rows), CV_8UC1);
+
+ const int red_delta =
+ (FLAGS_use_outdoors ? FLAGS_outdoors_red_delta : FLAGS_red_delta);
+ const int blue_delta =
+ (FLAGS_use_outdoors ? FLAGS_outdoors_blue_delta : FLAGS_blue_delta);
+
for (int row = 0; row < bgr_image.rows; row++) {
for (int col = 0; col < bgr_image.cols; col++) {
cv::Vec3b pixel = bgr_image.at<cv::Vec3b>(row, col);
@@ -28,8 +43,7 @@
int red = pixel.val[2];
// Simple filter that looks for green pixels sufficiently brigher than
// red and blue
- if ((green > blue + FLAGS_blue_delta) &&
- (green > red + FLAGS_red_delta)) {
+ if ((green > blue + blue_delta) && (green > red + red_delta)) {
binarized_image.at<uint8_t>(row, col) = 255;
} else {
binarized_image.at<uint8_t>(row, col) = 0;
diff --git a/y2022/vision/camera_reader_main.cc b/y2022/vision/camera_reader_main.cc
index dac2100..22794d3 100644
--- a/y2022/vision/camera_reader_main.cc
+++ b/y2022/vision/camera_reader_main.cc
@@ -5,10 +5,14 @@
// config used to allow running camera_reader independently. E.g.,
// bazel run //y2022/vision:camera_reader -- --config y2022/aos_config.json
// --override_hostname pi-7971-1 --ignore_timestamps true
+DECLARE_bool(use_outdoors);
DEFINE_string(config, "aos_config.json", "Path to the config file to use.");
DEFINE_double(duty_cycle, 0.6, "Duty cycle of the LEDs");
DEFINE_uint32(exposure, 5,
"Exposure time, in 100us increments; 0 implies auto exposure");
+DEFINE_uint32(outdoors_exposure, 2,
+ "Exposure time when using --use_outdoors, in 100us increments; 0 "
+ "implies auto exposure");
namespace y2022 {
namespace vision {
@@ -35,8 +39,10 @@
}
V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
- if (FLAGS_exposure > 0) {
- v4l2_reader.SetExposure(FLAGS_exposure);
+ const uint32_t exposure =
+ (FLAGS_use_outdoors ? FLAGS_outdoors_exposure : FLAGS_exposure);
+ if (exposure > 0) {
+ v4l2_reader.SetExposure(exposure);
}
CameraReader camera_reader(&event_loop, &calibration_data.message(),