summaryrefslogtreecommitdiffhomepage
path: root/FTNoIR_Tracker_PT/point_extractor.cpp
diff options
context:
space:
mode:
authorPatrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb>2012-09-20 15:08:10 +0000
committerPatrick Ruoff <c14-radioactive@19e81ba0-9b1a-49c3-bd6c-561e1906d5fb>2012-09-20 15:08:10 +0000
commit5da3b245b35cdd2bb4b1490aae81f8d0ff0bde82 (patch)
tree625b80ab77e3bfc408ea245cffa912affda2a447 /FTNoIR_Tracker_PT/point_extractor.cpp
parent13abb65d05e8eebe2438f952cde0867d9b0fa47e (diff)
corrected vc9 project file debug settings
Tracker_PT: implemented centering Tracker_PT: implemented new point extraction Tracker_PT: various bugfixes git-svn-id: svn+ssh://svn.code.sf.net/p/facetracknoir/code@148 19e81ba0-9b1a-49c3-bd6c-561e1906d5fb
Diffstat (limited to 'FTNoIR_Tracker_PT/point_extractor.cpp')
-rw-r--r--FTNoIR_Tracker_PT/point_extractor.cpp76
1 files changed, 73 insertions, 3 deletions
diff --git a/FTNoIR_Tracker_PT/point_extractor.cpp b/FTNoIR_Tracker_PT/point_extractor.cpp
index 956a2834..a415f24e 100644
--- a/FTNoIR_Tracker_PT/point_extractor.cpp
+++ b/FTNoIR_Tracker_PT/point_extractor.cpp
@@ -15,14 +15,32 @@ using namespace std;
// ----------------------------------------------------------------------------
const vector<Vec2f>& PointExtractor::extract_points(Mat frame, float dt, bool draw_output)
{
+ /*
+ // sensitivity test for tracker
+ static int n = 0;
+ if (points.size() == 3)
+ {
+ for (int i=0; i<3; ++i)
+ {
+ points[i][0] -= 1e-4*sin(n/100.0);
+ points[i][1] -= 1e-4*cos(n/100.0);
+ }
+ ++n;
+ return points;
+ }
+ */
+
// 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);
+ //erode(frame_bw, frame_bw, Mat(), Point(-1,-1), min_size); //destroys information -> bad for subpixel accurarcy
+ // find connected components...
+ // Method 1: contours
+ //*
// find contours
vector< vector<Point> > contours;
findContours(frame_bw.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
@@ -38,14 +56,66 @@ const vector<Vec2f>& PointExtractor::extract_points(Mat frame, float dt, bool dr
++iter)
{
minEnclosingCircle(*iter, dummy, r);
- if (r > max_size - min_size) break;
+ if (r > max_size) continue;
Moments m = moments(*iter);
- if (m.m00 == 0) break;
+ if (m.m00 < 3.14*min_size*min_size) continue;
// 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);
}
+ //*/
+
+ // Method 2: floodfill
+ /*
+ // extract blobs
+ struct BlobInfo
+ {
+ BlobInfo() : m00(0), m10(0), m01(0) {}
+ long m00;
+ long m10;
+ long m01;
+ };
+ vector<BlobInfo> blobs;
+ int blob_count = 1;
+
+ for (int y=0; y < frame_bw.rows; y++) {
+ for (int x=0; x < frame_bw.cols; x++) {
+ if (frame_bw.at<unsigned char>(y,x) != 255) continue;
+ Rect rect;
+ floodFill(frame_bw, Point(x,y), Scalar(blob_count), &rect, Scalar(0), Scalar(0), 4);
+ BlobInfo blob;
+ for (int i=rect.y; i < (rect.y+rect.height); i++) {
+ for (int j=rect.x; j < (rect.x+rect.width); j++) {
+ if (frame_bw.at<unsigned char>(i,j) != blob_count) continue;
+ blob.m00++;
+ blob.m01+=i;
+ blob.m10+=j;
+ }
+ }
+ blobs.push_back(blob);
+ blob_count++;
+ if (blob_count >= 255) break;
+ }
+ }
+
+ // extract points
+ Vec2f c;
+ points.clear();
+ float m00_min = 3.14*min_size*min_size;
+ float m00_max = 3.14*max_size*max_size;
+ for (vector<BlobInfo>::iterator iter = blobs.begin();
+ iter!= blobs.end();
+ ++iter)
+ {
+ const BlobInfo& m = *iter;
+ if (m.m00 < m00_min || m.m00 > m00_max) continue;
+ // convert to centered camera coordinate system with y axis upwards
+ c[0] = (m.m10/float(m.m00) - frame.cols/2)/frame.cols;
+ c[1] = -(m.m01/float(m.m00) - frame.rows/2)/frame.cols;
+ points.push_back(c);
+ }
+ */
// draw output image
if (draw_output)