-
Notifications
You must be signed in to change notification settings - Fork 20
Adaptive simple threshold #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<int>(), | ||
| // "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<std::string>(), | ||
| "Array of floats, [min,max], specifying the minimum and maximum " | ||
| "object contour area in pixels^2.") | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of white space around this option addition. |
||
| ("mincomp,m", po::value<int>(), | ||
| "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<int>(vm, config_table, "dilate", dilate, 0)) | ||
| set_dilate_size(dilate); | ||
|
|
||
| // Mincomp value | ||
| int mincomp; | ||
| if (oat::config::getNumericValue<int>(vm, config_table, "mincomp", mincomp, 0)) | ||
| set_mincomp_size(mincomp); | ||
|
|
||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of this line break. |
||
| // Min/max object area | ||
| std::vector<double> area; | ||
| if (oat::config::getArray<double, 2>(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_) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of mincomp_on variable and just do mincomp_ != 0 here. Where is the value of mincomp_ being used? It looks like you are just always adding whatever the minimum of the non zero part of the frame to the threshold range. In fact the if block should start before the first inRange call to get rid of the processing overhead if its not being used. It should end below the minMaxIdx function. |
||
| cv::minMaxIdx(frame, &mincomp_brightness,NULL,NULL,NULL,nonmasked_frame_); | ||
|
|
||
| //std::cout << " br " << mincomp_brightness <<"\n"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of temporary std::out stuff. |
||
|
|
||
| cv::inRange(frame, | ||
| t_min_, | ||
| t_max_, | ||
| t_min_+static_cast<int>(mincomp_brightness), | ||
| t_max_+static_cast<int>(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"; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of this debug output. |
||
| if (value != 0) { | ||
| mincomp_on_ = true; | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of line |
||
| mincomp_val_ = value; | ||
| } else { | ||
| mincomp_on_ = false; | ||
| } | ||
| } | ||
|
|
||
| // Non-member GUI callback functions | ||
| void simpleThresholdMinAreaSliderChangedCallback(int value, void *object) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't need this member function. Those were only needed for the erode and dilate options because I had to set up a little smoothing kernel each time the value is changed. |
||
|
|
||
| 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}; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int mincomp_ {0} on its own line with a an explanatory comment. It is not related to erode an dilate. |
||
| bool erode_on_ {false}, dilate_on_ {false}, mincomp_on_ {false}; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get rid of mincomp_on_ member. |
||
|
|
||
| // Internal matricies | ||
| cv::Mat erode_element_, dilate_element_; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get rid of these comments. space between function defs should be one line.