forked from peterbraden/node-opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: package.json
- Loading branch information
Showing
14 changed files
with
108 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ $ npm install opencv | |
``` | ||
|
||
## Examples | ||
Run the examples from the parent directory. | ||
|
||
### Face Detection | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
var cv = require('../lib/opencv'); | ||
|
||
cv.readImage("./files/mona.png", function(err, orig) { | ||
cv.readImage("./examples/files/mona.png", function(err, orig) { | ||
if (err) throw err; | ||
|
||
cv.readImage("./files/over_text.png", function(err, over_text) { | ||
cv.readImage("./examples/files/over_text.png", function(err, over_text) { | ||
if (err) throw err; | ||
|
||
var result = new cv.Matrix(orig.width(), orig.height()); | ||
result.addWeighted(orig, 0.7, over_text, 0.9); | ||
result.save("./tmp/weighted.png"); | ||
console.log('Image saved to ./tmp/weighted.png'); | ||
result.save("./examples/tmp/weighted.png"); | ||
console.log('Image saved to ./examples/tmp/weighted.png'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
var cv = require('../lib/opencv'); | ||
|
||
var camera = new cv.VideoCapture(0); | ||
var window = new cv.NamedWindow('Video', 0) | ||
|
||
setInterval(function() { | ||
camera.read(function(err, im) { | ||
if (err) throw err; | ||
window.show(im); | ||
window.blockingWaitKey(0, 50); | ||
}); | ||
}, 20); | ||
try { | ||
var camera = new cv.VideoCapture(0); | ||
var window = new cv.NamedWindow('Video', 0) | ||
/* | ||
setInterval(function() { | ||
camera.read(function(err, im) { | ||
if (err) throw err; | ||
console.log(im.size()) | ||
if (im.size()[0] > 0 && im.size()[1] > 0){ | ||
window.show(im); | ||
} | ||
window.blockingWaitKey(0, 50); | ||
}); | ||
}, 20); | ||
*/ | ||
} catch (e){ | ||
console.log("Couldn't start camera:", e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
var cv = require('../lib/opencv'); | ||
var vid = new cv.VideoCapture(0); | ||
try { | ||
var vid = new cv.VideoCapture(0); | ||
|
||
vid.read(function(err, im){ | ||
if (err) throw err; | ||
|
||
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){ | ||
vid.read(function(err, im){ | ||
if (err) throw err; | ||
if (!faces.length) return console.log("No Faces"); | ||
if (im.size()[0] > 0 && im.size()[1] > 0){ | ||
|
||
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){ | ||
if (err) throw err; | ||
if (!faces.length) return console.log("No Faces"); | ||
|
||
var face = faces[0]; | ||
var ims = im.size(); | ||
var im2 = im.roi(face.x, face.y, face.width, face.height) | ||
/* | ||
im.adjustROI( | ||
-face.y | ||
, (face.y + face.height) - ims[0] | ||
, -face.x | ||
, (face.x + face.width) - ims[1]) | ||
*/ | ||
im2.save('./tmp/take-face-pics.jpg') | ||
console.log('Image saved to ./tmp/take-face-pics.jpg'); | ||
}) | ||
}); | ||
var face = faces[0]; | ||
var ims = im.size(); | ||
var im2 = im.roi(face.x, face.y, face.width, face.height) | ||
/* | ||
im.adjustROI( | ||
-face.y | ||
, (face.y + face.height) - ims[0] | ||
, -face.x | ||
, (face.x + face.width) - ims[1]) | ||
*/ | ||
im2.save('./examples/tmp/take-face-pics.jpg') | ||
console.log('Image saved to ./tmp/take-face-pics.jpg'); | ||
}) | ||
} else { | ||
console.log("Camera didn't return image") | ||
} | ||
}); | ||
} catch (e){ | ||
console.log("Couldn't start camera", e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var test = require('tape') | ||
, glob = require('glob') | ||
, exec = require('child_process').exec | ||
, path = require('path') | ||
|
||
module.exports = function(){ | ||
|
||
glob.sync('./examples/*.js').forEach(function(example){ | ||
test("Example: " + example, function(assert){ | ||
|
||
var fullName = path.resolve(example) | ||
, examples = path.resolve('./examples') | ||
|
||
exec('node ' + fullName, {cwd: examples}, function(error, stdout, stderr){ | ||
assert.error(error) | ||
assert.end() | ||
}) | ||
}) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,3 +275,7 @@ test("fonts", function(t) { | |
}); | ||
}) | ||
|
||
// Test the examples folder. | ||
require('./examples')() | ||
|
||
|