Permalink
Browse files

WIP on CamShift with TrackedObject re #22

  • Loading branch information...
1 parent e4c0ddd commit 3a1477c5276e6f0a054c95022b9b14196b8aa81c @peterbraden committed Nov 10, 2012
Showing with 104 additions and 0 deletions.
  1. +1 −0 binding.gyp
  2. +60 −0 src/CamShift.cc
  3. +23 −0 src/CamShift.h
  4. +20 −0 test/unit.js
View
@@ -9,6 +9,7 @@
, "src/Contours.cc"
, "src/Point.cc"
, "src/VideoCaptureWrap.cc"
+ , "src/CamShift.cc"
]
, 'libraries': [
'<!@(pkg-config --libs opencv)'
View
@@ -0,0 +1,60 @@
+#include "Camshift.h"
+#include "OpenCV.h"
+#include "Matrix.h"
+
+Persistent<FunctionTemplate> TrackedObject::constructor;
+
+void
+TrackedObject::Init(Handle<Object> target) {
+ HandleScope scope;
+
+ // Constructor
+ constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(TrackedObject::New));
+ constructor->InstanceTemplate()->SetInternalFieldCount(1);
+ constructor->SetClassName(String::NewSymbol("TrackedObject"));
+
+ // Prototype
+ //Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
+
+ target->Set(String::NewSymbol("TrackedObject"), constructor->GetFunction());
+};
+
+
+Handle<Value>
+TrackedObject::New(const Arguments &args) {
+ HandleScope scope;
+
+ if (args.This()->InternalFieldCount() == 0)
+ return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Cannot Instantiate without new")));
+
+ Matrix* m = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
+ cv::Rect r;
+ TrackedObject *to = new TrackedObject(m->mat, r);
+ to->Wrap(args.This());
+ return args.This();
+}
+
+
+TrackedObject::TrackedObject(cv::Mat image, cv::Rect rect){
+}
+
+
+Handle<Value>
+TrackedObject::Track(const v8::Arguments& args){
+ SETUP_FUNCTION(TrackedObject)
+
+ if (args.Length() != 1){
+ v8::ThrowException(v8::Exception::TypeError(v8::String::New("track takes an image param")));
+ return Undefined();
+ }
+
+ Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
+
+ cv::RotatedRect r;
+
+ r = cv::CamShift(self->prob, self->prev_rect,
+ cv::TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 10, 1));
+
+
+ return Undefined();
+}
View
@@ -0,0 +1,23 @@
+#include "OpenCV.h"
+
+
+class TrackedObject: public node::ObjectWrap {
+ public:
+ cv::Mat hsv;
+ cv::Mat hue;
+ cv::Mat mask;
+ cv::Mat prob;
+
+ //cv::Histogram* hist;
+ cv::Rect prev_rect;
+ // cv::Box2D curr_box;
+
+ static Persistent<FunctionTemplate> constructor;
+ static void Init(Handle<Object> target);
+ static Handle<Value> New(const Arguments &args);
+
+ TrackedObject(cv::Mat image, cv::Rect rect);
+
+ JSFUNC(Track);
+
+};
View
@@ -257,6 +257,26 @@ vows.describe('Smoke Tests OpenCV').addBatch({
}
+ , "CamShift" : {
+ topic : require('../lib/opencv')
+
+ , "create TrackedObject" : function(cv){
+ var im = fs.readFileSync('./examples/mona.png')
+ , track = new cv.TrackedObject(im, [10,10, 50,50]);
+
+ assert.ok(track);
+ }
+
+ , "use TrackedObject.track" : function(cv){
+ var im = fs.readFileSync('./examples/mona.png')
+ , im2 = fs.readFileSync('./examples/mona.png')
+ , tracked = new cv.TrackedObject(im, [10,10, 50,50]);
+
+ assert.equal(tracked.track(im2), [10, 10, 50, 50]);
+ }
+
+ }
+
}).export(module);

0 comments on commit 3a1477c

Please sign in to comment.