VideoWriter

This commit is contained in:
Peter Braden 2013-03-05 17:42:58 -08:00
parent daca1a14cb
commit 1322e58bd9
5 changed files with 103 additions and 4 deletions

View File

@ -9,6 +9,7 @@
, "src/Contours.cc"
, "src/Point.cc"
, "src/VideoCaptureWrap.cc"
, "src/VideoWriter.cc"
, "src/CamShift.cc"
, "src/HighGUI.cc"
]

View File

@ -129,10 +129,14 @@ videostream.read = function(){
var frame = function(){
self.video.read(function(mat){
self.emit('data', mat)
if (!this.paused){
process.nextTick(frame)
}
if (mat.width() && mat.height()){
self.emit('data', mat)
if (!this.paused){
process.nextTick(frame)
}
} else {
self.emit('end')
}
})
}

77
src/VideoWriter.cc Normal file
View File

@ -0,0 +1,77 @@
#include "VideoWriter.h"
#include "Matrix.h"
#include "OpenCV.h"
v8::Persistent<FunctionTemplate> VideoWriterWrap::constructor;
void
VideoWriterWrap::Init(Handle<Object> target) {
HandleScope scope;
// Constructor
constructor = Persistent<FunctionTemplate>::New(
FunctionTemplate::New(VideoWriterWrap::New));
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(String::NewSymbol("VideoWriter"));
// Prototype
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
NODE_SET_PROTOTYPE_METHOD(constructor, "write", Write);
target->Set(String::NewSymbol("VideoWriter"), constructor->GetFunction());
};
Handle<Value>
VideoWriterWrap::New(const Arguments &args) {
HandleScope scope;
if (args.This()->InternalFieldCount() == 0)
return v8::ThrowException(
v8::Exception::TypeError(v8::String::New("Cannot Instantiate without new")));
VideoWriterWrap *v;
std::string filename;
int codec = CV_FOURCC('M','J','P','G'); // Default mjpg
double fps = 24.0;
cv::Size framesize = cv::Size(640, 320);
//bool isColor; // TODO
filename = std::string(*v8::String::AsciiValue(args[0]->ToString()));
v = new VideoWriterWrap(filename, codec, fps, framesize);
v->Wrap(args.This());
return args.This();
}
VideoWriterWrap::VideoWriterWrap(const std::string& filename, int codec,
double fps, cv::Size framesize){
writer = cv::VideoWriter(filename, codec, fps, framesize);
if (!writer.isOpened()){
std::cout << "VideoWriter: Could not be opened!"
}
}
Handle<Value>
VideoWriterWrap::Write(const Arguments &args) {
SETUP_FUNCTION(VideoWriterWrap)
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
self->writer << im->mat;
return scope.Close(v8::Undefined());
}

15
src/VideoWriter.h Normal file
View File

@ -0,0 +1,15 @@
#include "OpenCV.h"
class VideoWriterWrap: public node::ObjectWrap {
public:
cv::VideoWriter writer;
static Persistent<FunctionTemplate> constructor;
static void Init(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
VideoWriterWrap(const std::string& filename, int codec,
double fps, cv::Size framesize);
static Handle<Value> Write(const v8::Arguments&);
};

View File

@ -3,6 +3,7 @@
#include "Matrix.h"
#include "CascadeClassifierWrap.h"
#include "VideoCaptureWrap.h"
#include "VideoWriter.h"
#include "Contours.h"
#include "CamShift.h"
#include "HighGUI.h"
@ -16,6 +17,7 @@ init(Handle<Object> target) {
Matrix::Init(target);
CascadeClassifierWrap::Init(target);
VideoCaptureWrap::Init(target);
VideoWriterWrap::Init(target);
Contour::Init(target);
TrackedObject::Init(target);