diff --git a/examples/car-detection.js b/examples/car-detection.js index 95a5afa..58c2d61 100644 --- a/examples/car-detection.js +++ b/examples/car-detection.js @@ -1,10 +1,10 @@ var cv = require('../lib/opencv'); -cv.readImage("./examples/files/car1.jpg", function(err, im){ +cv.readImage("./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("./examples/files/car1.jpg", function(err, im){ im.rectangle([x.x, x.y], [x.width, x.height]); } - im.save('./examples/tmp/car-detection.jpg'); - console.log('Image saved to ./examples/tmp/car-detection.jpg'); + im.save('./tmp/car-detection.jpg'); + console.log('Image saved to ./tmp/car-detection.jpg'); }); }); diff --git a/examples/color-filter.js b/examples/color-filter.js index 031b65d..b7c5d6a 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('./examples/files/coin1.jpg', function(err, im) { +cv.readImage('./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('./examples/tmp/coin_detected.jpg'); + im.save('./tmp/coin_detected.jpg'); console.log('Image saved to ./tmp/coin_detected.jpg'); }); diff --git a/examples/contours.js b/examples/contours.js index 842011e..43bb0ac 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('./examples/files/stuff.png', function(err, im) { +cv.readImage('./files/stuff.png', function(err, im) { if (err) throw err; var width = im.width(); var height = im.height(); @@ -39,7 +39,7 @@ cv.readImage('./examples/files/stuff.png', function(err, im) { all.drawAllContours(contours, WHITE); - big.save('./examples/tmp/big.png'); - all.save('./examples/tmp/all.png'); - console.log('Image saved to ./examples/tmp/big.png && ./tmp/all.png'); + big.save('./tmp/big.png'); + all.save('./tmp/all.png'); + console.log('Image saved to ./tmp/big.png && ./tmp/all.png'); }); diff --git a/examples/convert-image.js b/examples/convert-image.js index dbc9f0c..7f62ff3 100755 --- a/examples/convert-image.js +++ b/examples/convert-image.js @@ -1,6 +1,6 @@ var cv = require('../lib/opencv'); -cv.readImage('./examples/files/mona.png', function(err, im) { +cv.readImage('./files/mona.png', function(err, im) { if (err) throw err; if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size'); @@ -10,12 +10,12 @@ cv.readImage('./examples/files/mona.png', function(err, im) { img_hsv.convertHSVscale(); img_gray.convertGrayscale(); - im.save('./examples/tmp/nor.png'); - img_hsv.save('./examples/tmp/hsv.png'); - img_gray.save('./examples/tmp/gray.png'); + im.save('./tmp/nor.png'); + img_hsv.save('./tmp/hsv.png'); + img_gray.save('./tmp/gray.png'); img_crop = im.crop(50,50,250,250); - img_crop.save('./examples/tmp/crop.png'); + img_crop.save('./tmp/crop.png'); - console.log('Image saved to ./examples/tmp/{crop|nor|hsv|gray}.png'); + console.log('Image saved to ./tmp/{crop|nor|hsv|gray}.png'); }); diff --git a/examples/detect-shapes.js b/examples/detect-shapes.js index 6326995..f465d23 100755 --- a/examples/detect-shapes.js +++ b/examples/detect-shapes.js @@ -12,7 +12,7 @@ var GREEN = [0, 255, 0]; // B, G, R var WHITE = [255, 255, 255]; // B, G, R -cv.readImage('./examples/files/shapes.jpg', function(err, im) { +cv.readImage('./files/shapes.jpg', function(err, im) { if (err) throw err; width = im.width() @@ -46,6 +46,6 @@ cv.readImage('./examples/files/shapes.jpg', function(err, im) { } } - out.save('./examples/tmp/detect-shapes.png'); - console.log('Image saved to ./examples/tmp/detect-shapes.png'); + out.save('./tmp/detect-shapes.png'); + console.log('Image saved to ./tmp/detect-shapes.png'); }); diff --git a/examples/face-detection-rectangle.js b/examples/face-detection-rectangle.js index e2d4f87..f108eee 100755 --- a/examples/face-detection-rectangle.js +++ b/examples/face-detection-rectangle.js @@ -3,11 +3,11 @@ var cv = require('../lib/opencv'); var COLOR = [0, 255, 0]; // default red var thickness = 2; // default 1 -cv.readImage('./examples/files/mona.png', function(err, im) { +cv.readImage('./files/mona.png', function(err, im) { if (err) throw err; if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size'); - im.detectObject('./data/haarcascade_frontalface_alt2.xml', {}, function(err, faces) { + im.detectObject('../data/haarcascade_frontalface_alt2.xml', {}, function(err, faces) { if (err) throw err; for (var i = 0; i < faces.length; i++) { @@ -15,8 +15,8 @@ cv.readImage('./examples/files/mona.png', function(err, im) { im.rectangle([face.x, face.y], [face.x + face.width, face.y + face.height], COLOR, 2); } - im.save('./examples/tmp/face-detection-rectangle.png'); - console.log('Image saved to ./examples/tmp/face-detection-rectangle.png'); + im.save('./tmp/face-detection-rectangle.png'); + console.log('Image saved to ./tmp/face-detection-rectangle.png'); }); }); diff --git a/examples/face-detection.js b/examples/face-detection.js index 185a78b..0cc5fee 100755 --- a/examples/face-detection.js +++ b/examples/face-detection.js @@ -1,10 +1,10 @@ var cv = require('../lib/opencv'); -cv.readImage("./examples/files/mona.png", function(err, im){ +cv.readImage("./files/mona.png", function(err, im){ if (err) throw err; if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size'); - im.detectObject("./data/haarcascade_frontalface_alt.xml", {}, function(err, faces){ + im.detectObject("../data/haarcascade_frontalface_alt.xml", {}, function(err, faces){ if (err) throw err; for (var i = 0; i < faces.length; i++){ @@ -12,7 +12,7 @@ cv.readImage("./examples/files/mona.png", function(err, im){ im.ellipse(face.x + face.width / 2, face.y + face.height / 2, face.width / 2, face.height / 2); } - im.save('./examples/tmp/face-detection.png'); - console.log('Image saved to ./examples/tmp/face-detection.png'); + im.save('./tmp/face-detection.png'); + console.log('Image saved to ./tmp/face-detection.png'); }); }); diff --git a/examples/quad-crosses.js b/examples/quad-crosses.js index 1a3a558..341631f 100755 --- a/examples/quad-crosses.js +++ b/examples/quad-crosses.js @@ -12,7 +12,7 @@ var RED = [0, 0, 255]; //B, G, R var GREEN = [0, 255, 0]; //B, G, R var WHITE = [255, 255, 255]; //B, G, R -cv.readImage('./examples/files/quads.jpg', function(err, im) { +cv.readImage('./files/quads.jpg', function(err, im) { if (err) throw err; if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size'); @@ -47,6 +47,6 @@ cv.readImage('./examples/files/quads.jpg', function(err, im) { out.line([points[1].x,points[1].y], [points[3].x, points[3].y], RED); } - out.save('./examples/tmp/quad-crosses.png'); - console.log('Image saved to ./examples/tmp/quad-crosses.png'); + out.save('./tmp/quad-crosses.png'); + console.log('Image saved to ./tmp/quad-crosses.png'); }); diff --git a/examples/salt.js b/examples/salt.js index d3212b2..737e834 100755 --- a/examples/salt.js +++ b/examples/salt.js @@ -1,7 +1,7 @@ var cv = require('../lib/opencv'); cv.readImage("./files/mona.png", function(err, im) { - salt(im, 1000); + salt(im, 100); im.save("./tmp/salt.png"); console.log('Image saved to ./tmp/salt.png'); }); diff --git a/examples/warp-image.js b/examples/warp-image.js index bcf13b8..8549bf9 100644 --- a/examples/warp-image.js +++ b/examples/warp-image.js @@ -1,6 +1,6 @@ var cv = require('../lib/opencv'); -cv.readImage("./examples/files/mona.png", function(err, im) { +cv.readImage("./files/mona.png", function(err, im) { if (err) throw err; var width = im.width(); @@ -11,6 +11,6 @@ cv.readImage("./examples/files/mona.png", function(err, im) { var dstArray = [0, 0, width * 0.9, height * 0.1, width, height, width * 0.2, height * 0.8]; var xfrmMat = im.getPerspectiveTransform(srcArray, dstArray); im.warpPerspective(xfrmMat, width, height, [255, 255, 255]); - im.save("./examples/tmp/warp-image.png"); + im.save("./tmp/warp-image.png"); console.log('Image saved to ./tmp/warp-image.png'); }); diff --git a/test/examples.js b/test/examples.js index b48a743..23f0f14 100644 --- a/test/examples.js +++ b/test/examples.js @@ -1,12 +1,17 @@ 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){ - exec('node ' + example, function(error, stdout, stderr){ + + var fullName = path.resolve(example) + , examples = path.resolve('./examples') + + exec('node ' + fullName, {cwd: examples}, function(error, stdout, stderr){ assert.error(error) assert.end() })