Reuse size variables, add missing var.

This commit is contained in:
Marc Bachmann 2014-10-04 17:55:17 +02:00
parent 950373579b
commit 6391cf0dc8
4 changed files with 14 additions and 12 deletions

View File

@ -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();

View File

@ -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');

View File

@ -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);
}
}

View File

@ -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];