Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP on CamShift with TrackedObject re #22
- Loading branch information
1 parent
e4c0ddd
commit 3a1477c
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters