diff options
-rw-r--r-- | ftnoir_tracker_pt/FTNoIR_PT_Controls.ui | 6 | ||||
-rw-r--r-- | ftnoir_tracker_pt/point_extractor.cpp | 33 |
2 files changed, 30 insertions, 9 deletions
diff --git a/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui b/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui index 32dcdef1..acdbda78 100644 --- a/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui +++ b/ftnoir_tracker_pt/FTNoIR_PT_Controls.ui @@ -9,8 +9,8 @@ <rect> <x>0</x> <y>0</y> - <width>419</width> - <height>575</height> + <width>424</width> + <height>579</height> </rect> </property> <property name="sizePolicy"> @@ -390,7 +390,7 @@ <item row="0" column="1"> <widget class="QCheckBox" name="auto_threshold"> <property name="text"> - <string>Enable, ignore slider</string> + <string>Enable, slider sets point size</string> </property> </widget> </item> diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index 0501a5c6..0ac2fc32 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -65,12 +65,33 @@ std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) } 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); + cv::Mat hist; + cv::calcHist(std::vector<cv::Mat> { frame_gray }, + std::vector<int> { 0 }, + cv::Mat(), + hist, + std::vector<int> { 256 }, + std::vector<float> { 0, 256 }, + false); + const int sz = hist.rows*hist.cols; + int val = 0; + int cnt = 0; + constexpr int min_pixels = 2000; + const int pixels_to_include = std::max(0, static_cast<int>(min_pixels * (1. - s.threshold / 100.))); + for (int i = sz-1; i >= 0; i--) + { + cnt += hist.at<float>(i); + if (cnt >= pixels_to_include) + { + val = i; + break; + } + } + val *= .95; + //qDebug() << "cnt" << cnt << "val" << val; + + cv::Mat frame_bin_; + cv::threshold(frame_gray, frame_bin_, val, 255, CV_THRESH_BINARY); frame_bin.setTo(170, frame_bin_); cv::findContours(frame_bin_, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE); } |