diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-02 13:45:38 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2015-10-02 13:45:38 +0200 |
commit | 4a2f89042595a5caefc1ee286b6ddca8e7714adc (patch) | |
tree | 8e9ae4c1dc79610f386fa2683a4861efe6394939 /ftnoir_tracker_pt/point_extractor.cpp | |
parent | fa12408b959a856c53d9aeadede060530e1ccbd3 (diff) |
pt: experimental auto threshold support
Sponsored-by: TrackHat
Diffstat (limited to 'ftnoir_tracker_pt/point_extractor.cpp')
-rw-r--r-- | ftnoir_tracker_pt/point_extractor.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index fcdbbaed..0501a5c6 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -31,8 +31,6 @@ std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) const int region_size_min = s.min_point_size; const int region_size_max = s.max_point_size; - const int thres = s.threshold; - struct simple_blob { double radius; @@ -56,12 +54,26 @@ std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) std::vector<simple_blob> blobs; std::vector<std::vector<cv::Point>> contours; + + const int thres = s.threshold; + if (!s.auto_threshold) { cv::Mat frame_bin_; cv::threshold(frame_gray, frame_bin_, thres, 255, cv::THRESH_BINARY); frame_bin.setTo(170, frame_bin_); cv::findContours(frame_bin_, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); } + else + { + cv::Mat frame_bin_, tmp; + int scale = frame_gray.cols > 400 ? 2 : 1; + constexpr int size = 3; + static cv::Mat kernel = cv::getGaussianKernel(size * scale + 1, CV_32F); + cv::sepFilter2D(frame_gray, tmp, -1, kernel, kernel); + cv::threshold(tmp, frame_bin_, 0, 255, CV_THRESH_BINARY|CV_THRESH_OTSU); + frame_bin.setTo(170, frame_bin_); + cv::findContours(frame_bin_, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); + } int cnt = 0; |