mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
make readfile async
This commit is contained in:
parent
1e9f8e9f35
commit
0c730cef5a
41
README.md
41
README.md
@ -39,6 +39,47 @@ Or to build the repo:
|
||||
|
||||
|
||||
|
||||
## API Documentation
|
||||
|
||||
### Matrix
|
||||
|
||||
The [matrix](http://opencv.jp/opencv-2svn_org/cpp/core_basic_structures.html#mat) is the most useful
|
||||
base datastructure in OpenCV. Things like images are just matrices of pixels.
|
||||
|
||||
#### Creation
|
||||
|
||||
new Matrix(width, height)
|
||||
|
||||
Or you can use opencv to read in image files. Supported formats are in the OpenCV docs, but jpgs etc are supported.
|
||||
|
||||
cv.readImage(filename, function(mat){
|
||||
...
|
||||
})
|
||||
|
||||
cv.readImage(buffer, function(mat){
|
||||
...
|
||||
})
|
||||
|
||||
If you need to pipe data into an image, you can use an imagestream:
|
||||
|
||||
var s = new cv.ImageStream()
|
||||
|
||||
s.on('load', function(matrix){
|
||||
...
|
||||
})
|
||||
|
||||
fs.createReadStream('./examples/test.jpg').pipe(s);
|
||||
|
||||
#### Accessors
|
||||
|
||||
#### Image Processing
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## WIP
|
||||
|
||||
@ -44,12 +44,15 @@ imagestream.write = function(buf){
|
||||
|
||||
|
||||
imagestream.end = function(b){
|
||||
var self = this;
|
||||
|
||||
if (b)
|
||||
imagestream.write.call(this,b);
|
||||
|
||||
var buf = this.data.toBuffer();
|
||||
|
||||
var im = cv.readImage(buf);
|
||||
this.emit('load', im);
|
||||
cv.readImage(buf, function(err, im){
|
||||
self.emit('load', im);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ OpenCV::ReadImage(const Arguments &args) {
|
||||
Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
|
||||
cv::Mat mat;
|
||||
|
||||
REQ_FUN_ARG(1, cb);
|
||||
|
||||
if (args[0]->IsNumber() && args[1]->IsNumber()){
|
||||
int width, height;
|
||||
@ -53,7 +54,21 @@ OpenCV::ReadImage(const Arguments &args) {
|
||||
}
|
||||
|
||||
img->mat = mat;
|
||||
return scope.Close(im_h);
|
||||
|
||||
Local<Value> argv[2];
|
||||
|
||||
argv[0] = Local<Value>::New(Null());
|
||||
argv[1] = im_h;
|
||||
|
||||
TryCatch try_catch;
|
||||
|
||||
cb->Call(Context::GetCurrent()->Global(), 2, argv);
|
||||
|
||||
if (try_catch.HasCaught()) {
|
||||
FatalException(try_catch);
|
||||
}
|
||||
|
||||
return Undefined();
|
||||
|
||||
} catch( cv::Exception& e ){
|
||||
const char* err_msg = e.what();
|
||||
|
||||
@ -111,19 +111,25 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
|
||||
, "toBuffer": function(cv){
|
||||
var buf = fs.readFileSync('./examples/mona.jpg')
|
||||
, im = cv.readImage(buf.slice(0))
|
||||
, buf0 = im.toBuffer()
|
||||
|
||||
assert.ok(buf0);
|
||||
cv.readImage(buf.slice(0), function(err, mat){
|
||||
var buf0 = mat.toBuffer()
|
||||
|
||||
assert.ok(buf0);
|
||||
//assert.equal(buf.toString('base64'), buf0.toString('base64'));
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
, "faceDetect": {
|
||||
|
||||
topic : function(){
|
||||
var cv = require('../lib/opencv')
|
||||
, im = cv.readImage("./examples/mona.jpg")
|
||||
im.faceDetect("./examples/haarcascade_frontalface_alt.xml", {}, this.callback)
|
||||
, cb = this.callback
|
||||
|
||||
cv.readImage("./examples/mona.jpg", function(err, im){
|
||||
im.faceDetect("./examples/haarcascade_frontalface_alt.xml", {}, cb)
|
||||
})
|
||||
}
|
||||
|
||||
, "finds face": function(err, faces){
|
||||
@ -142,19 +148,22 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
topic : require('../lib/opencv')
|
||||
|
||||
, ".readImage from file": function(cv){
|
||||
var im = cv.readImage("./examples/mona.jpg")
|
||||
assert.ok(im)
|
||||
assert.equal(im.width(), 500);
|
||||
assert.equal(im.height(), 756)
|
||||
assert.equal(im.empty(), false)
|
||||
cv.readImage("./examples/mona.jpg", function(err, im){
|
||||
assert.ok(im);
|
||||
assert.equal(im.width(), 500);
|
||||
assert.equal(im.height(), 756)
|
||||
assert.equal(im.empty(), false)
|
||||
})
|
||||
}
|
||||
|
||||
, ".readImage from buffer" : function(cv){
|
||||
var im = cv.readImage(fs.readFileSync('./examples/mona.jpg'))
|
||||
assert.ok(im);
|
||||
assert.equal(im.width(), 500);
|
||||
assert.equal(im.height(), 756)
|
||||
assert.equal(im.empty(), false)
|
||||
cv.readImage(fs.readFileSync('./examples/mona.jpg'), function(err, im){
|
||||
assert.ok(im);
|
||||
assert.equal(im.width(), 500);
|
||||
assert.equal(im.height(), 756)
|
||||
assert.equal(im.empty(), false)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -170,9 +179,13 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
||||
, "face detection": {
|
||||
topic : function(){
|
||||
var cv = require('../lib/opencv')
|
||||
, im = cv.readImage("./examples/mona.jpg")
|
||||
, cascade = new cv.CascadeClassifier("./examples/haarcascade_frontalface_alt.xml");
|
||||
cascade.detectMultiScale(im, this.callback)//, 1.1, 2, [30, 30]);
|
||||
, self = this
|
||||
|
||||
cv.readImage("./examples/mona.jpg", function(err, im){
|
||||
cascade = new cv.CascadeClassifier("./examples/haarcascade_frontalface_alt.xml");
|
||||
cascade.detectMultiScale(im, self.callback)//, 1.1, 2, [30, 30]);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
, "finds face": function(err, faces){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user