diff --git a/src/frameserver/PointGreyCam.cpp b/src/frameserver/PointGreyCam.cpp index dfba275..761acd4 100644 --- a/src/frameserver/PointGreyCam.cpp +++ b/src/frameserver/PointGreyCam.cpp @@ -195,14 +195,14 @@ void PointGreyCam::configure(const po::variables_map &vm) // Set white balance // TODO: Needs three states: On, Auto, manual - std::vector wb; - bool auto_wb; - if (oat::config::getValue(vm, config_table, "auto-white-balance", auto_wb)) - setupWhiteBalance(0, 0, true, true); - else if (oat::config::getArray(vm, config_table, "white-balance", wb)) - setupWhiteBalance(wb[0], wb[1], true, false); - else - setupWhiteBalance(0, 0, false, false); + //std::vector wb; + //bool auto_wb; + //if (oat::config::getValue(vm, config_table, "auto-white-balance", auto_wb)) + // setupWhiteBalance(0, 0, true, true); + //else if (oat::config::getArray(vm, config_table, "white-balance", wb)) + // setupWhiteBalance(wb[0], wb[1], true, false); + //else + // setupWhiteBalance(0, 0, false, false); // Pixel binning std::vector bin_size; @@ -357,12 +357,6 @@ void PointGreyCam::setupWhiteBalance(int bal_red, int bal_blue, bool is_on, b { std::cout << "Setting camera white balance..."; - if (!is_on) { - setPGOff(camera_, pg::WHITE_BALANCE); - std::cout << "set to off.\n"; - return; - } - // Mono pixels do not support white balance if (pix_col_ == PIX_GREY) { std::cerr << oat::Warn( @@ -370,6 +364,12 @@ void PointGreyCam::setupWhiteBalance(int bal_red, int bal_blue, bool is_on, b return; } + if (!is_on) { + setPGOff(camera_, pg::WHITE_BALANCE); + std::cout << "set to off.\n"; + return; + } + if (is_auto) { setPGAuto(camera_, pg::WHITE_BALANCE); std::cout << "set to auto.\n"; diff --git a/src/positiondetector/SimpleThreshold.cpp b/src/positiondetector/SimpleThreshold.cpp index a3f9b55..e8c3d28 100644 --- a/src/positiondetector/SimpleThreshold.cpp +++ b/src/positiondetector/SimpleThreshold.cpp @@ -41,11 +41,17 @@ SimpleThreshold::SimpleThreshold(const std::string &frame_source_address, // dilate_on must be set to false set_erode_size(0); set_dilate_size(0); + set_mincomp_size(0); // Set required frame type required_color_ = PIX_GREY; } + +//, +// ("mincomp,m", po::value(), +// "Minimum compensation, optionally adjust thresholds by the darkest pixels in the region."), + void SimpleThreshold::appendOptions(po::options_description &opts) { // Accepts a config file @@ -64,6 +70,10 @@ void SimpleThreshold::appendOptions(po::options_description &opts) ("area,a", po::value(), "Array of floats, [min,max], specifying the minimum and maximum " "object contour area in pixels^2.") + + ("mincomp,m", po::value(), + "Minimum compensation, optionally adjust thresholds by the darkest pixels in the region.") + ("tune,t", "If true, provide a GUI with sliders for tuning detection parameters.") ; @@ -102,6 +112,12 @@ void SimpleThreshold::configure(const po::variables_map &vm) if (oat::config::getNumericValue(vm, config_table, "dilate", dilate, 0)) set_dilate_size(dilate); + // Mincomp value + int mincomp; + if (oat::config::getNumericValue(vm, config_table, "mincomp", mincomp, 0)) + set_mincomp_size(mincomp); + + // Min/max object area std::vector area; if (oat::config::getArray(vm, config_table, "area", area)) { @@ -178,9 +194,21 @@ void SimpleThreshold::tune(cv::Mat &frame, const oat::Position2D &position) void SimpleThreshold::applyThreshold(cv::Mat &frame) { + + cv::inRange(frame, + 1, + 255, + nonmasked_frame_); + + double mincomp_brightness =0; + if (mincomp_on_) + cv::minMaxIdx(frame, &mincomp_brightness,NULL,NULL,NULL,nonmasked_frame_); + + //std::cout << " br " << mincomp_brightness <<"\n"; + cv::inRange(frame, - t_min_, - t_max_, + t_min_+static_cast(mincomp_brightness), + t_max_+static_cast(mincomp_brightness), threshold_frame_); // Filter the resulting threshold image @@ -259,6 +287,18 @@ void SimpleThreshold::set_dilate_size(int value) } } +void SimpleThreshold::set_mincomp_size(int value) +{ + std::cout << "mincomp set to " << value<<"\n"; + if (value != 0) { + mincomp_on_ = true; + + mincomp_val_ = value; + } else { + mincomp_on_ = false; + } +} + // Non-member GUI callback functions void simpleThresholdMinAreaSliderChangedCallback(int value, void *object) { diff --git a/src/positiondetector/SimpleThreshold.h b/src/positiondetector/SimpleThreshold.h index bc15d6d..720582f 100644 --- a/src/positiondetector/SimpleThreshold.h +++ b/src/positiondetector/SimpleThreshold.h @@ -54,18 +54,20 @@ class SimpleThreshold : public PositionDetector { void set_max_object_area(double value) { max_object_area_ = value; } void set_erode_size(int erode_px); void set_dilate_size(int dilate_px); + void set_mincomp_size(int mincomp_val); private: // Intermediate variables cv::Mat threshold_frame_; + cv::Mat nonmasked_frame_; // Object detection double object_area_ {0.0}; // Sizes of the erode and dilate blocks - int erode_px_ {0}, dilate_px_ {0}; - bool erode_on_ {false}, dilate_on_ {false}; + int erode_px_ {0}, dilate_px_ {0}, mincomp_val_ {0}; + bool erode_on_ {false}, dilate_on_ {false}, mincomp_on_ {false}; // Internal matricies cv::Mat erode_element_, dilate_element_;