mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Add basic highgui window support
This commit is contained in:
parent
6225a3c0f0
commit
77279a33c0
@ -10,6 +10,7 @@
|
|||||||
, "src/Point.cc"
|
, "src/Point.cc"
|
||||||
, "src/VideoCaptureWrap.cc"
|
, "src/VideoCaptureWrap.cc"
|
||||||
, "src/CamShift.cc"
|
, "src/CamShift.cc"
|
||||||
|
, "src/HighGUI.cc"
|
||||||
]
|
]
|
||||||
, 'libraries': [
|
, 'libraries': [
|
||||||
'<!@(pkg-config --libs opencv)'
|
'<!@(pkg-config --libs opencv)'
|
||||||
|
|||||||
@ -3,6 +3,6 @@ node-gyp build && echo '-- Compiled OK --
|
|||||||
|
|
||||||
' && node smoke/smoketest.js && echo '-- Smoke Done, running tests --
|
' && node smoke/smoketest.js && echo '-- Smoke Done, running tests --
|
||||||
|
|
||||||
' && npm test && echo '-- Tests Run, runnning examples --
|
' && npm test # && echo '-- Tests Run, runnning examples --
|
||||||
(building example data)
|
#(building example data)
|
||||||
' && ./examples/make-example-files.sh && node examples/motion-track.js
|
#' && ./examples/make-example-files.sh && node examples/motion-track.js
|
||||||
|
|||||||
@ -1,5 +1,13 @@
|
|||||||
var cv = require('../lib/opencv')
|
var cv = require('../lib/opencv')
|
||||||
|
|
||||||
|
var win = new cv.NamedWindow("foo");
|
||||||
|
cv.readImage('./examples/stuff.png', function(e, im){
|
||||||
|
win.show(im);
|
||||||
|
setTimeout(function(){
|
||||||
|
win.destroy();
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
67
src/HighGUI.cc
Normal file
67
src/HighGUI.cc
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#include "HighGUI.h"
|
||||||
|
#include "OpenCV.h"
|
||||||
|
#include "Matrix.h"
|
||||||
|
|
||||||
|
|
||||||
|
Persistent<FunctionTemplate> NamedWindow::constructor;
|
||||||
|
|
||||||
|
void
|
||||||
|
NamedWindow::Init(Handle<Object> target) {
|
||||||
|
HandleScope scope;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(NamedWindow::New));
|
||||||
|
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
|
constructor->SetClassName(String::NewSymbol("NamedWindow"));
|
||||||
|
|
||||||
|
// Prototype
|
||||||
|
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||||
|
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(constructor, "show", Show);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(constructor, "destroy", Destroy);
|
||||||
|
target->Set(String::NewSymbol("NamedWindow"), constructor->GetFunction());
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Handle<Value>
|
||||||
|
NamedWindow::New(const Arguments &args) {
|
||||||
|
HandleScope scope;
|
||||||
|
|
||||||
|
if (args.This()->InternalFieldCount() == 0){
|
||||||
|
JSTHROW_TYPE("Cannot Instantiate without new")
|
||||||
|
}
|
||||||
|
|
||||||
|
NamedWindow* win;
|
||||||
|
if (args.Length() == 1){
|
||||||
|
win = new NamedWindow(std::string(*v8::String::AsciiValue(args[0]->ToString())), 0);
|
||||||
|
} else if (args.Length() == 2){
|
||||||
|
win = new NamedWindow(std::string(*v8::String::AsciiValue(args[0]->ToString())), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
win->Wrap(args.Holder());
|
||||||
|
return scope.Close(args.Holder());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NamedWindow::NamedWindow(const std::string& name, int f){
|
||||||
|
winname = std::string(name);
|
||||||
|
flags = f;
|
||||||
|
cv::namedWindow(winname, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Handle<Value>
|
||||||
|
NamedWindow::Show(const v8::Arguments& args){
|
||||||
|
SETUP_FUNCTION(NamedWindow)
|
||||||
|
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||||
|
cv::imshow(self->winname, im->mat);
|
||||||
|
|
||||||
|
return scope.Close(args.Holder());
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle<Value>
|
||||||
|
NamedWindow::Destroy(const v8::Arguments& args){
|
||||||
|
SETUP_FUNCTION(NamedWindow)
|
||||||
|
cv::destroyWindow(self->winname);
|
||||||
|
return scope.Close(args.Holder());
|
||||||
|
}
|
||||||
19
src/HighGUI.h
Normal file
19
src/HighGUI.h
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "OpenCV.h"
|
||||||
|
|
||||||
|
|
||||||
|
class NamedWindow: public node::ObjectWrap {
|
||||||
|
public:
|
||||||
|
std::string winname;
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
|
||||||
|
static Persistent<FunctionTemplate> constructor;
|
||||||
|
static void Init(Handle<Object> target);
|
||||||
|
static Handle<Value> New(const Arguments &args);
|
||||||
|
|
||||||
|
NamedWindow(const std::string& winname, int flags);
|
||||||
|
|
||||||
|
JSFUNC(Show);
|
||||||
|
JSFUNC(Destroy);
|
||||||
|
|
||||||
|
};
|
||||||
@ -5,6 +5,7 @@
|
|||||||
#include "VideoCaptureWrap.h"
|
#include "VideoCaptureWrap.h"
|
||||||
#include "Contours.h"
|
#include "Contours.h"
|
||||||
#include "CamShift.h"
|
#include "CamShift.h"
|
||||||
|
#include "HighGUI.h"
|
||||||
|
|
||||||
|
|
||||||
extern "C" void
|
extern "C" void
|
||||||
@ -17,6 +18,8 @@ init(Handle<Object> target) {
|
|||||||
VideoCaptureWrap::Init(target);
|
VideoCaptureWrap::Init(target);
|
||||||
Contour::Init(target);
|
Contour::Init(target);
|
||||||
TrackedObject::Init(target);
|
TrackedObject::Init(target);
|
||||||
|
|
||||||
|
NamedWindow::Init(target);
|
||||||
};
|
};
|
||||||
|
|
||||||
NODE_MODULE(opencv, init)
|
NODE_MODULE(opencv, init)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user