All examples now run without erroring

This commit is contained in:
Peter Braden 2014-10-15 20:42:44 +02:00
parent 9b3b82fbbe
commit 1659f7ef1a
5 changed files with 32 additions and 26 deletions

View File

@ -22,6 +22,7 @@ $ npm install opencv
```
## Examples
Run the examples from the parent directory.
### Face Detection

View File

@ -1,10 +1,10 @@
var cv = require('../lib/opencv');
cv.readImage("./files/car1.jpg", function(err, im){
cv.readImage("./examples/files/car1.jpg", function(err, im){
if (err) throw err;
if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size');
im.detectObject("../data/hogcascade_cars_sideview.xml", {}, function(err, cars){
im.detectObject("./data/hogcascade_cars_sideview.xml", {}, function(err, cars){
if (err) throw err;
for (var i=0; i < cars.length; i++){
@ -12,7 +12,7 @@ cv.readImage("./files/car1.jpg", function(err, im){
im.rectangle([x.x, x.y], [x.width, x.height]);
}
im.save('./tmp/car-detection.jpg');
console.log('Image saved to ./tmp/car-detection.jpg');
im.save('./examples/tmp/car-detection.jpg');
console.log('Image saved to ./examples/tmp/car-detection.jpg');
});
});

View File

@ -4,11 +4,11 @@ var cv = require('../lib/opencv');
var lower_threshold = [46, 57, 83];
var upper_threshold = [80, 96, 115];
cv.readImage('./files/coin1.jpg', function(err, im) {
cv.readImage('./examples/files/coin1.jpg', function(err, im) {
if (err) throw err;
if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size');
im.inRange(lower_threshold, upper_threshold);
im.save('./tmp/coin_detected.jpg');
im.save('./examples/tmp/coin_detected.jpg');
console.log('Image saved to ./tmp/coin_detected.jpg');
});

View File

@ -9,7 +9,7 @@ var GREEN = [0, 255, 0]; // B, G, R
var WHITE = [255, 255, 255]; // B, G, R
var RED = [0, 0, 255]; // B, G, R
cv.readImage('./files/stuff.png', function(err, im) {
cv.readImage('./examples/files/stuff.png', function(err, im) {
if (err) throw err;
var width = im.width();
var height = im.height();
@ -39,7 +39,7 @@ cv.readImage('./files/stuff.png', function(err, im) {
all.drawAllContours(contours, WHITE);
big.save('./tmp/big.png');
all.save('./tmp/all.png');
console.log('Image saved to ./tmp/big.png && ./tmp/all.png');
big.save('./examples/tmp/big.png');
all.save('./examples/tmp/all.png');
console.log('Image saved to ./examples/tmp/big.png && ./tmp/all.png');
});

View File

@ -4,21 +4,26 @@ var vid = new cv.VideoCapture(0);
vid.read(function(err, im){
if (err) throw err;
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
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];
var ims = im.size();
var im2 = im.roi(face.x, face.y, face.width, face.height)
/*
im.adjustROI(
-face.y
, (face.y + face.height) - ims[0]
, -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');
})
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
if (err) throw err;
if (!faces.length) return console.log("No Faces");
var face = faces[0];
var ims = im.size();
var im2 = im.roi(face.x, face.y, face.width, face.height)
/*
im.adjustROI(
-face.y
, (face.y + face.height) - ims[0]
, -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")
}
});