summaryrefslogtreecommitdiffhomepage
path: root/ftnoir_tracker_pt
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-10-02 14:03:33 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-10-02 14:03:33 +0200
commit93f518264a5b46d1764d6009ce59f43934fb451c (patch)
tree167d77d4c23206d7e65440b5268c1e1317196a05 /ftnoir_tracker_pt
parentfc3be69e2a53e582aee04f184636a93e27534739 (diff)
parent4a2f89042595a5caefc1ee286b6ddca8e7714adc (diff)
Merge branch 'unstable' into trackhat-ui
* unstable: pt: experimental auto threshold support
Diffstat (limited to 'ftnoir_tracker_pt')
-rw-r--r--ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h4
-rw-r--r--ftnoir_tracker_pt/point_extractor.cpp16
2 files changed, 17 insertions, 3 deletions
diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h
index 00346267..91086dfd 100644
--- a/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h
+++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_settings.h
@@ -23,6 +23,7 @@ struct settings_pt : opts
value<bool> dynamic_pose;
value<int> init_phase_timeout;
+ value<bool> auto_threshold;
settings_pt() :
opts("tracker-pt"),
@@ -36,7 +37,8 @@ struct settings_pt : opts
camera_mode(b, "camera-mode", 0),
model_used(b, "model-used", 0),
dynamic_pose(b, "dynamic-pose-resolution", true),
- init_phase_timeout(b, "init-phase-timeout", 500)
+ init_phase_timeout(b, "init-phase-timeout", 500),
+ auto_threshold(b, "automatic-threshold", false)
{}
};
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;