harthur / kittydar

Face detection for cats in JavaScript - demo for TXJS 2012 talk
http://harthur.github.com/kittydar
MIT License
1.42k stars 172 forks source link

TypeError: Image or Canvas expected #20

Open rainer-maucher opened 10 years ago

rainer-maucher commented 10 years ago

Hi by executing: node test.js on a raspberry Pi with kittydar 1.6

where test.js contains the following JS:

var http = require('http'), fs = require('fs'), Canvas = require('canvas'); kittyDar = require('kittydar');

fs.readFile('/var/www/kittenpush/web/images/userData/kittenimage.jpg', function(err, squid){ if (err) throw err;

img = new Canvas.Image; img.src = squid;

var canvas = new Canvas(img.width, img.height); var ctxxxx = canvas.getContext('2d'); ctxxxx.drawImage(img, 0, 0, img.width, img.height,0,0,img.width,img.height);

console.log(canvas); var cats = kittyDar.detectCats(canvas); console.log("there are", cats.length, "cats in this photo"); });

I'm ending up with an error insite the kittydar:

[Canvas 1600x1200]

/home/pi/node_modules/kittydar/kittydar.js:151 ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, ^ TypeError: Image or Canvas expected at resizeCanvas (/home/pi/node_modules/kittydar/kittydar.js:151:7) at Object.kittydar.scaleCanvas (/home/pi/node_modules/kittydar/kittydar.js:96:14) at Object.kittydar.getAllSizes (/home/pi/node_modules/kittydar/kittydar.js:81:28) at Object.kittydar.detectCats (/home/pi/node_modules/kittydar/kittydar.js:56:24) at /home/pi/test.js:19:23 at fs.js:266:14 at Object.oncomplete (fs.js:107:15)

Im not sure maybe im just missing something on creating my canvas, but it seems like the kittydar package looses the canvas during execution?

Has anyone else this issue? Would be glad if someone could help.

chrissloey commented 10 years ago

I've had the same issue previously and it turned out to be caused by using a newer version of node-canvas. Explicitly setting the correct versions in my package.json solved the issue for me:

"kittydar": "0.1.6",
"canvas": "1.0.1"
rainer-maucher commented 10 years ago

Hi, ok i had adifferent canvas version, but unfortunately this didn't made the trick for me, could you maybe post your whole package.json ? Maybe there are more differences... Just to make sure, even your node.js version would be great :)

rainer-maucher commented 10 years ago

Mhm, sorry my mistake i the kittydar had the old canvas installation inside itsself... fixing this to the version you gave me solved the problem, it works now.

girliemac commented 9 years ago

I am using Pi too, with the latest Raspbian.

I had problem with node-canvas 1.0.1, so manually installed the latest, which gives me the same error. However, as stated in https://github.com/Automattic/node-canvas/issues/487, I just point to the same node-canvas as a temporary fix, and everything is fine.

var kittydar = require('kittydar');
var Canvas = require('kittydar/node_modules/canvas');