forked from peterbraden/node-opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge github.com:talvarez/node-opencv
Conflicts: src/Matrix.cc src/Matrix.h
- Loading branch information
Showing
58 changed files
with
847 additions
and
184 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
node-waf configure build && | ||
cd examples && | ||
#node face_detection.js | ||
node $1 |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Examples | ||
Face Detection | ||
|
||
cv.readImage("./examples/test.jpg", function(err, im){ | ||
im.detectObject("./examples/haarcascade_frontalface_alt.xml", {}, function(err, faces){ | ||
for (var i=0;i<faces.length; i++){ | ||
var x = faces[i] | ||
im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2); | ||
} | ||
im.save('./out.jpg'); | ||
|
||
}); | ||
}) | ||
|
||
API Documentation | ||
Matrix | ||
|
||
The matrix is the most useful base datastructure in OpenCV. Things like images are just matrices of pixels. | ||
Creation | ||
|
||
new Matrix(width, height) | ||
|
||
Or you can use opencv to read in image files. Supported formats are in the OpenCV docs, but jpgs etc are supported. | ||
|
||
cv.readImage(filename, function(mat){ | ||
... | ||
}) | ||
|
||
cv.readImage(buffer, function(mat){ | ||
... | ||
}) | ||
|
||
If you need to pipe data into an image, you can use an imagestream: | ||
|
||
var s = new cv.ImageStream() | ||
|
||
s.on('load', function(matrix){ | ||
... | ||
}) | ||
|
||
fs.createReadStream('./examples/test.jpg').pipe(s); | ||
|
||
Accessors | ||
|
||
var mat = new cv.Matrix.Eye(4,4); // Create identity matrix | ||
|
||
mat.get(0,0) // 1 | ||
|
||
mat.row(0) // [1,0,0,0] | ||
mat.col(4) // [0,0,0,1] | ||
|
||
Image Processing | ||
Object Detection | ||
|
||
There is a shortcut method for Viola-Jones Haar Cascade object detection. This can be used for face detection etc. | ||
|
||
mat.detectObject(haar_cascade_xml, opts, function(err, matches){}) | ||
|
||
WIP | ||
|
||
This is a WIP. I've never written C++ before so the code may be interesting - if I'm doing stuff wrong please feel free to correct me. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var cv = require('../lib/opencv'); | ||
|
||
|
||
cv.readImage("./mona.png", function(err, orig) { | ||
|
||
cv.readImage("./over_text.png", function(err, over_text) { | ||
|
||
var result = new cv.Matrix(orig.width(), orig.height()); | ||
|
||
result.addWeighted(orig, 0.7, over_text, 0.9); | ||
result.save("/tmp/weighted.png"); | ||
}); | ||
|
||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
var cv = require('../lib/opencv'); | ||
|
||
var camera = new cv.VideoCapture(0); | ||
|
||
|
||
setInterval(function() { | ||
|
||
camera.read(function(im) { | ||
|
||
im.save('/tmp/cam.png'); | ||
}); | ||
|
||
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var cv = require('../lib/opencv'); | ||
|
||
var lowThresh = 0; | ||
var highThresh = 100; | ||
var nIters = 2; | ||
var maxArea = 2500; | ||
|
||
var GREEN = [0, 255, 0]; //B, G, R | ||
var WHITE = [255, 255, 255]; //B, G, R | ||
|
||
|
||
cv.readImage('./stuff.png', function(err, im) { | ||
|
||
var big = new cv.Matrix(im.width(), im.height()); | ||
var all = new cv.Matrix(im.width(), im.height()); | ||
|
||
im.convertGrayscale(); | ||
im_canny = im.copy(); | ||
|
||
im_canny.canny(lowThresh, highThresh); | ||
im_canny.dilate(nIters); | ||
|
||
contours = im_canny.findContours(); | ||
|
||
for(i = 0; i < contours.size(); i++) { | ||
if(contours.area(i) > maxArea) { | ||
big.drawContour(contours, i, GREEN); | ||
} | ||
} | ||
|
||
all.drawAllContours(contours, WHITE); | ||
|
||
|
||
big.save('/tmp/big.png'); | ||
all.save('/tmp/all.png'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var cv = require('../lib/opencv'); | ||
|
||
|
||
cv.readImage("./mona.png", function(err, im) { | ||
|
||
img_hsv = im.copy(); | ||
img_gray = im.copy(); | ||
|
||
img_hsv.convertHSVscale(); | ||
img_gray.convertGrayscale(); | ||
|
||
im.save("/tmp/nor.png"); | ||
img_hsv.save("/tmp/hsv.png"); | ||
img_gray.save("/tmp/gray.png"); | ||
|
||
console.log("Guardado"); | ||
}); | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var cv = require('../lib/opencv') | ||
, assert = require('assert') | ||
, fs =require('fs') | ||
|
||
|
||
//console.log(cv.version) | ||
cv.readImage("./mona.png", function(err, im){ | ||
|
||
im.detectObject("./haarcascade_frontalface_alt.xml", {}, function(err, faces){ | ||
|
||
for (var i=0;i<faces.length; i++){ | ||
var x = faces[i]; | ||
im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2); | ||
} | ||
|
||
im.save('./out.png'); | ||
}); | ||
}); |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
var cv = require('../lib/opencv'); | ||
|
||
|
||
cv.readImage("./mona.png", function(err, im) { | ||
salt(im, 3000); | ||
im.save("/tmp/salt.png"); | ||
}); | ||
|
||
|
||
|
||
function salt(img, n) { | ||
|
||
|
||
if (img.channels() == 1) { | ||
|
||
console.log("1 Canales"); | ||
} else if (img.channels() == 3) { | ||
|
||
for(k = 0; k < n; k ++) { | ||
i = Math.random() * img.width(); | ||
j = Math.random() * img.height(); | ||
|
||
img.set(j, i, 255); | ||
} | ||
} | ||
|
||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ var cv = require('./lib/opencv') | |
im.save('./out.jpg'); | ||
|
||
}); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "Contours.h" | ||
#include "OpenCV.h" | ||
|
||
#include <iostream> | ||
|
||
v8::Persistent<FunctionTemplate> Contour::constructor; | ||
|
||
|
||
void | ||
Contour::Init(Handle<Object> target) { | ||
HandleScope scope; | ||
|
||
//Class | ||
v8::Local<v8::FunctionTemplate> m = v8::FunctionTemplate::New(New); | ||
m->SetClassName(v8::String::NewSymbol("Contours")); | ||
|
||
// Constructor | ||
constructor = Persistent<FunctionTemplate>::New(m); | ||
constructor->InstanceTemplate()->SetInternalFieldCount(1); | ||
constructor->SetClassName(String::NewSymbol("Contours")); | ||
|
||
// Prototype | ||
Local<ObjectTemplate> proto = constructor->PrototypeTemplate(); | ||
|
||
|
||
NODE_SET_PROTOTYPE_METHOD(constructor, "size", Size); | ||
NODE_SET_PROTOTYPE_METHOD(constructor, "area", Area); | ||
target->Set(String::NewSymbol("Contours"), m->GetFunction()); | ||
}; | ||
|
||
|
||
Handle<Value> | ||
Contour::New(const Arguments &args) { | ||
HandleScope scope; | ||
|
||
if (args.This()->InternalFieldCount() == 0) | ||
return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Cannot instantiate without new"))); | ||
|
||
Contour *contours; | ||
contours = new Contour; | ||
|
||
contours->Wrap(args.Holder()); | ||
return scope.Close(args.Holder()); | ||
} | ||
|
||
|
||
Contour::Contour(): ObjectWrap() { | ||
} | ||
|
||
|
||
Handle<Value> | ||
Contour::Size(const Arguments &args) { | ||
HandleScope scope; | ||
|
||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This()); | ||
|
||
return scope.Close(Number::New(self->contours.size())); | ||
|
||
} | ||
|
||
|
||
Handle<Value> | ||
Contour::Area(const Arguments &args) { | ||
HandleScope scope; | ||
|
||
Contour *self = ObjectWrap::Unwrap<Contour>(args.This()); | ||
int pos = args[0]->NumberValue(); | ||
|
||
//return scope.Close(Number::New(contourArea(self->contours))); | ||
return scope.Close(Number::New(contourArea(cv::Mat(self->contours[pos])))); | ||
|
||
|
||
} |
Oops, something went wrong.