From 1659f7ef1aa36e685f317826ad4e1846127327fa Mon Sep 17 00:00:00 2001 From: Peter Braden Date: Wed, 15 Oct 2014 20:42:44 +0200 Subject: [PATCH] All examples now run without erroring --- README.md | 1 + examples/car-detection.js | 8 ++++---- examples/color-filter.js | 4 ++-- examples/contours.js | 8 ++++---- examples/take-face-pics.js | 37 +++++++++++++++++++++---------------- 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 8060758..babcb83 100755 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ $ npm install opencv ``` ## Examples +Run the examples from the parent directory. ### Face Detection diff --git a/examples/car-detection.js b/examples/car-detection.js index 58c2d61..95a5afa 100644 --- a/examples/car-detection.js +++ b/examples/car-detection.js @@ -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'); }); }); diff --git a/examples/color-filter.js b/examples/color-filter.js index b7c5d6a..031b65d 100644 --- a/examples/color-filter.js +++ b/examples/color-filter.js @@ -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'); }); diff --git a/examples/contours.js b/examples/contours.js index 43bb0ac..842011e 100755 --- a/examples/contours.js +++ b/examples/contours.js @@ -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'); }); diff --git a/examples/take-face-pics.js b/examples/take-face-pics.js index 36e8831..2c61ebe 100644 --- a/examples/take-face-pics.js +++ b/examples/take-face-pics.js @@ -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") + } });