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

An API to return the coordinates of cat's face given image url? #23

Open lenadroid opened 9 years ago

lenadroid commented 9 years ago

Hello!

Is there a way or an API where given an URL of some image (jpg, png, etc.) I can use kittydar to get the coordinates of cat's face, or an array of face coords, if there are several cats?

vicary commented 9 years ago

Since Kittydar.prototype.detectCats() is already returning coordinates, all you need is a canvas.

Not sure what environment you're working on though. In browsers should be easily done with a little edit from the example website. For standalone scripts, may be PhantomJS or node-canvas?

lenadroid commented 9 years ago

@vicary thanks for the reply. I am working from .NET server side language, and want to be able to make the request like "https://harthur.github.io/kittydar/blablabla?image=http://25.media.tumblr.com/tumblr_m2qun38akV1qzwa71o1_1280.jpg" and receive the coordinates as a result..

vicary commented 9 years ago

In short, no.

Github pages only supports HTML, Markdown and wiki styles. Server side scripting is not likely to support that way. I am afraid you have to make your own wrapper, it's easy though.

Since this is written in javascript, you'll need a javascript environment to run it.

Good news is that I missed the part that kittydar itself is depends on node-canvas, in fact you can simply download the image and stuff the binary data into utils.dataToCanvas().

You can see my gist wrapped with restify. But if you don't want to expose this for others to use, I recommend a command-line script instead, which is even more easier and use less resources.

For either case, you will need to install Cairo before you can npm install kittydar because kittydar depends on canvas and canvas needs Cairo to run.

Note I cannot build canvas@1.0.1 which is required by kittydar@0.1.6, the current version of canvas@1.2.1 can be built with warnings though. Possibly because v8 of my node version has been upgraded.

I just don't bother testing out which version of node works. kittydar should upgrade it's dependency of canvas to ~1.2, or pin down the node version in package.json.

The kittyUtil in my gist is written with my best guess, but most of the script should work once you managed to npm install kittydar.

rozboris commented 9 years ago

I'm doing it in a similar way, if kittydar community is interested. It's rather slow, but works as an API (/?url=http://example.com/link-to-image.jpg). See gist here It returns proper JSON, even in case of an error (check for the presence of an 'error' field in response). It supports http:// and https://, JPG and PNG (converting anything to PNG with sharp, since Canvas.Image did not work with JPG on my Debian installation). It's dirty, since it was written in one night, sorry. Tested on Debian 7 x64 (Digitalocean instance) with the following dependencies:

vicary commented 9 years ago

@rozboris Small utils like that should be written in one night, you're doing it right. :smile: I am interested in your node version too, coz my build failure is about V8.

rozboris commented 9 years ago

@vicary It's running on the latest Node.js v0.10.36. BTW, you might be able to drop heavy sharp lib depedency if you don't need JPG support. It works fine with PNG without conversion (on my setup).

vicary commented 9 years ago

@rozboris Thanks, good to know.

Since node-canvas does not specifically lists out supported formats, utils.dataToCanvas();, canvas.drawImage(img, ... ); pipes directly to the C module and then to Cairo.

I mean, it is possible that Cairo supports most of the common formats directly, may try taking out all image conversion deps too.

rozboris commented 9 years ago

@vicary The only reason I was dealing with conversion through sharp is because my version of Cairo did not work with jpg. I did not have time to figure out why, it was complaining for something (I don't have any records to check what was it exactly). kittydar depends on rather old canvas which in turn depends on rather old Cairo, that can be the issue here.

vicary commented 9 years ago

@rozboris Time to fork?

@harthur Knock, knock.

harthur commented 9 years ago

@rozboris you need to install libjpeg for node-canvas to work with jpegs, I believe.

rozboris commented 9 years ago

@harthur It was definitely installed (it's a prerequisite for Cairo/node-canvas, see https://github.com/Automattic/node-canvas/wiki/Installation---Ubuntu-and-other-Debian-based-systems#installing-dependencies), but it's not enough.