Permalink
Browse files

Add basic highgui window support

  • Loading branch information...
1 parent 6225a3c commit 77279a33c0c15ccf034b85aed00a053e6f69c26c @peterbraden committed Mar 4, 2013
Showing with 101 additions and 3 deletions.
  1. +1 −0 binding.gyp
  2. +3 −3 smoke/smoke.sh
  3. +8 −0 smoke/smoketest.js
  4. +67 −0 src/HighGUI.cc
  5. +19 −0 src/HighGUI.h
  6. +3 −0 src/init.cc
View
1 binding.gyp
@@ -10,6 +10,7 @@
, "src/Point.cc"
, "src/VideoCaptureWrap.cc"
, "src/CamShift.cc"
+ , "src/HighGUI.cc"
]
, 'libraries': [
'<!@(pkg-config --libs opencv)'
View
6 smoke/smoke.sh
@@ -3,6 +3,6 @@ node-gyp build && echo '-- Compiled OK --
' && node smoke/smoketest.js && echo '-- Smoke Done, running tests --
-' && npm test && echo '-- Tests Run, runnning examples --
-(building example data)
-' && ./examples/make-example-files.sh && node examples/motion-track.js
+' && npm test # && echo '-- Tests Run, runnning examples --
+#(building example data)
+#' && ./examples/make-example-files.sh && node examples/motion-track.js
View
8 smoke/smoketest.js
@@ -1,5 +1,13 @@
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)
+})
+
/*
View
67 src/HighGUI.cc
@@ -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());
+}
View
19 src/HighGUI.h
@@ -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);
+
+};
View
3 src/init.cc
@@ -5,6 +5,7 @@
#include "VideoCaptureWrap.h"
#include "Contours.h"
#include "CamShift.h"
+#include "HighGUI.h"
extern "C" void
@@ -17,6 +18,8 @@ init(Handle<Object> target) {
VideoCaptureWrap::Init(target);
Contour::Init(target);
TrackedObject::Init(target);
+
+ NamedWindow::Init(target);
};
NODE_MODULE(opencv, init)

0 comments on commit 77279a3

Please sign in to comment.