Comparar commits
79 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| cb6a8c4816 | |||
| ceb4d1f5e0 | |||
| c4cc2d45b8 | |||
| 391eb01ca6 | |||
| 3b5311cf42 | |||
| 298cc5adf3 | |||
| e9cbf158d5 | |||
| d4579e6d4c | |||
| d1ffdb056f | |||
| f7bd72f1ae | |||
| 03e444071c | |||
| 7468d0e5fe | |||
| 849e8a7beb | |||
| 7e564d504e | |||
| 0d43626aa0 | |||
| 809b5eba50 | |||
| 26484a1ed2 | |||
| ad9623c2f6 | |||
| a640b94dc7 | |||
| ef423a2be9 | |||
| b4489cfb77 | |||
| 6a6fb0ea7e | |||
| cb7a49b4f1 | |||
| 037cfb8c9c | |||
| 624194e334 | |||
| e1f4182a3e | |||
| f74971be01 | |||
| 8037d68386 | |||
| 55b2aa2476 | |||
| 0b6aab7b2b | |||
| 06e984c8f6 | |||
| 1faf584392 | |||
| e8cc061187 | |||
| 48ab05f624 | |||
| 946e1fc344 | |||
| c01ae532a6 | |||
| f855b2a332 | |||
| 97ffde101f | |||
| ce126ba9c8 | |||
| 6412013e41 | |||
| 9bf1f8bfdc | |||
| 8bfb1630cc | |||
| dbebe54425 | |||
| 279c3709f7 | |||
| 447c949d09 | |||
| 82694e5082 | |||
| 7272c1a9b5 | |||
| 0ff2d8dc83 | |||
| cc16770900 | |||
| 83ef8576dc | |||
| e1db78e6d9 | |||
| 5c1243329d | |||
| 1adb8409b9 | |||
| 7b6fad7606 | |||
| ec160560fc | |||
| 8d618a523a | |||
| 48996e2448 | |||
| 7532b9e332 | |||
| 8f8181b539 | |||
| 62293f5ecb | |||
| 9f88205143 | |||
| 4d1ea2867b | |||
| a0308135cb | |||
| b73174c00f | |||
| efbae5b61b | |||
| c4a1c7161f | |||
| 6168713d5f | |||
| 5f4ef5af30 | |||
| d154496199 | |||
| 0c7d496c0d | |||
| 8468ea4385 | |||
| 19526c294b | |||
| 2d1c374918 | |||
| be208afaae | |||
| c13aa6a945 | |||
| 765ee8d68b | |||
| 118da26a80 | |||
| 43b376e5e4 | |||
| 1f41b20438 |
Arquivo normal → Arquivo executável
+2
@@ -2,3 +2,5 @@ build
|
||||
.lock-wscript
|
||||
.DS_Store
|
||||
node_modules
|
||||
npm-debug.log
|
||||
out.jpg
|
||||
|
||||
Arquivo normal → Arquivo executável
+2
-10
@@ -3,14 +3,6 @@ node_js:
|
||||
- 0.6
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update
|
||||
- sudo apt-get upgrade
|
||||
- sudo apt-get install libavformat-dev
|
||||
- sudo apt-get install ffmpeg
|
||||
- sudo apt-get install libcv2.1
|
||||
- sudo apt-get install libcvaux2.1
|
||||
- sudo apt-get install libhighgui2.1
|
||||
- sudo apt-get install libcv-dev
|
||||
- sudo apt-get install libcvaux-dev
|
||||
- sudo apt-get install libcv-dev
|
||||
- sudo apt-get install libopencv-dev
|
||||
- sudo apt-get install libhighgui-dev
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
Copyright 2012 Peter Braden and other contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Arquivo normal → Arquivo executável
+40
-11
@@ -3,11 +3,13 @@
|
||||
[](http://travis-ci.org/peterbraden/node-opencv)
|
||||
|
||||
|
||||
[OpenCV](http://opencv.willowgarage.com/wiki/) bindings for Node.js
|
||||
[OpenCV](http://opencv.willowgarage.com/wiki/) bindings for Node.js. OpenCV is the defacto computer vision library - by interfacing with it natively in node, we get powerful real time vision in js.
|
||||
|
||||
People are using node-opencv to fly control quadrocoptors, detect faces from webcam images and annotate video streams. If you're using it for something cool, I'd love to hear about it!
|
||||
|
||||
## Install
|
||||
|
||||
You'll need OpenCV installed. I'm using v2.2 because I couldn't get 2.3 to compile, but it should theoretically work with 2.3
|
||||
You'll need OpenCV 2.3.1 installed.
|
||||
|
||||
Then:
|
||||
|
||||
@@ -18,7 +20,7 @@ Then:
|
||||
Or to build the repo:
|
||||
|
||||
|
||||
node-waf configure && node-waf build
|
||||
node-gyp rebuild
|
||||
|
||||
|
||||
## Examples
|
||||
@@ -27,13 +29,12 @@ Or to build the repo:
|
||||
|
||||
|
||||
cv.readImage("./examples/test.jpg", function(err, im){
|
||||
im.detectObject("./examples/haarcascade_frontalface_alt.xml", {}, function(err, faces){
|
||||
im.detectObject("./data/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');
|
||||
|
||||
im.save('./out.jpg');
|
||||
});
|
||||
})
|
||||
|
||||
@@ -70,8 +71,8 @@ If you need to pipe data into an image, you can use an imagestream:
|
||||
|
||||
fs.createReadStream('./examples/test.jpg').pipe(s);
|
||||
|
||||
#### Accessors
|
||||
|
||||
#### Accessing Data
|
||||
|
||||
var mat = new cv.Matrix.Eye(4,4); // Create identity matrix
|
||||
|
||||
mat.get(0,0) // 1
|
||||
@@ -80,9 +81,28 @@ If you need to pipe data into an image, you can use an imagestream:
|
||||
mat.col(4) // [0,0,0,1]
|
||||
|
||||
|
||||
##### Save
|
||||
|
||||
mat.save('./pic.jpg')
|
||||
|
||||
or:
|
||||
|
||||
var buff = mat.toBuffer()
|
||||
|
||||
|
||||
#### Image Processing
|
||||
|
||||
im.convertGrayscale()
|
||||
im.canny(5, 300)
|
||||
im.houghLinesP()
|
||||
|
||||
|
||||
|
||||
#### Simple Drawing
|
||||
|
||||
im.ellipse(x, y)
|
||||
im.line([x1,y1], [x2, y2])
|
||||
|
||||
|
||||
#### Object Detection
|
||||
|
||||
@@ -94,9 +114,18 @@ detection. This can be used for face detection etc.
|
||||
mat.detectObject(haar_cascade_xml, opts, function(err, matches){})
|
||||
|
||||
|
||||
Also:
|
||||
|
||||
mat.goodFeaturesToTrack
|
||||
|
||||
|
||||
## WIP
|
||||
#### Contours
|
||||
|
||||
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.
|
||||
mat.findCountours
|
||||
mat.drawContour
|
||||
mat.drawAllContours
|
||||
|
||||
|
||||
## MIT License
|
||||
The library is distributed under the MIT License - if for some reason that
|
||||
doesn't work for you please get in touch.
|
||||
|
||||
Arquivo normal → Arquivo executável
+1
-1
@@ -42,4 +42,4 @@ cv.loadImage('test.jpg', function(err, im){
|
||||
|
||||
http://www.athile.net/library/wiki/index.php?title=Library/V8/Tutorial#Wrapping_a_Javascript_function_as_a_std::function.3C.3E
|
||||
|
||||
https://www.cloudkick.com/blog/2010/aug/23/writing-nodejs-native-extensions/
|
||||
https://www.cloudkick.com/blog/2010/aug/23/writing-nodejs-native-extensions/
|
||||
|
||||
Arquivo executável
+37
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"targets": [{
|
||||
"target_name": "opencv"
|
||||
, "sources": [
|
||||
"src/init.cc"
|
||||
, "src/Matrix.cc"
|
||||
, "src/OpenCV.cc"
|
||||
, "src/CascadeClassifierWrap.cc"
|
||||
, "src/Contours.cc"
|
||||
, "src/Point.cc"
|
||||
, "src/VideoCaptureWrap.cc"
|
||||
]
|
||||
, 'libraries': [
|
||||
'<!@(pkg-config --libs opencv)'
|
||||
]
|
||||
, 'cflags': [
|
||||
'<!@(pkg-config --cflags --libs opencv)'
|
||||
, '-Wall'
|
||||
]
|
||||
, 'cflags!' : [ '-fno-exceptions']
|
||||
, 'cflags_cc!': [ '-fno-rtti', '-fno-exceptions']
|
||||
, "conditions": [
|
||||
['OS=="mac"', {
|
||||
# cflags on OS X are stupid and have to be defined like this
|
||||
'xcode_settings': {
|
||||
'OTHER_CFLAGS': [
|
||||
'<!@(pkg-config --cflags opencv)'
|
||||
]
|
||||
, "GCC_ENABLE_CPP_RTTI": "YES"
|
||||
, "GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
||||
}
|
||||
}]
|
||||
|
||||
]
|
||||
}]
|
||||
}
|
||||
|
||||
Arquivo executável
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
node-gyp rebuild &&
|
||||
cd examples &&
|
||||
#node face_detection.js
|
||||
node $1
|
||||
Arquivo executável
+15452
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+33158
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo normal → Arquivo executável
Arquivo executável
+23550
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+103493
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+35712
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+18118
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+9803
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+15085
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+10930
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+12586
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+23791
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+21991
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+48433
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+42252
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+46327
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+31930
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+9833
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+29767
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Arquivo executável
+20
@@ -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');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
Arquivo executável
+16
@@ -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");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
Arquivo executável
+13
@@ -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);
|
||||
Arquivo executável
+36
@@ -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('./big.png');
|
||||
all.save('./all.png');
|
||||
});
|
||||
Arquivo executável
+18
@@ -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");
|
||||
});
|
||||
|
||||
Arquivo normal → Arquivo executável
+1
-1
@@ -7,7 +7,7 @@ Face recognition proxy
|
||||
var http = require('http')
|
||||
, request = require('request')
|
||||
, cv = require('../lib/opencv')
|
||||
, face_cascade = new cv.CascadeClassifier("./examples/haarcascade_frontalface_alt.xml")
|
||||
, face_cascade = new cv.CascadeClassifier("./data/haarcascade_frontalface_alt.xml")
|
||||
|
||||
|
||||
|
||||
|
||||
Arquivo executável
+18
@@ -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');
|
||||
});
|
||||
});
|
||||
Arquivo binário não exibido.
|
Antes Largura: | Altura: | Tamanho: 112 KiB |
Arquivo executável
BIN
Arquivo binário não exibido.
|
Depois Largura: | Altura: | Tamanho: 518 KiB |
Arquivo executável
BIN
Arquivo binário não exibido.
|
Depois Largura: | Altura: | Tamanho: 5.4 KiB |
Arquivo executável
+27
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Arquivo executável
BIN
Arquivo binário não exibido.
|
Depois Largura: | Altura: | Tamanho: 186 KiB |
Arquivo normal → Arquivo executável
Arquivo normal → Arquivo executável
Arquivo normal → Arquivo executável
+5
-2
@@ -1,5 +1,5 @@
|
||||
var Stream = require('stream').Stream
|
||||
, Buffers = require('buffers')
|
||||
, Buffers = require('buffer')
|
||||
, util = require('util');
|
||||
|
||||
var bindings = require('./bindings')
|
||||
@@ -18,8 +18,11 @@ The matrix is one of opencv's most core datatypes.
|
||||
var matrix = cv.Matrix.prototype;
|
||||
|
||||
matrix.detectObject = function(classifier, opts, cb){
|
||||
opts = opts || {}
|
||||
|
||||
var face_cascade = new cv.CascadeClassifier(classifier);
|
||||
face_cascade.detectMultiScale(this, cb);
|
||||
face_cascade.detectMultiScale(this, cb, opts.scale, opts.neighbors
|
||||
, opts.min && opts.min[0], opts.min && opts.min[1]);
|
||||
}
|
||||
|
||||
matrix.inspect = function(){
|
||||
|
||||
Arquivo normal → Arquivo executável
+15
-19
@@ -1,22 +1,18 @@
|
||||
{
|
||||
"name": "opencv"
|
||||
, "description": "Node Bindings to OpenCV"
|
||||
, "author": "Peter Braden <peterbraden@peterbraden.co.uk>"
|
||||
, "dependencies": {
|
||||
}
|
||||
, "version" : "0.0.2"
|
||||
|
||||
, "dependencies": {
|
||||
"buffers" : "0.1.1"
|
||||
}
|
||||
|
||||
, "devDependencies": {
|
||||
"name": "opencv",
|
||||
"description": "Node Bindings to OpenCV",
|
||||
"author": "Peter Braden <peterbraden@peterbraden.co.uk>",
|
||||
"dependencies": {
|
||||
"buffers": "0.1.1"
|
||||
},
|
||||
"version": "0.0.8",
|
||||
"devDependencies": {
|
||||
"vows": "*"
|
||||
}
|
||||
, "engine": "node >= 0.4.1"
|
||||
, "scripts": {
|
||||
"preinstall": "node-waf configure build"
|
||||
, "test": "node test/smoke.js"
|
||||
}
|
||||
, "main": "./lib/opencv"
|
||||
},
|
||||
"engine": "node >= 0.4.1",
|
||||
"scripts": {
|
||||
"preinstall": "node-gyp clean rebuild",
|
||||
"test": "vows test/unit.js"
|
||||
},
|
||||
"main": "./lib/opencv"
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
node-waf configure && node-waf build && echo '-- Compiled OK --
|
||||
|
||||
' && node smoketest.js && echo '-- Smoke Done, running tests --
|
||||
|
||||
' && npm test
|
||||
Arquivo executável
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
node-gyp rebuild && echo '-- Compiled OK --
|
||||
|
||||
' && node smoke/smoketest.js && echo '-- Smoke Done, running tests --
|
||||
|
||||
' && npm test
|
||||
Arquivo executável
+34
@@ -0,0 +1,34 @@
|
||||
var cv = require('../lib/opencv')
|
||||
/*
|
||||
new cv.VideoCapture(0).read(function(mat){
|
||||
|
||||
mat.resize(200,100)
|
||||
mat.save('./out.jpg')
|
||||
|
||||
mat.detectObject("./data/haarcascade_frontalface_alt.xml", {min : [30,30]}, function(err, faces){
|
||||
for (var i=0;i<faces.length; i++){
|
||||
var x = faces[i]
|
||||
mat.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);
|
||||
}
|
||||
console.log(faces.length ? (faces.length + " faces found") : "No faces")
|
||||
mat.save('./out.jpg');
|
||||
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
|
||||
cv.readImage("./examples/stuff.png", function(err, im){
|
||||
var i2 = im.copy()
|
||||
i2.convertGrayscale()
|
||||
i2.canny(5, 300)
|
||||
var features = i2.houghLinesP();
|
||||
for (var i=0;i<features.length; i++){
|
||||
var x = features[i]
|
||||
im.line([x[0], x[1]], [x[2], x[3]]);
|
||||
im.ellipse(x[0], x[1]);
|
||||
im.ellipse(x[2], x[3]);
|
||||
}
|
||||
console.log(features)
|
||||
im.save('./out.jpg');
|
||||
});
|
||||
@@ -1,17 +0,0 @@
|
||||
var cv = require('./lib/opencv')
|
||||
, assert = require('assert')
|
||||
, fs =require('fs')
|
||||
|
||||
//console.log(cv.version)
|
||||
|
||||
|
||||
cv.readImage("./examples/mona.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');
|
||||
|
||||
});
|
||||
})
|
||||
Arquivo normal → Arquivo executável
+26
-17
@@ -3,6 +3,8 @@
|
||||
#include "Matrix.h"
|
||||
|
||||
|
||||
void AsyncDetectMultiScale(uv_work_t *req);
|
||||
void AfterAsyncDetectMultiScale(uv_work_t *req);
|
||||
|
||||
Persistent<FunctionTemplate> CascadeClassifierWrap::constructor;
|
||||
|
||||
@@ -16,7 +18,7 @@ CascadeClassifierWrap::Init(Handle<Object> target) {
|
||||
constructor->SetClassName(String::NewSymbol("CascadeClassifier"));
|
||||
|
||||
// Prototype
|
||||
Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "detectMultiScale", DetectMultiScale);
|
||||
|
||||
@@ -61,6 +63,8 @@ struct classifier_baton_t {
|
||||
int minh;
|
||||
int sleep_for;
|
||||
std::vector<cv::Rect> res;
|
||||
|
||||
uv_work_t request;
|
||||
};
|
||||
|
||||
|
||||
@@ -102,42 +106,47 @@ CascadeClassifierWrap::DetectMultiScale(const v8::Arguments& args){
|
||||
baton->minw = minw;
|
||||
baton->minh = minh;
|
||||
baton->sleep_for = 1;
|
||||
self->Ref();
|
||||
baton->request.data = baton;
|
||||
// self->Ref();
|
||||
|
||||
eio_custom(EIO_DetectMultiScale, EIO_PRI_DEFAULT, EIO_AfterDetectMultiScale, baton);
|
||||
ev_ref(EV_DEFAULT_UC);
|
||||
// eio_custom(EIO_DetectMultiScale, EIO_PRI_DEFAULT, EIO_AfterDetectMultiScale, baton);
|
||||
// ev_ref(EV_DEFAULT_UC);
|
||||
|
||||
uv_queue_work(uv_default_loop(), &baton->request, AsyncDetectMultiScale, AfterAsyncDetectMultiScale);
|
||||
|
||||
return Undefined();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CascadeClassifierWrap::EIO_DetectMultiScale(eio_req *req){
|
||||
|
||||
void AsyncDetectMultiScale(uv_work_t *req) {
|
||||
classifier_baton_t *baton = static_cast<classifier_baton_t *>(req->data);
|
||||
|
||||
sleep(baton->sleep_for);
|
||||
|
||||
// sleep(baton->sleep_for);
|
||||
|
||||
std::vector<cv::Rect> objects;
|
||||
|
||||
cv::Mat gray;
|
||||
|
||||
cvtColor( baton->im->mat, gray, CV_BGR2GRAY );
|
||||
equalizeHist( gray, gray);
|
||||
if(baton->im->mat.channels() != 1)
|
||||
cvtColor(baton->im->mat, gray, CV_BGR2GRAY);
|
||||
|
||||
baton->cc->cc.detectMultiScale(gray, objects, baton->scale, baton->neighbors, 0, cv::Size(baton->minw, baton->minh));
|
||||
|
||||
equalizeHist( gray, gray);
|
||||
baton->cc->cc.detectMultiScale(gray, objects, baton->scale, baton->neighbors, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(baton->minw, baton->minh));
|
||||
|
||||
baton->res = objects;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
CascadeClassifierWrap::EIO_AfterDetectMultiScale(eio_req *req){
|
||||
void AfterAsyncDetectMultiScale(uv_work_t *req) {
|
||||
|
||||
HandleScope scope;
|
||||
classifier_baton_t *baton = static_cast<classifier_baton_t *>(req->data);
|
||||
ev_unref(EV_DEFAULT_UC);
|
||||
baton->cc->Unref();
|
||||
// ev_unref(EV_DEFAULT_UC);
|
||||
// baton->cc->Unref();
|
||||
|
||||
Local<Value> argv[2];
|
||||
|
||||
@@ -169,6 +178,6 @@ CascadeClassifierWrap::EIO_AfterDetectMultiScale(eio_req *req){
|
||||
|
||||
delete baton;
|
||||
|
||||
return 0;
|
||||
// return 0;
|
||||
}
|
||||
|
||||
|
||||
Arquivo normal → Arquivo executável
+1
-1
@@ -16,4 +16,4 @@ class CascadeClassifierWrap: public node::ObjectWrap {
|
||||
static void EIO_DetectMultiScale(eio_req *req);
|
||||
static int EIO_AfterDetectMultiScale(eio_req *req);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
Arquivo executável
+73
@@ -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]))));
|
||||
|
||||
|
||||
}
|
||||
Arquivo executável
+20
@@ -0,0 +1,20 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Contour: public node::ObjectWrap {
|
||||
public:
|
||||
|
||||
cv::Mat mat;
|
||||
vector<vector<cv::Point> > contours;
|
||||
static Persistent<FunctionTemplate> constructor;
|
||||
static void Init(Handle<Object> target);
|
||||
static Handle<Value> New(const Arguments &args);
|
||||
|
||||
Contour();
|
||||
|
||||
//JSFUNC(Size)
|
||||
static Handle<Value> Size(const v8::Arguments&);
|
||||
static Handle<Value> Area(const v8::Arguments&);
|
||||
};
|
||||
|
||||
Arquivo normal → Arquivo executável
+598
-117
@@ -1,221 +1,702 @@
|
||||
#include "Contours.h"
|
||||
#include "Matrix.h"
|
||||
#include "OpenCV.h"
|
||||
|
||||
v8::Persistent<FunctionTemplate> Matrix::constructor;
|
||||
|
||||
cv::Scalar setColor(Local<Object> objColor);
|
||||
|
||||
//
|
||||
|
||||
void
|
||||
Matrix::Init(Handle<Object> target) {
|
||||
HandleScope scope;
|
||||
HandleScope scope;
|
||||
|
||||
//Class
|
||||
v8::Local<v8::FunctionTemplate> m = v8::FunctionTemplate::New(New);
|
||||
m->SetClassName(v8::String::NewSymbol("Matrix"));
|
||||
//Class
|
||||
v8::Local<v8::FunctionTemplate> m = v8::FunctionTemplate::New(New);
|
||||
m->SetClassName(v8::String::NewSymbol("Matrix"));
|
||||
|
||||
// Constructor
|
||||
constructor = Persistent<FunctionTemplate>::New(m);
|
||||
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
constructor->SetClassName(String::NewSymbol("Matrix"));
|
||||
// Constructor
|
||||
constructor = Persistent<FunctionTemplate>::New(m);
|
||||
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
constructor->SetClassName(String::NewSymbol("Matrix"));
|
||||
|
||||
// Prototype
|
||||
Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
// Prototype
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "row", Row);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "col", Col);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "row", Row);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "col", Col);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "pixelRow", PixelRow);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "pixelCol", PixelCol);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "empty", Empty);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "get", Get);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "set", Set);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "width", Width);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "height", Height);
|
||||
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, "line", Line);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "save", Save);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "resize", Resize);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "channels", Channels);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "convertGrayscale", ConvertGrayscale);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "convertHSVscale", ConvertHSVscale);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "copy", Copy);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "ptr", Ptr);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "addWeighted", AddWeighted);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "split", Split);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "canny", Canny);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "dilate", Dilate);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "findContours", FindContours);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "drawContour", DrawContour);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "drawAllContours", DrawAllContours);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "goodFeaturesToTrack", GoodFeaturesToTrack);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "houghLinesP", HoughLinesP);
|
||||
|
||||
NODE_SET_METHOD(constructor, "Eye", Eye);
|
||||
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "empty", Empty);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "get", Get);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "set", Set);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "width", Width);
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "height", Height);
|
||||
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, "save", Save);
|
||||
|
||||
NODE_SET_METHOD(constructor, "Eye", Eye);
|
||||
|
||||
|
||||
target->Set(String::NewSymbol("Matrix"), m->GetFunction());
|
||||
};
|
||||
target->Set(String::NewSymbol("Matrix"), m->GetFunction());
|
||||
};
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::New(const Arguments &args) {
|
||||
HandleScope scope;
|
||||
HandleScope scope;
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Cannot instantiate without new")));
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Cannot instantiate without new")));
|
||||
|
||||
Matrix *mat;
|
||||
Matrix *mat;
|
||||
|
||||
if (args.Length() == 0){
|
||||
mat = new Matrix;
|
||||
} else if (args.Length() == 2 && args[0]->IsInt32() && args[1]->IsInt32()){
|
||||
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||
}
|
||||
mat->Wrap(args.Holder());
|
||||
return scope.Close(args.Holder());
|
||||
if (args.Length() == 0){
|
||||
mat = new Matrix;
|
||||
} else if (args.Length() == 2 && args[0]->IsInt32() && args[1]->IsInt32()){
|
||||
mat = new Matrix(args[0]->IntegerValue(), args[1]->IntegerValue());
|
||||
} else if (args.Length() == 5) {
|
||||
Matrix *other = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
int x = args[1]->IntegerValue();
|
||||
int y = args[2]->IntegerValue();
|
||||
int w = args[3]->IntegerValue();
|
||||
int h = args[4]->IntegerValue();
|
||||
mat = new Matrix(other->mat, cv::Rect(x, y, w, h));
|
||||
}
|
||||
|
||||
mat->Wrap(args.Holder());
|
||||
return scope.Close(args.Holder());
|
||||
}
|
||||
|
||||
|
||||
Matrix::Matrix(): ObjectWrap() {
|
||||
mat = cv::Mat();
|
||||
mat = cv::Mat();
|
||||
}
|
||||
|
||||
|
||||
Matrix::Matrix(int w, int h): ObjectWrap() {
|
||||
mat = cv::Mat(w, h, CV_64FC1);
|
||||
mat = cv::Mat(w, h, CV_32FC3);
|
||||
//TODO:Parametrizar esto
|
||||
//mat = cv::Mat(h, w, CV_8UC3);
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Matrix(cv::Mat m, cv::Rect roi): ObjectWrap() {
|
||||
mat = cv::Mat(m, roi);
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Empty(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
return scope.Close(Boolean::New(self->mat.empty()));
|
||||
return scope.Close(Boolean::New(self->mat.empty()));
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
|
||||
|
||||
double
|
||||
Matrix::DblGet(cv::Mat mat, int i, int j){
|
||||
|
||||
double val = 0;
|
||||
cv::Vec3b pix;
|
||||
unsigned int pint = 0;
|
||||
|
||||
switch(mat.type()){
|
||||
case CV_32FC3:
|
||||
pix = mat.at<cv::Vec3b>(i, j);
|
||||
pint |= (uchar) pix.val[2];
|
||||
pint |= ((uchar) pix.val[1]) << 8;
|
||||
pint |= ((uchar) pix.val[0]) << 16;
|
||||
val = (double) pint;
|
||||
break;
|
||||
|
||||
case CV_64FC1:
|
||||
val = mat.at<double>(i, j);
|
||||
break;
|
||||
|
||||
default:
|
||||
val = mat.at<double>(i,j);
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Get(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
int i = args[0]->IntegerValue();
|
||||
int j = args[1]->IntegerValue();
|
||||
int i = args[0]->IntegerValue();
|
||||
int j = args[1]->IntegerValue();
|
||||
|
||||
return scope.Close(Number::New(self->mat.at<double>(i,j)));
|
||||
double val = Matrix::DblGet(self->mat, i, j);
|
||||
return scope.Close(Number::New(val));
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Set(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
int i = args[0]->IntegerValue();
|
||||
int j = args[1]->IntegerValue();
|
||||
double val = args[2]->NumberValue();
|
||||
int i = args[0]->IntegerValue();
|
||||
int j = args[1]->IntegerValue();
|
||||
double val = args[2]->NumberValue();
|
||||
int vint = 0;
|
||||
|
||||
self->mat.at<double>(i,j) = val;
|
||||
if(args.Length() == 4) {
|
||||
self->mat.at<cv::Vec3b>(i,j)[args[3]->NumberValue()] = val;
|
||||
|
||||
return scope.Close(Undefined());
|
||||
} else if(args.Length() == 3) {
|
||||
switch(self->mat.type()){
|
||||
|
||||
case CV_32FC3:
|
||||
vint = static_cast<unsigned int>(val + 0.5);
|
||||
self->mat.at<cv::Vec3b>(i,j)[0] = (uchar) (vint >> 16) & 0xff;
|
||||
self->mat.at<cv::Vec3b>(i,j)[1] = (uchar) (vint >> 8) & 0xff;
|
||||
self->mat.at<cv::Vec3b>(i,j)[2] = (uchar) (vint) & 0xff;
|
||||
//printf("!!!i %x, %x, %x", (vint >> 16) & 0xff, (vint >> 8) & 0xff, (vint) & 0xff);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
self->mat.at<double>(i,j) = val;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
return v8::ThrowException(v8::Exception::TypeError(String::New("Invalid number of arguments")));
|
||||
}
|
||||
|
||||
return scope.Close(Undefined());
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Size(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
v8::Local<v8::Array> arr = v8::Array::New(2);
|
||||
arr->Set(0, Number::New(self->mat.size().height));
|
||||
arr->Set(1, Number::New(self->mat.size().width));
|
||||
v8::Local<v8::Array> arr = v8::Array::New(2);
|
||||
arr->Set(0, Number::New(self->mat.size().height));
|
||||
arr->Set(1, Number::New(self->mat.size().width));
|
||||
|
||||
return scope.Close(arr);
|
||||
return scope.Close(arr);
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Row(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
int width = self->mat.size().width;
|
||||
int j = args[0]->IntegerValue();
|
||||
v8::Local<v8::Array> arr = v8::Array::New(width);
|
||||
int width = self->mat.size().width;
|
||||
int y = args[0]->IntegerValue();
|
||||
v8::Local<v8::Array> arr = v8::Array::New(width);
|
||||
|
||||
for (int i=0; i<width; i++){
|
||||
arr->Set(i, Number::New(self->mat.at<double>(i, j)));
|
||||
}
|
||||
return scope.Close(arr);
|
||||
for (int x=0; x<width; x++){
|
||||
double v = Matrix::DblGet(self->mat, y, x);
|
||||
arr->Set(x, Number::New(v));
|
||||
}
|
||||
|
||||
return scope.Close(arr);
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::PixelRow(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
int width = self->mat.size().width;
|
||||
int y = args[0]->IntegerValue();
|
||||
v8::Local<v8::Array> arr = v8::Array::New(width * 3);
|
||||
|
||||
for (int x=0; x<width; x++){
|
||||
cv::Vec3b pixel = self->mat.at<cv::Vec3b>(y, x);
|
||||
int offset = x * 3;
|
||||
arr->Set(offset , Number::New((double)pixel.val[0]));
|
||||
arr->Set(offset + 1, Number::New((double)pixel.val[1]));
|
||||
arr->Set(offset + 2, Number::New((double)pixel.val[2]));
|
||||
}
|
||||
|
||||
return scope.Close(arr);
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Col(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
int width = self->mat.size().width;
|
||||
int j = args[0]->IntegerValue();
|
||||
v8::Local<v8::Array> arr = v8::Array::New(width);
|
||||
int height = self->mat.size().height;
|
||||
int x = args[0]->IntegerValue();
|
||||
v8::Local<v8::Array> arr = v8::Array::New(height);
|
||||
|
||||
for (int i=0; i<width; i++){
|
||||
arr->Set(i, Number::New(self->mat.at<double>(j, i)));
|
||||
for (int y=0; y<height; y++){
|
||||
double v = Matrix::DblGet(self->mat, y, x);
|
||||
arr->Set(y, Number::New(v));
|
||||
}
|
||||
return scope.Close(arr);
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::PixelCol(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
int height = self->mat.size().height;
|
||||
int x = args[0]->IntegerValue();
|
||||
v8::Local<v8::Array> arr = v8::Array::New(height * 3);
|
||||
|
||||
for (int y=0; y<height; y++){
|
||||
cv::Vec3b pixel = self->mat.at<cv::Vec3b>(y, x);
|
||||
int offset = y * 3;
|
||||
arr->Set(offset , Number::New((double)pixel.val[0]));
|
||||
arr->Set(offset + 1, Number::New((double)pixel.val[1]));
|
||||
arr->Set(offset + 2, Number::New((double)pixel.val[2]));
|
||||
}
|
||||
return scope.Close(arr);
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Width(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
return scope.Close(Number::New(self->mat.size().width));
|
||||
return scope.Close(Number::New(self->mat.size().width));
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Height(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
return scope.Close(Number::New(self->mat.size().height));
|
||||
}
|
||||
return scope.Close(Number::New(self->mat.size().height));
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Channels(const Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
return scope.Close(Number::New(self->mat.channels()));
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::ToBuffer(const v8::Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
std::vector<uchar> vec(0);
|
||||
std::vector<int> params(0);//CV_IMWRITE_JPEG_QUALITY 90
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
cv::imencode(".jpg", self->mat, vec, params);
|
||||
std::vector<uchar> vec(0);
|
||||
std::vector<int> params(0);//CV_IMWRITE_JPEG_QUALITY 90
|
||||
|
||||
node::Buffer *buf = node::Buffer::New(vec.size());
|
||||
uchar* data = (uchar*) Buffer::Data(buf);
|
||||
memcpy(data, &vec[0], vec.size());
|
||||
cv::imencode(".jpg", self->mat, vec, params);
|
||||
|
||||
v8::Local<v8::Object> globalObj = v8::Context::GetCurrent()->Global();
|
||||
v8::Local<v8::Function> bufferConstructor = v8::Local<v8::Function>::Cast(globalObj->Get(v8::String::New("Buffer")));
|
||||
v8::Handle<v8::Value> constructorArgs[3] = {buf->handle_, v8::Integer::New(vec.size()), v8::Integer::New(0)};
|
||||
v8::Local<v8::Object> actualBuffer = bufferConstructor->NewInstance(3, constructorArgs);
|
||||
node::Buffer *buf = node::Buffer::New(vec.size());
|
||||
uchar* data = (uchar*) Buffer::Data(buf);
|
||||
memcpy(data, &vec[0], vec.size());
|
||||
|
||||
return scope.Close(actualBuffer);
|
||||
}
|
||||
v8::Local<v8::Object> globalObj = v8::Context::GetCurrent()->Global();
|
||||
v8::Local<v8::Function> bufferConstructor = v8::Local<v8::Function>::Cast(globalObj->Get(v8::String::New("Buffer")));
|
||||
v8::Handle<v8::Value> constructorArgs[3] = {buf->handle_, v8::Integer::New(vec.size()), v8::Integer::New(0)};
|
||||
v8::Local<v8::Object> actualBuffer = bufferConstructor->NewInstance(3, constructorArgs);
|
||||
|
||||
return scope.Close(actualBuffer);
|
||||
}
|
||||
|
||||
|
||||
// ellipse(x, y, wid, height, angle, startangle, endangle, color, thickness, linetype, shift)
|
||||
Handle<Value>
|
||||
Matrix::Ellipse(const v8::Arguments& args){
|
||||
SETUP_FUNCTION(Matrix)
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
int x = args[0]->Uint32Value();
|
||||
int y = args[1]->Uint32Value();
|
||||
int width = args[2]->Uint32Value();
|
||||
int height = args[3]->Uint32Value();
|
||||
int height = args[3]->Uint32Value();
|
||||
uint color = args[4]->Uint32Value();
|
||||
|
||||
cv::ellipse(self->mat, cv::Point(x, y), cv::Size(width, height), 0, 0, 360, cv::Scalar( 255, 0, 255 ), 4, 8, 0);
|
||||
cv::ellipse(self->mat, cv::Point(x, y), cv::Size(width, height), 0, 0, 360,
|
||||
cv::Scalar( (color >> 16) & 0xff , (color >> 8) & 0xff, color & 0xff ), 4, 8, 0);
|
||||
return scope.Close(v8::Null());
|
||||
}
|
||||
|
||||
|
||||
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::Line(const Arguments& args) {
|
||||
SETUP_FUNCTION(Matrix)
|
||||
|
||||
|
||||
if(args[0]->IsArray() && args[1]->IsArray()) {
|
||||
Local<Object> xy1 = args[0]->ToObject();
|
||||
Local<Object> xy2 = args[1]->ToObject();
|
||||
|
||||
cv::Scalar color(0, 0, 255);
|
||||
|
||||
if(args[2]->IsArray()) {
|
||||
Local<Object> objColor = args[2]->ToObject();
|
||||
color = setColor(objColor);
|
||||
}
|
||||
|
||||
int x1 = xy1->Get(0)->IntegerValue();
|
||||
int y1 = xy1->Get(1)->IntegerValue();
|
||||
|
||||
int x2 = xy2->Get(0)->IntegerValue();
|
||||
int y2 = xy2->Get(1)->IntegerValue();
|
||||
|
||||
int thickness = 1;
|
||||
|
||||
if(args[3]->IntegerValue())
|
||||
thickness = args[3]->IntegerValue();
|
||||
|
||||
cv::line(self->mat, cv::Point(x1, y1), cv::Point(x2, y2), color, thickness);
|
||||
}
|
||||
|
||||
return scope.Close(v8::Null());
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Save(const v8::Arguments& args){
|
||||
HandleScope scope;
|
||||
|
||||
if (!args[0]->IsString())
|
||||
return v8::ThrowException(v8::Exception::TypeError(String::New("filename required")));
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
String::AsciiValue filename(args[0]);
|
||||
int res = cv::imwrite(*filename, self->mat);
|
||||
return scope.Close(Number::New(res));
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Eye(const v8::Arguments& args){
|
||||
HandleScope scope;
|
||||
|
||||
int w = args[0]->Uint32Value();
|
||||
int h = args[1]->Uint32Value();
|
||||
|
||||
Local<Object> im_h = Matrix::constructor->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
|
||||
cv::Mat mat = cv::Mat::eye(w, h, CV_64FC1);
|
||||
|
||||
img->mat = mat;
|
||||
return scope.Close(im_h);
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Save(const v8::Arguments& args){
|
||||
Matrix::ConvertGrayscale(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
if(self->mat.channels() != 3)
|
||||
return v8::ThrowException(String::New("Image is no 3-channel"));
|
||||
|
||||
cv::Mat gray;
|
||||
|
||||
cv::cvtColor(self->mat, gray, CV_BGR2GRAY);
|
||||
gray.copyTo(self->mat);
|
||||
|
||||
|
||||
return scope.Close(v8::Null());
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::ConvertHSVscale(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
if(self->mat.channels() != 3)
|
||||
return v8::ThrowException(String::New("Image is no 3-channel"));
|
||||
|
||||
cv::Mat hsv;
|
||||
|
||||
cv::cvtColor(self->mat, hsv, CV_BGR2HSV);
|
||||
hsv.copyTo(self->mat);
|
||||
|
||||
return scope.Close(v8::Null());
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Copy(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
|
||||
Local<Object> img_to_return = Matrix::constructor->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(img_to_return);
|
||||
self->mat.copyTo(img->mat);
|
||||
|
||||
return scope.Close(img_to_return);
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Ptr(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
int line = args[0]->Uint32Value();
|
||||
|
||||
|
||||
char* data = self->mat.ptr<char>(line);
|
||||
//uchar* data = self->mat.data;
|
||||
|
||||
/*
|
||||
char *mydata = "Random raw data\0";
|
||||
*/
|
||||
node::Buffer *return_buffer = Buffer::New((char *)data, self->mat.step);
|
||||
return scope.Close( return_buffer->handle_ );
|
||||
|
||||
// return Undefined();
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::AddWeighted(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
|
||||
Matrix *src1 = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||
Matrix *src2 = ObjectWrap::Unwrap<Matrix>(args[2]->ToObject());
|
||||
|
||||
float alpha = args[1]->NumberValue();
|
||||
float beta = args[3]->NumberValue();
|
||||
int gamma = 0;
|
||||
|
||||
cv::addWeighted(src1->mat, alpha, src2->mat, beta, gamma, self->mat);
|
||||
|
||||
|
||||
return scope.Close(v8::Null());
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Split(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
//Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
|
||||
return scope.Close(v8::Null());
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Canny(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
int lowThresh = args[0]->NumberValue();
|
||||
int highThresh = args[1]->NumberValue();
|
||||
|
||||
cv::Canny(self->mat, self->mat, lowThresh, highThresh);
|
||||
|
||||
return scope.Close(v8::Null());
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Dilate(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
int niters = args[0]->NumberValue();
|
||||
|
||||
cv::dilate(self->mat, self->mat, cv::Mat(), cv::Point(-1, -1), niters);
|
||||
|
||||
return scope.Close(v8::Null());
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::FindContours(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
|
||||
Local<Object> conts_to_return= Contour::constructor->GetFunction()->NewInstance();
|
||||
Contour *contours = ObjectWrap::Unwrap<Contour>(conts_to_return);
|
||||
|
||||
cv::findContours(self->mat, contours->contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
|
||||
|
||||
return scope.Close(conts_to_return);
|
||||
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::DrawContour(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
Contour *cont = ObjectWrap::Unwrap<Contour>(args[0]->ToObject());
|
||||
int pos = args[1]->NumberValue();
|
||||
|
||||
cv::Scalar color(0, 0, 255);
|
||||
|
||||
if(args[2]->IsArray()) {
|
||||
Local<Object> objColor = args[2]->ToObject();
|
||||
color = setColor(objColor);
|
||||
}
|
||||
|
||||
cv::drawContours(self->mat, cont->contours, pos, color, 1);
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::DrawAllContours(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
Contour *cont = ObjectWrap::Unwrap<Contour>(args[0]->ToObject());
|
||||
|
||||
cv::Scalar color(0, 0, 255);
|
||||
|
||||
if(args[1]->IsArray()) {
|
||||
Local<Object> objColor = args[1]->ToObject();
|
||||
color = setColor(objColor);
|
||||
}
|
||||
|
||||
cv::drawContours(self->mat, cont->contours, -1, color, 1);
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::GoodFeaturesToTrack(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
std::vector<cv::Point2f> corners;
|
||||
|
||||
cv::Mat gray;
|
||||
|
||||
cvtColor(self->mat, gray, CV_BGR2GRAY);
|
||||
equalizeHist(gray, gray);
|
||||
|
||||
cv::goodFeaturesToTrack(gray, corners, 500, 0.01, 10);
|
||||
|
||||
v8::Local<v8::Array> arr = v8::Array::New(corners.size());
|
||||
|
||||
|
||||
for (unsigned int i=0; i<corners.size(); i++){
|
||||
v8::Local<v8::Array> pt = v8::Array::New(2);
|
||||
pt->Set(0, Number::New((double) corners[i].x));
|
||||
pt->Set(1, Number::New((double) corners[i].y));
|
||||
arr->Set(i, pt);
|
||||
}
|
||||
|
||||
return scope.Close(arr);
|
||||
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::HoughLinesP(const v8::Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
std::vector<cv::Vec4i> lines;
|
||||
|
||||
cv::Mat gray;
|
||||
|
||||
|
||||
equalizeHist(self->mat, gray);
|
||||
// cv::Canny(gray, gray, 50, 200, 3);
|
||||
cv::HoughLinesP(gray, lines, 1, CV_PI/180, 80, 30, 10);
|
||||
|
||||
v8::Local<v8::Array> arr = v8::Array::New(lines.size());
|
||||
|
||||
|
||||
for (unsigned int i=0; i<lines.size(); i++){
|
||||
v8::Local<v8::Array> pt = v8::Array::New(4);
|
||||
pt->Set(0, Number::New((double) lines[i][0]));
|
||||
pt->Set(1, Number::New((double) lines[i][1]));
|
||||
pt->Set(2, Number::New((double) lines[i][2]));
|
||||
pt->Set(3, Number::New((double) lines[i][3]));
|
||||
arr->Set(i, pt);
|
||||
}
|
||||
|
||||
return scope.Close(arr);
|
||||
|
||||
}
|
||||
|
||||
cv::Scalar setColor(Local<Object> objColor) {
|
||||
|
||||
Local<Value> valB = objColor->Get(0);
|
||||
Local<Value> valG = objColor->Get(1);
|
||||
Local<Value> valR = objColor->Get(2);
|
||||
|
||||
cv::Scalar color = cv::Scalar(valB->IntegerValue(), valG->IntegerValue(), valR->IntegerValue());
|
||||
return color;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Resize(const v8::Arguments& args){
|
||||
HandleScope scope;
|
||||
|
||||
if (!args[0]->IsString())
|
||||
return ThrowException(Exception::TypeError(String::New("filename required")));
|
||||
|
||||
int x = args[0]->Uint32Value();
|
||||
int y = args[1]->Uint32Value();
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
String::AsciiValue filename(args[0]);
|
||||
int res = cv::imwrite(*filename, self->mat);
|
||||
return scope.Close(Number::New(res));
|
||||
}
|
||||
|
||||
Handle<Value>
|
||||
Matrix::Eye(const v8::Arguments& args){
|
||||
HandleScope scope;
|
||||
|
||||
int w = args[0]->Uint32Value();
|
||||
int h = args[1]->Uint32Value();
|
||||
|
||||
Local<Object> im_h = Matrix::constructor->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
|
||||
cv::Mat mat = cv::Mat::eye(w, h, CV_64FC1);
|
||||
|
||||
img->mat = mat;
|
||||
return scope.Close(im_h);
|
||||
cv::Mat res = cv::Mat(x, y, CV_32FC3);
|
||||
cv::resize(self->mat, res, cv::Size(x, y), 0, 0, cv::INTER_LINEAR);
|
||||
~self->mat;
|
||||
self->mat = res;
|
||||
|
||||
|
||||
return scope.Close(Undefined());
|
||||
}
|
||||
|
||||
Arquivo normal → Arquivo executável
+41
-17
@@ -8,19 +8,56 @@ class Matrix: public node::ObjectWrap {
|
||||
static void Init(Handle<Object> target);
|
||||
static Handle<Value> New(const Arguments &args);
|
||||
Matrix();
|
||||
Matrix(cv::Mat other, cv::Rect roi);
|
||||
Matrix(int rows, int cols);
|
||||
Matrix(int rows, int cols, int typ);
|
||||
|
||||
static double DblGet(cv::Mat mat, int i, int j);
|
||||
|
||||
JSFUNC(Eye) // factory
|
||||
|
||||
JSFUNC(Get) // at
|
||||
JSFUNC(Set)
|
||||
|
||||
JSFUNC(Row)
|
||||
JSFUNC(PixelRow)
|
||||
JSFUNC(Col)
|
||||
JSFUNC(Eye) // factory
|
||||
JSFUNC(PixelCol)
|
||||
|
||||
JSFUNC(Size)
|
||||
JSFUNC(Width)
|
||||
JSFUNC(Height)
|
||||
JSFUNC(Channels)
|
||||
|
||||
JSFUNC(Ellipse)
|
||||
JSFUNC(Rectangle)
|
||||
JSFUNC(Line)
|
||||
JSFUNC(Empty)
|
||||
|
||||
JSFUNC(Save)
|
||||
JSFUNC(ToBuffer)
|
||||
|
||||
JSFUNC(Resize)
|
||||
|
||||
JSFUNC(ConvertGrayscale)
|
||||
JSFUNC(ConvertHSVscale)
|
||||
JSFUNC(Copy)
|
||||
JSFUNC(Ptr)
|
||||
JSFUNC(AddWeighted)
|
||||
JSFUNC(Split)
|
||||
JSFUNC(Canny)
|
||||
JSFUNC(Dilate)
|
||||
|
||||
JSFUNC(FindContours)
|
||||
JSFUNC(DrawContour)
|
||||
JSFUNC(DrawAllContours)
|
||||
|
||||
// Feature Detection
|
||||
JSFUNC(GoodFeaturesToTrack)
|
||||
JSFUNC(HoughLinesP)
|
||||
|
||||
/*
|
||||
static Handle<Value> Val(const Arguments& args);
|
||||
|
||||
|
||||
|
||||
static Handle<Value> RowRange(const Arguments& args);
|
||||
static Handle<Value> ColRange(const Arguments& args);
|
||||
static Handle<Value> Diag(const Arguments& args);
|
||||
@@ -37,9 +74,7 @@ class Matrix: public node::ObjectWrap {
|
||||
static Handle<Value> Dot(const Arguments& args);
|
||||
static Handle<Value> Zeroes(const Arguments& args);
|
||||
static Handle<Value> Ones(const Arguments& args);
|
||||
static Handle<Value> Eye(const Arguments& args);
|
||||
// create, increment, release
|
||||
static Handle<Value> Resize(const Arguments& args);
|
||||
static Handle<Value> PushBack(const Arguments& args);
|
||||
static Handle<Value> PopBack(const Arguments& args);
|
||||
static Handle<Value> LocateROI(const Arguments& args);
|
||||
@@ -54,16 +89,5 @@ class Matrix: public node::ObjectWrap {
|
||||
|
||||
*/
|
||||
|
||||
|
||||
JSFUNC(Get) // at
|
||||
JSFUNC(Set)
|
||||
JSFUNC(Size)
|
||||
JSFUNC(Width)
|
||||
JSFUNC(Height)
|
||||
JSFUNC(ToBuffer)
|
||||
JSFUNC(Ellipse)
|
||||
JSFUNC(Empty)
|
||||
JSFUNC(Save)
|
||||
|
||||
};
|
||||
|
||||
|
||||
Arquivo normal → Arquivo executável
+3
-3
@@ -39,7 +39,7 @@ OpenCV::ReadImage(const Arguments &args) {
|
||||
} else if (args[0]->IsString()) {
|
||||
|
||||
std::string filename = std::string(*v8::String::AsciiValue(args[0]->ToString()));
|
||||
mat = cv::imread(filename, -1);
|
||||
mat = cv::imread(filename);
|
||||
|
||||
} else if (Buffer::HasInstance(args[0])){
|
||||
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
|
||||
@@ -71,8 +71,8 @@ OpenCV::ReadImage(const Arguments &args) {
|
||||
return Undefined();
|
||||
|
||||
} catch( cv::Exception& e ){
|
||||
const char* err_msg = e.what();
|
||||
return v8::ThrowException(v8::Exception::Error(v8::String::New(err_msg)));
|
||||
const char* err_msg = e.what();
|
||||
return v8::ThrowException(v8::Exception::Error(v8::String::New(err_msg)));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Arquivo normal → Arquivo executável
+1
-1
@@ -15,7 +15,7 @@ using namespace node;
|
||||
|
||||
#define REQ_FUN_ARG(I, VAR) \
|
||||
if (args.Length() <= (I) || !args[I]->IsFunction()) \
|
||||
return ThrowException(Exception::TypeError( \
|
||||
return v8::ThrowException(v8::Exception::TypeError( \
|
||||
String::New("Argument " #I " must be a function"))); \
|
||||
Local<Function> VAR = Local<Function>::Cast(args[I]);
|
||||
|
||||
|
||||
Arquivo normal → Arquivo executável
+1
-1
@@ -70,4 +70,4 @@ Point::Dot(const v8::Arguments& args){
|
||||
|
||||
Point::Point(double x, double y): ObjectWrap() {
|
||||
point = cvPoint2D32f(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
Arquivo normal → Arquivo executável
+2
-1
@@ -15,4 +15,5 @@ class Point: public node::ObjectWrap {
|
||||
static void RaiseImmutable(Local<String> property, Local<Value> value, const AccessorInfo& info);
|
||||
static Handle<Value> Dot(const v8::Arguments&);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Arquivo normal → Arquivo executável
+82
-32
@@ -2,64 +2,114 @@
|
||||
#include "Matrix.h"
|
||||
#include "OpenCV.h"
|
||||
|
||||
|
||||
void AsyncRead(uv_work_t *req);
|
||||
void AfterAsyncRead(uv_work_t *req);
|
||||
|
||||
v8::Persistent<FunctionTemplate> VideoCaptureWrap::constructor;
|
||||
|
||||
struct videocapture_baton {
|
||||
|
||||
Persistent<Function> cb;
|
||||
VideoCaptureWrap *vc;
|
||||
Matrix *im;
|
||||
|
||||
uv_work_t request;
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
VideoCaptureWrap::Init(Handle<Object> target) {
|
||||
HandleScope scope;
|
||||
|
||||
// Constructor
|
||||
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(VideoCaptureWrap::New));
|
||||
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
constructor->SetClassName(String::NewSymbol("VideoCapture"));
|
||||
// Constructor
|
||||
constructor = Persistent<FunctionTemplate>::New(FunctionTemplate::New(VideoCaptureWrap::New));
|
||||
constructor->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
constructor->SetClassName(String::NewSymbol("VideoCapture"));
|
||||
|
||||
// Prototype
|
||||
Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "getFrame", GetFrame);
|
||||
// Prototype
|
||||
//Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
|
||||
|
||||
target->Set(String::NewSymbol("VideoCapture"), constructor->GetFunction());
|
||||
NODE_SET_PROTOTYPE_METHOD(constructor, "read", Read);
|
||||
|
||||
target->Set(String::NewSymbol("VideoCapture"), constructor->GetFunction());
|
||||
};
|
||||
|
||||
Handle<Value>
|
||||
VideoCaptureWrap::New(const Arguments &args) {
|
||||
HandleScope scope;
|
||||
HandleScope scope;
|
||||
|
||||
if (args.This()->InternalFieldCount() == 0)
|
||||
return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Cannot Instantiate without new")));
|
||||
return v8::ThrowException(v8::Exception::TypeError(v8::String::New("Cannot Instantiate without new")));
|
||||
|
||||
VideoCaptureWrap *v;
|
||||
VideoCaptureWrap *v;
|
||||
|
||||
if (args[0]->IsNumber()){
|
||||
v = new VideoCaptureWrap(args[0]->NumberValue());
|
||||
} else {}
|
||||
v->Wrap(args.This());
|
||||
return args.This();
|
||||
if (args[0]->IsNumber()){
|
||||
v = new VideoCaptureWrap(args[0]->NumberValue());
|
||||
} else {}
|
||||
|
||||
|
||||
v->Wrap(args.This());
|
||||
|
||||
return args.This();
|
||||
}
|
||||
|
||||
|
||||
VideoCaptureWrap::VideoCaptureWrap(int device){
|
||||
HandleScope scope;
|
||||
|
||||
cv::VideoCapture cap(device);
|
||||
HandleScope scope;
|
||||
cap.open(device);
|
||||
|
||||
if(!cap.isOpened()){
|
||||
ThrowException(Exception::Error(String::New("Camera could not be opened")));
|
||||
}
|
||||
if(!cap.isOpened()){
|
||||
v8::ThrowException(v8::Exception::Error(String::New("Camera could not be opened")));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Handle<Value>
|
||||
VideoCaptureWrap::GetFrame(const Arguments &args) {
|
||||
SETUP_FUNCTION(VideoCaptureWrap)
|
||||
VideoCaptureWrap::Read(const Arguments &args) {
|
||||
|
||||
cv::Mat frame;
|
||||
self->cap.retrieve(frame);
|
||||
HandleScope scope;
|
||||
VideoCaptureWrap *v = ObjectWrap::Unwrap<VideoCaptureWrap>(args.This());
|
||||
|
||||
REQ_FUN_ARG(0, cb);
|
||||
|
||||
videocapture_baton *baton = new videocapture_baton();
|
||||
baton->vc = v;
|
||||
baton->cb = Persistent<Function>::New(cb);
|
||||
baton->im = new Matrix();
|
||||
baton->request.data = baton;
|
||||
|
||||
uv_queue_work(uv_default_loop(), &baton->request, AsyncRead, AfterAsyncRead);
|
||||
return Undefined();
|
||||
|
||||
Local<Object> im_h = Matrix::constructor->GetFunction()->NewInstance();
|
||||
Matrix *im = ObjectWrap::Unwrap<Matrix>(im_h);
|
||||
im->mat = frame;
|
||||
return scope.Close(im_h);
|
||||
}
|
||||
|
||||
|
||||
void AsyncRead(uv_work_t *req) {
|
||||
videocapture_baton *baton = static_cast<videocapture_baton *>(req->data);
|
||||
|
||||
baton->vc->cap.read(baton->im->mat);
|
||||
}
|
||||
|
||||
|
||||
void AfterAsyncRead(uv_work_t *req) {
|
||||
|
||||
HandleScope scope;
|
||||
|
||||
videocapture_baton *baton = static_cast<videocapture_baton *>(req->data);
|
||||
|
||||
Local<Object> im_to_return= Matrix::constructor->GetFunction()->NewInstance();
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_to_return);
|
||||
cv::Mat mat;
|
||||
mat = baton->im->mat;
|
||||
|
||||
img->mat = mat;
|
||||
Local<Value> argv[1];
|
||||
|
||||
argv[0] = im_to_return;
|
||||
|
||||
baton->cb->Call(Context::GetCurrent()->Global(), 1, argv);
|
||||
baton->cb.Dispose();
|
||||
|
||||
delete baton;
|
||||
|
||||
}
|
||||
|
||||
Arquivo normal → Arquivo executável
+3
-1
@@ -11,7 +11,9 @@ class VideoCaptureWrap: public node::ObjectWrap {
|
||||
VideoCaptureWrap(const std::string& filename);
|
||||
VideoCaptureWrap(int device);
|
||||
|
||||
static Handle<Value> GetFrame(const v8::Arguments&);
|
||||
static Handle<Value> Read(const v8::Arguments&);
|
||||
|
||||
|
||||
static Handle<Value> GetFrameAt(const v8::Arguments&);
|
||||
|
||||
};
|
||||
|
||||
Arquivo normal → Arquivo executável
+4
@@ -3,6 +3,7 @@
|
||||
#include "Matrix.h"
|
||||
#include "CascadeClassifierWrap.h"
|
||||
#include "VideoCaptureWrap.h"
|
||||
#include "Contours.h"
|
||||
|
||||
|
||||
extern "C" void
|
||||
@@ -13,4 +14,7 @@ init(Handle<Object> target) {
|
||||
Matrix::Init(target);
|
||||
CascadeClassifierWrap::Init(target);
|
||||
VideoCaptureWrap::Init(target);
|
||||
Contour::Init(target);
|
||||
};
|
||||
|
||||
NODE_MODULE(opencv, init)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
var buf, cv;
|
||||
|
||||
cv = require('../lib/opencv');
|
||||
var fs = require('fs')
|
||||
|
||||
buf = fs.readFileSync('../examples/stuff.png')
|
||||
|
||||
var cb = function(){console.log("OK")}
|
||||
|
||||
cv.readImage(buf, function(err, im) {
|
||||
if (err != null) {
|
||||
return cb(err);
|
||||
}
|
||||
return im.detectObject("../data/haarcascade_frontalface_alt.xml", {}, function(err, faces) {
|
||||
if (err != null) {
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null, faces);
|
||||
});
|
||||
});
|
||||
|
||||
Arquivo normal → Arquivo executável
+27
-10
@@ -72,6 +72,14 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
assert.ok(new cv.Matrix);
|
||||
assert.ok(new cv.Matrix(1,2));
|
||||
}
|
||||
|
||||
, "set/row" : function(cv){
|
||||
var mat = new cv.Matrix(1, 2);
|
||||
mat.set(0,0,3)
|
||||
mat.set(0,1,5000)
|
||||
assert.deepEqual(mat.row(0), [3,5000]);
|
||||
}
|
||||
|
||||
, "get/set" : function(cv){
|
||||
var mat = new cv.Matrix(1,2);
|
||||
assert.equal(mat.set(0,0,3), undefined);
|
||||
@@ -93,6 +101,15 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
assert.deepEqual(mat.size(), [6, 7]);
|
||||
}
|
||||
|
||||
|
||||
, "resize" : function(cv){
|
||||
var mat = new cv.Matrix(6,7);
|
||||
assert.equal(mat.width(), 7);
|
||||
mat.resize(8,9);
|
||||
assert.equal(mat.width(), 8);
|
||||
|
||||
}
|
||||
|
||||
, 'row' : function(cv){
|
||||
var mat = new cv.Matrix.Eye(4,4)
|
||||
assertDeepSimilar(mat.row(1), [0,1,0,0])
|
||||
@@ -110,7 +127,7 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
}
|
||||
|
||||
, "toBuffer": function(cv){
|
||||
var buf = fs.readFileSync('./examples/mona.jpg')
|
||||
var buf = fs.readFileSync('./examples/mona.png')
|
||||
|
||||
cv.readImage(buf.slice(0), function(err, mat){
|
||||
var buf0 = mat.toBuffer()
|
||||
@@ -127,8 +144,8 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
var cv = require('../lib/opencv')
|
||||
, cb = this.callback
|
||||
|
||||
cv.readImage("./examples/mona.jpg", function(err, im){
|
||||
im.detectObject("./examples/haarcascade_frontalface_alt.xml", {}, cb)
|
||||
cv.readImage("./examples/mona.png", function(err, im){
|
||||
im.detectObject("./data/haarcascade_frontalface_alt.xml", {}, cb)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -148,7 +165,7 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
topic : require('../lib/opencv')
|
||||
|
||||
, ".readImage from file": function(cv){
|
||||
cv.readImage("./examples/mona.jpg", function(err, im){
|
||||
cv.readImage("./examples/mona.png", function(err, im){
|
||||
assert.ok(im);
|
||||
assert.equal(im.width(), 500);
|
||||
assert.equal(im.height(), 756)
|
||||
@@ -157,7 +174,7 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
}
|
||||
|
||||
, ".readImage from buffer" : function(cv){
|
||||
cv.readImage(fs.readFileSync('./examples/mona.jpg'), function(err, im){
|
||||
cv.readImage(fs.readFileSync('./examples/mona.png'), function(err, im){
|
||||
assert.ok(im);
|
||||
assert.equal(im.width(), 500);
|
||||
assert.equal(im.height(), 756)
|
||||
@@ -173,7 +190,7 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
topic : require('../lib/opencv')
|
||||
|
||||
, "constructor" : function(cv){
|
||||
assert.ok(new cv.CascadeClassifier("./examples/haarcascade_frontalface_alt.xml"))
|
||||
assert.ok(new cv.CascadeClassifier("./data/haarcascade_frontalface_alt.xml"))
|
||||
}
|
||||
|
||||
, "face detection": {
|
||||
@@ -181,8 +198,8 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
var cv = require('../lib/opencv')
|
||||
, self = this
|
||||
|
||||
cv.readImage("./examples/mona.jpg", function(err, im){
|
||||
cascade = new cv.CascadeClassifier("./examples/haarcascade_frontalface_alt.xml");
|
||||
cv.readImage("./examples/mona.png", function(err, im){
|
||||
cascade = new cv.CascadeClassifier("./data/haarcascade_frontalface_alt.xml");
|
||||
cascade.detectMultiScale(im, self.callback)//, 1.1, 2, [30, 30]);
|
||||
})
|
||||
|
||||
@@ -211,7 +228,7 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
assert.equal(im.empty(), false);
|
||||
self.callback()
|
||||
})
|
||||
fs.createReadStream('./examples/mona.jpg').pipe(s);
|
||||
fs.createReadStream('./examples/mona.png').pipe(s);
|
||||
}
|
||||
|
||||
, "loaded" : function(im){
|
||||
@@ -225,4 +242,4 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
|
||||
|
||||
|
||||
}).run();
|
||||
}).export(module);
|
||||
Arquivo executável
+45
@@ -0,0 +1,45 @@
|
||||
|
||||
im.calcHistograms(function(err, hist){})
|
||||
|
||||
im.calcHistograms(mask, function(err, hist){})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## Face recognition TODO
|
||||
|
||||
|
||||
// Load Database
|
||||
// TODO<
|
||||
|
||||
|
||||
|
||||
cv.loadImage('test.jpg', function(err, im){
|
||||
im.detectObject("front-face.xml", {}, function(err, faces){
|
||||
_.each(faces, function(v){
|
||||
|
||||
// TODO {
|
||||
|
||||
var section = im.slice(v.x, v.y, v.x + v.width, v.y + v.height);
|
||||
section.convertGrayscale()
|
||||
section.resize(WID, HEIGHT);
|
||||
section.equaliseHistogram();
|
||||
|
||||
// } TODO
|
||||
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-----
|
||||
|
||||
|
||||
http://www.athile.net/library/wiki/index.php?title=Library/V8/Tutorial#Wrapping_a_Javascript_function_as_a_std::function.3C.3E
|
||||
|
||||
https://www.cloudkick.com/blog/2010/aug/23/writing-nodejs-native-extensions/
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
def set_options(opt):
|
||||
opt.tool_options("compiler_cxx")
|
||||
|
||||
|
||||
def configure(conf):
|
||||
conf.check_tool('compiler_cxx')
|
||||
conf.check_tool('node_addon')
|
||||
#conf.check(lib='opencv', libpath=[
|
||||
# '/lib', '/usr/lib', '/usr/local/lib','/usr/local/include'], uselib_store='OPENCV', mandatory=True)
|
||||
conf.check_cfg(package='opencv', libpath=[
|
||||
'/lib', '/usr/lib', '/usr/local/lib','/usr/local/include'], args='--cflags --libs', uselib_store='OPENCV')
|
||||
|
||||
|
||||
def build(bld):
|
||||
obj = bld.new_task_gen("cxx", "shlib", "node_addon")
|
||||
obj.cxxflags = ["-g", "-D_FILE_OFFSET_BITS=64", "-D_LARGEFILE_SOURCE", "-Wall"]
|
||||
# This is the name of our extension.
|
||||
obj.target = "opencv"
|
||||
obj.source = bld.glob('src/*.cc')
|
||||
obj.uselib = ['OPENCV']
|
||||
Referência em uma Nova Issue
Bloquear um usuário