diff options
author | Patrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb> | 2012-09-17 16:32:04 +0000 |
---|---|---|
committer | Patrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb> | 2012-09-17 16:32:04 +0000 |
commit | cc3bc1c6d14de535f87e6601ed562b505d902fce (patch) | |
tree | 215fff88ae282a197b80b9db926430380c36c946 /FTNoIR_Tracker_PT/point_extractor.cpp | |
parent | f5df7884cf82b87fce50d3ff68c6a4bfa85064e9 (diff) |
added pointtracker
created VC9 solution and project files for available projects
git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@143 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FTNoIR_Tracker_PT/point_extractor.cpp')
-rw-r--r-- | FTNoIR_Tracker_PT/point_extractor.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/FTNoIR_Tracker_PT/point_extractor.cpp b/FTNoIR_Tracker_PT/point_extractor.cpp new file mode 100644 index 00000000..956a2834 --- /dev/null +++ b/FTNoIR_Tracker_PT/point_extractor.cpp @@ -0,0 +1,57 @@ +/* Copyright (c) 2012 Patrick Ruoff
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+#include "point_extractor.h"
+
+#include <QDebug>
+
+using namespace cv;
+using namespace std;
+
+// ----------------------------------------------------------------------------
+const vector<Vec2f>& PointExtractor::extract_points(Mat frame, float dt, bool draw_output)
+{
+ // convert to grayscale
+ Mat frame_bw;
+ cvtColor(frame, frame_bw, CV_RGB2GRAY);
+
+ // convert to binary
+ threshold(frame_bw, frame_bw, threshold_val, 255, THRESH_BINARY);
+ erode(frame_bw, frame_bw, Mat(), Point(-1,-1), min_size);
+
+ // find contours
+ vector< vector<Point> > contours;
+ findContours(frame_bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
+
+ // extract points
+ // TODO: use proximity to old points for classification
+ float r;
+ Vec2f c;
+ Point2f dummy;
+ points.clear();
+ for (vector< vector<Point> >::iterator iter = contours.begin();
+ iter!= contours.end();
+ ++iter)
+ {
+ minEnclosingCircle(*iter, dummy, r);
+ if (r > max_size - min_size) break;
+ Moments m = moments(*iter);
+ if (m.m00 == 0) break;
+ // convert to centered camera coordinate system with y axis upwards
+ c[0] = (m.m10/m.m00 - frame.cols/2)/frame.cols;
+ c[1] = -(m.m01/m.m00 - frame.rows/2)/frame.cols;
+ points.push_back(c);
+ }
+
+ // draw output image
+ if (draw_output)
+ {
+ frame.setTo(Scalar(255,0,0), frame_bw);
+ }
+
+ return points;
+}
|