From 6391cf0dc89380740d4b647cddedec77cee96574 Mon Sep 17 00:00:00 2001 From: Marc Bachmann Date: Sat, 4 Oct 2014 17:55:17 +0200 Subject: [PATCH] Reuse size variables, add missing var. --- examples/contours.js | 8 +++++--- examples/convert-image.js | 3 --- examples/salt.js | 11 +++++++---- examples/warp-image.js | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/contours.js b/examples/contours.js index 0a8ac96..43bb0ac 100755 --- a/examples/contours.js +++ b/examples/contours.js @@ -11,10 +11,12 @@ var RED = [0, 0, 255]; // B, G, R cv.readImage('./files/stuff.png', function(err, im) { if (err) throw err; - if (im.width() < 1 || im.height() < 1) throw new Error('Image has no size'); + var width = im.width(); + var height = im.height(); + if (width < 1 || height < 1) throw new Error('Image has no size'); - var big = new cv.Matrix(im.height(), im.width()); - var all = new cv.Matrix(im.height(), im.width()); + var big = new cv.Matrix(height, width); + var all = new cv.Matrix(height, width); im.convertGrayscale(); im_canny = im.copy(); diff --git a/examples/convert-image.js b/examples/convert-image.js index f7bdaeb..7f62ff3 100755 --- a/examples/convert-image.js +++ b/examples/convert-image.js @@ -7,12 +7,9 @@ cv.readImage('./files/mona.png', function(err, im) { img_hsv = im.copy(); img_gray = im.copy(); - img_hsv.convertHSVscale(); img_gray.convertGrayscale(); - console.log(img_gray.pixel(100,100)); - im.save('./tmp/nor.png'); img_hsv.save('./tmp/hsv.png'); img_gray.save('./tmp/gray.png'); diff --git a/examples/salt.js b/examples/salt.js index 49f19b5..d3212b2 100755 --- a/examples/salt.js +++ b/examples/salt.js @@ -1,17 +1,20 @@ var cv = require('../lib/opencv'); cv.readImage("./files/mona.png", function(err, im) { - salt(im, 3000); + salt(im, 1000); im.save("./tmp/salt.png"); console.log('Image saved to ./tmp/salt.png'); }); function salt(img, n) { - if ((var channels img.channels()) != 3) return console.log('Image has only %s Channel. It\'s not possible to salt this image.', channels) + var channels; + if ((channels = img.channels()) != 3) return console.log('Image has only %s Channel. It\'s not possible to salt this image.', channels) + var width = img.width(); + var height = img.height(); for(var i = 0; i < n; i ++) { - x = Math.random() * img.width(); - y = Math.random() * img.height(); + x = Math.random() * width; + y = Math.random() * height; img.set(y, x, 255); } } diff --git a/examples/warp-image.js b/examples/warp-image.js index 9f4dda2..5b6d32d 100644 --- a/examples/warp-image.js +++ b/examples/warp-image.js @@ -3,8 +3,8 @@ var cv = require('../lib/opencv'); cv.readImage("./mona.png", function(err, im) { if (err) throw err; - width = im.width(); - height = im.height(); + var width = im.width(); + var height = im.height(); if (width < 1 || height < 1) throw new Error('Image has no size'); var srcArray = [0, 0, width, 0, width, height, 0, height];