Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 102 lines (53 sloc) 2.328 kb
a911fe3 @peterbraden readme
peterbraden authored
1 # node-opencv
2
b121221 @peterbraden build icon
peterbraden authored
3 [![Build Status](https://secure.travis-ci.org/peterbraden/node-opencv.png)](http://travis-ci.org/peterbraden/node-opencv)
4
5
a911fe3 @peterbraden readme
peterbraden authored
6 [OpenCV](http://opencv.willowgarage.com/wiki/) bindings for Node.js
7
8 ## Install
9
468034d @peterbraden WIP
peterbraden authored
10 You'll need OpenCV installed. I'm using v2.2 because I couldn't get 2.3 to compile, but it should theoretically work with 2.3
11
12 Then:
a82c66f @peterbraden readme etc
peterbraden authored
13
14
15 npm install opencv
16
17
18 Or to build the repo:
19
20
468034d @peterbraden WIP
peterbraden authored
21 node-waf configure && node-waf build
22
23
a82c66f @peterbraden readme etc
peterbraden authored
24 ## Examples
25
26 ### Face Detection
27
28
c93b9dc @peterbraden update examples
peterbraden authored
29 cv.readImage("./examples/test.jpg", function(err, im){
1f41b20 @peterbraden mv data
peterbraden authored
30 im.detectObject("./data/haarcascade_frontalface_alt.xml", {}, function(err, faces){
c93b9dc @peterbraden update examples
peterbraden authored
31 for (var i=0;i<faces.length; i++){
32 var x = faces[i]
33 im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);
34 }
35 im.save('./out.jpg');
36
37 });
38 })
97fadd3 @peterbraden make detectMultiscale async
peterbraden authored
39
a82c66f @peterbraden readme etc
peterbraden authored
40
41
0c730ce @peterbraden make readfile async
peterbraden authored
42 ## API Documentation
43
44 ### Matrix
45
46 The [matrix](http://opencv.jp/opencv-2svn_org/cpp/core_basic_structures.html#mat) is the most useful
47 base datastructure in OpenCV. Things like images are just matrices of pixels.
48
49 #### Creation
50
51 new Matrix(width, height)
52
53 Or you can use opencv to read in image files. Supported formats are in the OpenCV docs, but jpgs etc are supported.
54
55 cv.readImage(filename, function(mat){
56 ...
57 })
58
59 cv.readImage(buffer, function(mat){
60 ...
61 })
62
63 If you need to pipe data into an image, you can use an imagestream:
64
65 var s = new cv.ImageStream()
66
67 s.on('load', function(matrix){
68 ...
69 })
70
71 fs.createReadStream('./examples/test.jpg').pipe(s);
72
73 #### Accessors
bc91847 @peterbraden docs etc
peterbraden authored
74
75 var mat = new cv.Matrix.Eye(4,4); // Create identity matrix
76
77 mat.get(0,0) // 1
78
79 mat.row(0) // [1,0,0,0]
80 mat.col(4) // [0,0,0,1]
81
82
0c730ce @peterbraden make readfile async
peterbraden authored
83
84 #### Image Processing
85
86
d54e8dc @peterbraden docs etc
peterbraden authored
87 #### Object Detection
88
89 There is a shortcut method for
90 [Viola-Jones Haar Cascade](http://www.cognotics.com/opencv/servo_2007_series/part_2/sidebar.html) object
91 detection. This can be used for face detection etc.
0c730ce @peterbraden make readfile async
peterbraden authored
92
93
f510f71 @peterbraden improve interface
peterbraden authored
94 mat.detectObject(haar_cascade_xml, opts, function(err, matches){})
0c730ce @peterbraden make readfile async
peterbraden authored
95
96
a911fe3 @peterbraden readme
peterbraden authored
97
98
99 ## WIP
100
101 This is a WIP. I've never written C++ before so the code may be _interesting_ - if
56ff741 @peterbraden update face detect and readme
peterbraden authored
102 I'm doing stuff wrong please feel free to correct me.
Something went wrong with that request. Please try again.