56

Can we use OpenCV from Javascript? Is there such implementation?

Is there any JS libraries that can be used for detecting face elements in the picture or video?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Bohdan
  • 16,531
  • 16
  • 74
  • 68

9 Answers9

29

OpenCV has never been ported to JavaScript in its entirety, but individual parts and algorithms have:

  • For face and face element detection (and other parts / objects), you could use js-objectdetect or HAAR.js which are ports of the OpenCV Object Detection based on Haar Feature Cascades.

  • The very first face detection algorithm on the web found in ccv also deserves a mention. Its classifier seems to be less reliable than the one provided by OpenCV though.

  • The headtrackr library used for facetracking might also be of interest since it implements the camshift algorithm also found in OpenCV.

le_m
  • 19,302
  • 9
  • 64
  • 74
  • 1
    +1 to headtrackr: well designed API providing events or face tracking (position, width, height, angle), head tracking (position in relation to camera) and status (getUserMedia available, streaming, face detection, redetection, etc.) – Sam Dutton Mar 19 '13 at 09:53
19

I recommend OpenCVjs. This is javascript OpenCV library.

amrocs
  • 344
  • 7
  • 9
16

I don't think there is any way of using openCV in JS other than communicating with a server with openCV on it and doing the processing there.

There is one Face detection algo in JS that I know of: http://badassjs.com/post/1461943420/face-detection-in-javascript-via-html5-canvas

crazyjoe
  • 471
  • 3
  • 5
  • do you know any way to access camera from js? – Bohdan Feb 05 '12 at 12:34
  • 1
    @BohdanVoloshyn refer getUSerMedia (webrtc) – Ram Aug 21 '12 at 15:51
  • 2
    now opencv is also available in Javascript as opencv.js (Ported to JS using Emscripten into asm.js format), for more info visit- https://docs.opencv.org/trunk/d5/d10/tutorial_js_root.html – flamelite Nov 15 '17 at 14:00
15

I do not know of a full implementation of OpenCV in Javascript, however a good number of the algorithms from it are implemented in JSFeat which is a Computer Vision library in Javascript.

I believe that it might be possible to compile bits of OpenCV with emscripten, but as far as I know, nobody has done that.

kybernetikos
  • 8,281
  • 1
  • 46
  • 54
  • useful lib, however I wanted to detect faces when I had to use OpenCV – Bohdan Jul 03 '13 at 21:19
  • you might prefer something like http://neave.github.io/face-detection/ then (although the haar detector in jsfeat can be used for face detection). – kybernetikos Jul 10 '13 at 23:39
  • and there's even running example for that: http://inspirit.github.io/jsfeat/sample_haar_face.html – Eran W Oct 19 '13 at 14:16
15

Porting OpenCV to Javascript should be doable using asm.js which can compile C or C++ to Javascript

Another take: OpenCV is ported to Chrome Native Client: http://opencv.org/opencv-ported-to-google-chrome-nacl-and-pnacl.html

Maciej Jankowski
  • 2,794
  • 3
  • 26
  • 33
6

Excellent repo for that here: https://github.com/peterbraden/node-opencv Doesn't seem to have full opencv functionality, but has face detection and great support for image streams coming from sources like an ar-drone.

Harrison
  • 830
  • 1
  • 15
  • 28
6

This seems to be very good. http://trackingjs.com/ Have a look.

arpo
  • 1,831
  • 2
  • 27
  • 48
2

Concerning your second question clmtrackr looks very promising. It ...

... is a javascript library for fitting facial models to faces in videos or images. It currently is an implementation of constrained local models fitted by regularized landmark mean-shift, as described in Jason M. Saragih's paper. clmtrackr tracks a face and outputs the coordinate positions of the face model as an array.

Try out this example to have a look at their model.

Christoph
  • 1,310
  • 16
  • 28
2

In addition to those mentioned, there is another repo for "opencvjs"

https://github.com/blittle/opencvjs

It's a little unclear which of them (if any) are supposed to be canonical

cavalcade
  • 1,367
  • 14
  • 15