From 48ab05f6244deb5bbe95b73f8a4bd67fcf620bf3 Mon Sep 17 00:00:00 2001 From: Peter Braden Date: Wed, 19 Sep 2012 12:26:46 -0700 Subject: [PATCH] basics of goodFeaturesToTrack --- smoke.sh | 4 ++-- smoketest.js | 14 +++++++++++++- src/Matrix.cc | 30 ++++++++++++++++++++++++++++++ src/Matrix.h | 2 ++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/smoke.sh b/smoke.sh index 419d67a..e136e2e 100755 --- a/smoke.sh +++ b/smoke.sh @@ -1,6 +1,6 @@ #!/bin/bash node-gyp rebuild && echo '-- Compiled OK -- -' && node smoketest.js && echo '-- Smoke Done, running tests -- +' && node smoketest.js #&& echo '-- Smoke Done, running tests -- -' && npm test +#' && npm test diff --git a/smoketest.js b/smoketest.js index c62f657..50ea037 100755 --- a/smoketest.js +++ b/smoketest.js @@ -1,5 +1,5 @@ var cv = require('./lib/opencv') - +/* new cv.VideoCapture(0).read(function(mat){ mat.resize(200,100) @@ -15,3 +15,15 @@ new cv.VideoCapture(0).read(function(mat){ }) }) +*/ + + +cv.readImage("./examples/mona.png", function(err, im){ + var features = im.goodFeaturesToTrack(); + for (var i=0;i target) { NODE_SET_PROTOTYPE_METHOD(constructor, "findContours", FindContours); NODE_SET_PROTOTYPE_METHOD(constructor, "drawContour", DrawContour); NODE_SET_PROTOTYPE_METHOD(constructor, "drawAllContours", DrawAllContours); + + NODE_SET_PROTOTYPE_METHOD(constructor, "goodFeaturesToTrack", GoodFeaturesToTrack); NODE_SET_METHOD(constructor, "Eye", Eye); @@ -555,6 +557,34 @@ Matrix::DrawAllContours(const v8::Arguments& args) { return Undefined(); } +Handle +Matrix::GoodFeaturesToTrack(const v8::Arguments& args) { + HandleScope scope; + + Matrix *self = ObjectWrap::Unwrap(args.This()); + std::vector corners; + + cv::Mat gray; + + cvtColor(self->mat, gray, CV_BGR2GRAY); + equalizeHist(gray, gray); + + cv::goodFeaturesToTrack(gray, corners, 500, 0.01, 10); + + v8::Local arr = v8::Array::New(corners.size()); + + + for (unsigned int i=0; i pt = v8::Array::New(2); + pt->Set(0, Number::New((double) corners[i].x)); + pt->Set(1, Number::New((double) corners[i].y)); + arr->Set(i, pt); + } + + return scope.Close(arr); + +} + cv::Scalar setColor(Local objColor) { diff --git a/src/Matrix.h b/src/Matrix.h index ca5c14c..be16fbf 100755 --- a/src/Matrix.h +++ b/src/Matrix.h @@ -84,5 +84,7 @@ class Matrix: public node::ObjectWrap { JSFUNC(DrawContour) JSFUNC(DrawAllContours) + JSFUNC(GoodFeaturesToTrack) + };