From 28750d127543e9547cbc21176e18ecabc5d08b19 Mon Sep 17 00:00:00 2001 From: Salman Date: Sat, 3 May 2014 16:30:13 +0500 Subject: [PATCH] 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&);