From efc55fbd0ba1a866d9441351192a4fbfac22060f Mon Sep 17 00:00:00 2001 From: Salman Date: Sat, 3 May 2014 13:04:33 +0500 Subject: [PATCH 1/3] updated BackgroundSubtractor to work with OpenCV 2.4.X instead of 3.0.0 --- src/BackgroundSubtractor.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/BackgroundSubtractor.cc b/src/BackgroundSubtractor.cc index 86ea9f4..a982416 100644 --- a/src/BackgroundSubtractor.cc +++ b/src/BackgroundSubtractor.cc @@ -29,7 +29,7 @@ BackgroundSubtractorWrap::New(const Arguments &args) { JSTHROW_TYPE("Cannot Instantiate without new") //Create MOG by default - cv::Ptr bg = cv::createBackgroundSubtractorMOG(200, 5, 0.7, 0); + cv::Ptr bg; BackgroundSubtractorWrap *pt = new BackgroundSubtractorWrap(bg); pt->Wrap(args.This()); @@ -55,9 +55,7 @@ BackgroundSubtractorWrap::CreateMOG(const Arguments &args) { Local n = BackgroundSubtractorWrap::constructor->GetFunction()->NewInstance(); - cv::Ptr bg = cv::createBackgroundSubtractorMOG( - history, nmixtures, backgroundRatio, noiseSigma - ); + cv::Ptr bg; BackgroundSubtractorWrap *pt = new BackgroundSubtractorWrap(bg); pt->Wrap(n); @@ -106,7 +104,7 @@ BackgroundSubtractorWrap::ApplyMOG(const Arguments &args) { } cv::Mat _fgMask; - self->subtractor->apply(mat, _fgMask); + self->subtractor->operator()(mat, _fgMask); img->mat = _fgMask; From 28750d127543e9547cbc21176e18ecabc5d08b19 Mon Sep 17 00:00:00 2001 From: Salman Date: Sat, 3 May 2014 16:30:13 +0500 Subject: [PATCH 2/3] Added setWidth and setHeight for VideoCapture issue #126 --- src/VideoCaptureWrap.cc | 27 +++++++++++++++++++++++++++ src/VideoCaptureWrap.h | 4 ++++ 2 files changed, 31 insertions(+) diff --git a/src/VideoCaptureWrap.cc b/src/VideoCaptureWrap.cc index d28ae50..a98ff69 100755 --- a/src/VideoCaptureWrap.cc +++ b/src/VideoCaptureWrap.cc @@ -2,6 +2,9 @@ #include "Matrix.h" #include "OpenCV.h" +#include +using namespace std; + void AsyncRead(uv_work_t *req); void AfterAsyncRead(uv_work_t *req); @@ -31,6 +34,8 @@ VideoCaptureWrap::Init(Handle target) { //Local proto = constructor->PrototypeTemplate(); NODE_SET_PROTOTYPE_METHOD(constructor, "read", Read); + NODE_SET_PROTOTYPE_METHOD(constructor, "setWidth", SetWidth); + NODE_SET_PROTOTYPE_METHOD(constructor, "setHeight", SetHeight); target->Set(String::NewSymbol("VideoCapture"), constructor->GetFunction()); }; @@ -77,6 +82,28 @@ VideoCaptureWrap::VideoCaptureWrap(const std::string& filename){ } +Handle +VideoCaptureWrap::SetWidth(const Arguments &args){ + + HandleScope scope; + VideoCaptureWrap *v = ObjectWrap::Unwrap(args.This()); + + if(v->cap.isOpened()) + v->cap.set(CV_CAP_PROP_FRAME_WIDTH, 320); + + return Undefined(); +} + +Handle +VideoCaptureWrap::SetHeight(const Arguments &args){ + + HandleScope scope; + VideoCaptureWrap *v = ObjectWrap::Unwrap(args.This()); + + v->cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240); + + return Undefined(); +} Handle VideoCaptureWrap::Read(const Arguments &args) { diff --git a/src/VideoCaptureWrap.h b/src/VideoCaptureWrap.h index 397ee27..5d5f96c 100755 --- a/src/VideoCaptureWrap.h +++ b/src/VideoCaptureWrap.h @@ -13,6 +13,10 @@ class VideoCaptureWrap: public node::ObjectWrap { static Handle Read(const v8::Arguments&); + //(Optional) For setting width and height of the input video stream + static Handle SetWidth(const v8::Arguments&); + static Handle SetHeight(const v8::Arguments&); + static Handle GetFrameAt(const v8::Arguments&); From b62b09502c682cf350607f16d1be81bd66ed1596 Mon Sep 17 00:00:00 2001 From: Salman Date: Sat, 3 May 2014 16:35:26 +0500 Subject: [PATCH 3/3] updated VideoCaptureWrap with setWidth() and setHeight() --- src/VideoCaptureWrap.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/VideoCaptureWrap.cc b/src/VideoCaptureWrap.cc index a98ff69..a23d6b3 100755 --- a/src/VideoCaptureWrap.cc +++ b/src/VideoCaptureWrap.cc @@ -88,10 +88,15 @@ VideoCaptureWrap::SetWidth(const Arguments &args){ HandleScope scope; VideoCaptureWrap *v = ObjectWrap::Unwrap(args.This()); - if(v->cap.isOpened()) - v->cap.set(CV_CAP_PROP_FRAME_WIDTH, 320); + if(args.Length() != 1) + return scope.Close(Undefined()); + + int w = args[0]->IntegerValue(); - return Undefined(); + if(v->cap.isOpened()) + v->cap.set(CV_CAP_PROP_FRAME_WIDTH, w); + + return scope.Close(Undefined()); } Handle @@ -100,7 +105,12 @@ VideoCaptureWrap::SetHeight(const Arguments &args){ HandleScope scope; VideoCaptureWrap *v = ObjectWrap::Unwrap(args.This()); - v->cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240); + if(args.Length() != 1) + return scope.Close(Undefined()); + + int h = args[0]->IntegerValue(); + + v->cap.set(CV_CAP_PROP_FRAME_HEIGHT, h); return Undefined(); }