Permalink
Browse files

New rectangle function, new example and added std namespace fixing th…

…e vector compile problem
  • Loading branch information...
1 parent 4d1ea28 commit 9f882051436258588f3551169f6fbf3bd9339d82 @raichuk raichuk committed Jun 22, 2012
Showing with 58 additions and 1 deletion.
  1. +20 −0 examples/Face.js
  2. +2 −0 src/Contours.h
  3. +34 −0 src/Matrix.cc
  4. +1 −0 src/Matrix.h
  5. +1 −1 src/Point.cc
View
@@ -0,0 +1,20 @@
+var cv = require('../lib/opencv');
+
+var COLOR = [0, 255, 0]; //default red
+var thickness = 2; // default 1
+
+cv.readImage('./mona.png', function(err, im) {
+
+ im.detectObject('../data/haarcascade_frontalface_alt2.xml', {}, function(err, faces) {
+
+ for(var k = 0; k < faces.length; k++) {
+
+ face = faces[k];
+ im.rectangle([face.x, face.y], [face.x + face.width, face.y + face.height], COLOR, 2);
+ }
+
+ im.save('/tmp/salida.png');
+
+ });
+
+});
View
@@ -1,5 +1,7 @@
#include "OpenCV.h"
+using namespace std;
+
class Contour: public node::ObjectWrap {
public:
View
@@ -39,6 +39,7 @@ Matrix::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor, "size", Size);
NODE_SET_PROTOTYPE_METHOD(constructor, "toBuffer", ToBuffer);
NODE_SET_PROTOTYPE_METHOD(constructor, "ellipse", Ellipse);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "rectangle", Rectangle);
NODE_SET_PROTOTYPE_METHOD(constructor, "save", Save);
NODE_SET_PROTOTYPE_METHOD(constructor, "resize", Resize);
NODE_SET_PROTOTYPE_METHOD(constructor, "channels", Channels);
@@ -301,6 +302,39 @@ Matrix::Ellipse(const v8::Arguments& args){
}
+Handle<Value>
+Matrix::Rectangle(const Arguments& args) {
+ SETUP_FUNCTION(Matrix)
+
+
+ if(args[0]->IsArray() && args[1]->IsArray()) {
+ Local<Object> xy = args[0]->ToObject();
+ Local<Object> width_height = args[1]->ToObject();
+
+ cv::Scalar color(0, 0, 255);
+
+ if(args[2]->IsArray()) {
+ Local<Object> objColor = args[2]->ToObject();
+ color = setColor(objColor);
+ }
+
+ int x = xy->Get(0)->IntegerValue();
+ int y = xy->Get(1)->IntegerValue();
+
+ int width = width_height->Get(0)->IntegerValue();
+ int height = width_height->Get(1)->IntegerValue();
+
+ int thickness = 1;
+
+ if(args[3]->IntegerValue())
+ thickness = args[3]->IntegerValue();
+
+ cv::rectangle(self->mat, cv::Point(x, y), cv::Point(width, height), color, thickness);
+ }
+
+ return scope.Close(v8::Null());
+}
+
Handle<Value>
Matrix::Save(const v8::Arguments& args){
HandleScope scope;
View
@@ -64,6 +64,7 @@ class Matrix: public node::ObjectWrap {
JSFUNC(Channels)
JSFUNC(ToBuffer)
JSFUNC(Ellipse)
+ JSFUNC(Rectangle)
JSFUNC(Empty)
JSFUNC(Save)
View
@@ -70,4 +70,4 @@ Point::Dot(const v8::Arguments& args){
Point::Point(double x, double y): ObjectWrap() {
point = cvPoint2D32f(x, y);
-}
+}

0 comments on commit 9f88205

Please sign in to comment.