mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge pull request #284 from mvines/a512cf9
Add support for VideoCapture grab/retrieve
This commit is contained in:
commit
2691de4fa2
@ -37,6 +37,8 @@ VideoCaptureWrap::Init(Handle<Object> target) {
|
|||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "setPosition", SetPosition);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "setPosition", SetPosition);
|
||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "close", Close);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "close", Close);
|
||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "ReadSync", ReadSync);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "ReadSync", ReadSync);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(ctor, "grab", Grab);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(ctor, "retrieve", Retrieve);
|
||||||
|
|
||||||
target->Set(NanNew("VideoCapture"), ctor->GetFunction());
|
target->Set(NanNew("VideoCapture"), ctor->GetFunction());
|
||||||
};
|
};
|
||||||
@ -141,8 +143,10 @@ NAN_METHOD(VideoCaptureWrap::Close){
|
|||||||
|
|
||||||
class AsyncVCWorker : public NanAsyncWorker {
|
class AsyncVCWorker : public NanAsyncWorker {
|
||||||
public:
|
public:
|
||||||
AsyncVCWorker(NanCallback *callback, VideoCaptureWrap* vc, Matrix* matrix)
|
AsyncVCWorker(NanCallback *callback, VideoCaptureWrap* vc, Matrix* matrix,
|
||||||
: NanAsyncWorker(callback), vc(vc), matrix(matrix) {}
|
bool retrieve = false, int channel = 0)
|
||||||
|
: NanAsyncWorker(callback), vc(vc), matrix(matrix),
|
||||||
|
retrieve(retrieve), channel(channel) {}
|
||||||
~AsyncVCWorker() {}
|
~AsyncVCWorker() {}
|
||||||
|
|
||||||
// Executed inside the worker-thread.
|
// Executed inside the worker-thread.
|
||||||
@ -150,7 +154,13 @@ class AsyncVCWorker : public NanAsyncWorker {
|
|||||||
// here, so everything we need for input and output
|
// here, so everything we need for input and output
|
||||||
// should go on `this`.
|
// should go on `this`.
|
||||||
void Execute () {
|
void Execute () {
|
||||||
this->vc->cap.read(matrix->mat);
|
if (retrieve) {
|
||||||
|
if (!this->vc->cap.retrieve(matrix->mat, channel)) {
|
||||||
|
SetErrorMessage("retrieve failed");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this->vc->cap.read(matrix->mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Executed when the async work is complete
|
// Executed when the async work is complete
|
||||||
@ -180,6 +190,8 @@ class AsyncVCWorker : public NanAsyncWorker {
|
|||||||
private:
|
private:
|
||||||
VideoCaptureWrap *vc;
|
VideoCaptureWrap *vc;
|
||||||
Matrix* matrix;
|
Matrix* matrix;
|
||||||
|
bool retrieve;
|
||||||
|
int channel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -210,3 +222,49 @@ NAN_METHOD(VideoCaptureWrap::ReadSync) {
|
|||||||
|
|
||||||
NanReturnValue(im_to_return);
|
NanReturnValue(im_to_return);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class AsyncGrabWorker : public NanAsyncWorker {
|
||||||
|
public:
|
||||||
|
AsyncGrabWorker(NanCallback *callback, VideoCaptureWrap* vc)
|
||||||
|
: NanAsyncWorker(callback), vc(vc) {}
|
||||||
|
~AsyncGrabWorker() {}
|
||||||
|
|
||||||
|
void Execute () {
|
||||||
|
if (!this->vc->cap.grab()) {
|
||||||
|
SetErrorMessage("grab failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
VideoCaptureWrap *vc;
|
||||||
|
};
|
||||||
|
|
||||||
|
NAN_METHOD(VideoCaptureWrap::Grab) {
|
||||||
|
|
||||||
|
NanScope();
|
||||||
|
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||||
|
|
||||||
|
REQ_FUN_ARG(0, cb);
|
||||||
|
|
||||||
|
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||||
|
NanAsyncQueueWorker(new AsyncGrabWorker(callback, v));
|
||||||
|
|
||||||
|
NanReturnUndefined();
|
||||||
|
}
|
||||||
|
|
||||||
|
NAN_METHOD(VideoCaptureWrap::Retrieve) {
|
||||||
|
|
||||||
|
NanScope();
|
||||||
|
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||||
|
|
||||||
|
int channel = 0;
|
||||||
|
REQ_FUN_ARG(0, cb);
|
||||||
|
INT_FROM_ARGS(channel, 1);
|
||||||
|
|
||||||
|
NanCallback *callback = new NanCallback(cb.As<Function>());
|
||||||
|
NanAsyncQueueWorker(new AsyncVCWorker(callback, v, new Matrix(), true, channel));
|
||||||
|
|
||||||
|
NanReturnUndefined();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,9 @@ class VideoCaptureWrap: public node::ObjectWrap {
|
|||||||
static NAN_METHOD(Read);
|
static NAN_METHOD(Read);
|
||||||
static NAN_METHOD(ReadSync);
|
static NAN_METHOD(ReadSync);
|
||||||
|
|
||||||
|
static NAN_METHOD(Grab);
|
||||||
|
static NAN_METHOD(Retrieve);
|
||||||
|
|
||||||
//(Optional) For setting width and height of the input video stream
|
//(Optional) For setting width and height of the input video stream
|
||||||
static NAN_METHOD(SetWidth);
|
static NAN_METHOD(SetWidth);
|
||||||
static NAN_METHOD(SetHeight);
|
static NAN_METHOD(SetHeight);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user