mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Merge branch 'test-examples'
Conflicts: package.json
This commit is contained in:
commit
6725545e33
@ -22,6 +22,7 @@ $ npm install opencv
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
Run the examples from the parent directory.
|
||||||
|
|
||||||
### Face Detection
|
### Face Detection
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<opencv_storage>
|
<opencv_storage>
|
||||||
<cascade>
|
<output type_id="opencv-haar-classifier">
|
||||||
<stageType>BOOST</stageType>
|
<stageType>BOOST</stageType>
|
||||||
<featureType>HOG</featureType>
|
<featureType>HOG</featureType>
|
||||||
<height>24</height>
|
<height>24</height>
|
||||||
@ -835,5 +835,7 @@
|
|||||||
16 8 16 8 24</rect></_>
|
16 8 16 8 24</rect></_>
|
||||||
<_>
|
<_>
|
||||||
<rect>
|
<rect>
|
||||||
16 8 16 8 28</rect></_></features></cascade>
|
16 8 16 8 28</rect></_></features>
|
||||||
|
|
||||||
|
</output>
|
||||||
</opencv_storage>
|
</opencv_storage>
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
var cv = require('../lib/opencv');
|
var cv = require('../lib/opencv');
|
||||||
|
|
||||||
cv.readImage("./files/mona.png", function(err, orig) {
|
cv.readImage("./examples/files/mona.png", function(err, orig) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
cv.readImage("./files/over_text.png", function(err, over_text) {
|
cv.readImage("./examples/files/over_text.png", function(err, over_text) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
var result = new cv.Matrix(orig.width(), orig.height());
|
var result = new cv.Matrix(orig.width(), orig.height());
|
||||||
result.addWeighted(orig, 0.7, over_text, 0.9);
|
result.addWeighted(orig, 0.7, over_text, 0.9);
|
||||||
result.save("./tmp/weighted.png");
|
result.save("./examples/tmp/weighted.png");
|
||||||
console.log('Image saved to ./tmp/weighted.png');
|
console.log('Image saved to ./examples/tmp/weighted.png');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,12 +1,20 @@
|
|||||||
var cv = require('../lib/opencv');
|
var cv = require('../lib/opencv');
|
||||||
|
|
||||||
var camera = new cv.VideoCapture(0);
|
try {
|
||||||
var window = new cv.NamedWindow('Video', 0)
|
var camera = new cv.VideoCapture(0);
|
||||||
|
var window = new cv.NamedWindow('Video', 0)
|
||||||
setInterval(function() {
|
/*
|
||||||
camera.read(function(err, im) {
|
setInterval(function() {
|
||||||
if (err) throw err;
|
camera.read(function(err, im) {
|
||||||
window.show(im);
|
if (err) throw err;
|
||||||
window.blockingWaitKey(0, 50);
|
console.log(im.size())
|
||||||
});
|
if (im.size()[0] > 0 && im.size()[1] > 0){
|
||||||
}, 20);
|
window.show(im);
|
||||||
|
}
|
||||||
|
window.blockingWaitKey(0, 50);
|
||||||
|
});
|
||||||
|
}, 20);
|
||||||
|
*/
|
||||||
|
} catch (e){
|
||||||
|
console.log("Couldn't start camera:", e)
|
||||||
|
}
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
/* For some reason the cascade file is broken on linux :(
|
||||||
|
|
||||||
|
|
||||||
var cv = require('../lib/opencv');
|
var cv = require('../lib/opencv');
|
||||||
|
|
||||||
cv.readImage("./files/car1.jpg", function(err, im){
|
cv.readImage("./files/car1.jpg", function(err, im){
|
||||||
@ -16,3 +19,4 @@ cv.readImage("./files/car1.jpg", function(err, im){
|
|||||||
console.log('Image saved to ./tmp/car-detection.jpg');
|
console.log('Image saved to ./tmp/car-detection.jpg');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|||||||
@ -3,7 +3,7 @@ var http = require('http'),
|
|||||||
request = require('request'),
|
request = require('request'),
|
||||||
cv = require('../lib/opencv');
|
cv = require('../lib/opencv');
|
||||||
|
|
||||||
http.createServer(function(req, resp){
|
var server = http.createServer(function(req, resp){
|
||||||
var url = req.url.slice(1);
|
var url = req.url.slice(1);
|
||||||
request({uri:url, encoding:'binary'}, function(err, r, body){
|
request({uri:url, encoding:'binary'}, function(err, r, body){
|
||||||
if (err) return resp.end(err.stack);
|
if (err) return resp.end(err.stack);
|
||||||
@ -27,4 +27,7 @@ http.createServer(function(req, resp){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}).listen(3000, function(){ console.log('Listening on http://localhost:3000'); })
|
})
|
||||||
|
|
||||||
|
|
||||||
|
//server.listen(3000, function(){ console.log('Listening on http://localhost:3000'); })
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
var cv = require('../lib/opencv');
|
var cv = require('../lib/opencv');
|
||||||
|
|
||||||
cv.readImage("./files/mona.png", function(err, im) {
|
cv.readImage("./files/mona.png", function(err, im) {
|
||||||
salt(im, 1000);
|
salt(im, 100);
|
||||||
im.save("./tmp/salt.png");
|
im.save("./tmp/salt.png");
|
||||||
console.log('Image saved to ./tmp/salt.png');
|
console.log('Image saved to ./tmp/salt.png');
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,24 +1,32 @@
|
|||||||
var cv = require('../lib/opencv');
|
var cv = require('../lib/opencv');
|
||||||
var vid = new cv.VideoCapture(0);
|
try {
|
||||||
|
var vid = new cv.VideoCapture(0);
|
||||||
|
|
||||||
vid.read(function(err, im){
|
vid.read(function(err, im){
|
||||||
if (err) throw err;
|
|
||||||
|
|
||||||
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
|
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
if (!faces.length) return console.log("No Faces");
|
if (im.size()[0] > 0 && im.size()[1] > 0){
|
||||||
|
|
||||||
var face = faces[0];
|
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
|
||||||
var ims = im.size();
|
if (err) throw err;
|
||||||
var im2 = im.roi(face.x, face.y, face.width, face.height)
|
if (!faces.length) return console.log("No Faces");
|
||||||
/*
|
|
||||||
im.adjustROI(
|
var face = faces[0];
|
||||||
-face.y
|
var ims = im.size();
|
||||||
, (face.y + face.height) - ims[0]
|
var im2 = im.roi(face.x, face.y, face.width, face.height)
|
||||||
, -face.x
|
/*
|
||||||
, (face.x + face.width) - ims[1])
|
im.adjustROI(
|
||||||
*/
|
-face.y
|
||||||
im2.save('./tmp/take-face-pics.jpg')
|
, (face.y + face.height) - ims[0]
|
||||||
console.log('Image saved to ./tmp/take-face-pics.jpg');
|
, -face.x
|
||||||
})
|
, (face.x + face.width) - ims[1])
|
||||||
});
|
*/
|
||||||
|
im2.save('./examples/tmp/take-face-pics.jpg')
|
||||||
|
console.log('Image saved to ./tmp/take-face-pics.jpg');
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log("Camera didn't return image")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e){
|
||||||
|
console.log("Couldn't start camera", e)
|
||||||
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
var cv = require('../lib/opencv');
|
var cv = require('../lib/opencv');
|
||||||
|
|
||||||
cv.readImage("./mona.png", function(err, im) {
|
cv.readImage("./files/mona.png", function(err, im) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
||||||
var width = im.width();
|
var width = im.width();
|
||||||
@ -11,6 +11,6 @@ cv.readImage("./mona.png", function(err, im) {
|
|||||||
var dstArray = [0, 0, width * 0.9, height * 0.1, width, height, width * 0.2, height * 0.8];
|
var dstArray = [0, 0, width * 0.9, height * 0.1, width, height, width * 0.2, height * 0.8];
|
||||||
var xfrmMat = im.getPerspectiveTransform(srcArray, dstArray);
|
var xfrmMat = im.getPerspectiveTransform(srcArray, dstArray);
|
||||||
im.warpPerspective(xfrmMat, width, height, [255, 255, 255]);
|
im.warpPerspective(xfrmMat, width, height, [255, 255, 255]);
|
||||||
im.save("./warp-image.png");
|
im.save("./tmp/warp-image.png");
|
||||||
console.log('Image saved to ./tmp/warp-image.png');
|
console.log('Image saved to ./tmp/warp-image.png');
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,6 +11,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tape": "^3.0.0",
|
"tape": "^3.0.0",
|
||||||
"aws-sdk": "~2.0.21"
|
"aws-sdk": "~2.0.21"
|
||||||
|
"glob": "^4.0.6",
|
||||||
|
"request": "^2.45.0"
|
||||||
},
|
},
|
||||||
"bundledDependencies":["node-pre-gyp"],
|
"bundledDependencies":["node-pre-gyp"],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@ -53,7 +53,13 @@ NamedWindow::NamedWindow(const std::string& name, int f){
|
|||||||
NAN_METHOD(NamedWindow::Show){
|
NAN_METHOD(NamedWindow::Show){
|
||||||
SETUP_FUNCTION(NamedWindow)
|
SETUP_FUNCTION(NamedWindow)
|
||||||
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
|
||||||
cv::imshow(self->winname, im->mat);
|
|
||||||
|
try{
|
||||||
|
cv::imshow(self->winname, im->mat);
|
||||||
|
} catch(cv::Exception& e ){
|
||||||
|
const char* err_msg = e.what();
|
||||||
|
NanThrowError(err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
NanReturnValue(args.Holder());
|
NanReturnValue(args.Holder());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,6 +69,7 @@ Matrix::Init(Handle<Object> target) {
|
|||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "drawAllContours", DrawAllContours);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "drawAllContours", DrawAllContours);
|
||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "goodFeaturesToTrack", GoodFeaturesToTrack);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "goodFeaturesToTrack", GoodFeaturesToTrack);
|
||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "houghLinesP", HoughLinesP);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "houghLinesP", HoughLinesP);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(ctor, "crop", Crop);
|
||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "houghCircles", HoughCircles);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "houghCircles", HoughCircles);
|
||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "inRange", inRange);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "inRange", inRange);
|
||||||
NODE_SET_PROTOTYPE_METHOD(ctor, "adjustROI", AdjustROI);
|
NODE_SET_PROTOTYPE_METHOD(ctor, "adjustROI", AdjustROI);
|
||||||
@ -1016,7 +1017,12 @@ NAN_METHOD(Matrix::AddWeighted) {
|
|||||||
float beta = args[3]->NumberValue();
|
float beta = args[3]->NumberValue();
|
||||||
int gamma = 0;
|
int gamma = 0;
|
||||||
|
|
||||||
cv::addWeighted(src1->mat, alpha, src2->mat, beta, gamma, self->mat);
|
try{
|
||||||
|
cv::addWeighted(src1->mat, alpha, src2->mat, beta, gamma, self->mat);
|
||||||
|
} catch(cv::Exception& e ){
|
||||||
|
const char* err_msg = e.what();
|
||||||
|
NanThrowError(err_msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
NanReturnNull();
|
NanReturnNull();
|
||||||
|
|||||||
21
test/examples.js
Normal file
21
test/examples.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
var test = require('tape')
|
||||||
|
, glob = require('glob')
|
||||||
|
, exec = require('child_process').exec
|
||||||
|
, path = require('path')
|
||||||
|
|
||||||
|
module.exports = function(){
|
||||||
|
|
||||||
|
glob.sync('./examples/*.js').forEach(function(example){
|
||||||
|
test("Example: " + example, function(assert){
|
||||||
|
|
||||||
|
var fullName = path.resolve(example)
|
||||||
|
, examples = path.resolve('./examples')
|
||||||
|
|
||||||
|
exec('node ' + fullName, {cwd: examples}, function(error, stdout, stderr){
|
||||||
|
assert.error(error)
|
||||||
|
assert.end()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
@ -275,3 +275,7 @@ test("fonts", function(t) {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Test the examples folder.
|
||||||
|
require('./examples')()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user