Skip to content

Commit

Permalink
Merge branch 'master' into test-examples
Browse files Browse the repository at this point in the history
Conflicts:
	src/Matrix.cc
  • Loading branch information
peterbraden committed Feb 11, 2015
2 parents a62456f + 081ca60 commit 091447b
Show file tree
Hide file tree
Showing 18 changed files with 830 additions and 68 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: node_js
node_js:
- "0.10"
- "0.11"
- "0.12"

before_install:
- sudo apt-get update
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@

# Changelog

### 2.0.0

- Support for node 0.12
- Camera Calibration Functions from @queuecumber
- Fix for Nan 1.5.1 from @IMGNRY
- More build fixes from @scanlime
- Matrix crop prototype from @dbpieter
- Many fixes from @madshall

Thanks to everyone that contributed!


### 1.0.0

Ok, let's do a proper semver release :)
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,29 +173,29 @@ See [relevant source code](src/Contours.cc) and [examples](examples/)
```javascript
var contours = im.findContours;

# Count of contours in the Contours object
// Count of contours in the Contours object
contours.size();

# Count of corners(verticies) of contour `index`
// Count of corners(verticies) of contour `index`
contours.cornerCount(index);

# Access vertex data of contours
// Access vertex data of contours
for(var c = 0; c < contours.size(); ++c) {
console.log("Contour " + c);
for(var i = 0; i < contours.cornerCount(c); ++i) {
var point = contours.point(c, i);
console.log("(" + point.x + "," + point.y + ")");"
console.log("(" + point.x + "," + point.y + ")");
}
}

# Computations of contour `index`
// Computations of contour `index`
contours.area(index);
contours.arcLength(index, isClosed);
contours.boundingRect(index);
contours.minAreaRect(index);
contours.isConvex(index);

# Destructively alter contour `index`
// Destructively alter contour `index`
contours.approxPolyDP(index, epsilon, isClosed);
contours.convexHull(index, clockwise);
```
Expand Down
2 changes: 2 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
, "src/FaceRecognizer.cc"
, "src/BackgroundSubtractor.cc"
, "src/Constants.cc"
, "src/Calib3D.cc"
, "src/ImgProc.cc"
]
, 'libraries': [
'<!@(pkg-config --libs opencv)'
Expand Down
37 changes: 26 additions & 11 deletions lib/opencv.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ var Stream = require('stream').Stream
, path = require('path');

var cv = module.exports = require('./bindings');
var Matrix = cv.Matrix, VideoCapture = cv.VideoCapture,
ImageStream, ImageDataStream, ObjectDetectionStream, VideoStream;

var Matrix = cv.Matrix
, VideoCapture = cv.VideoCapture
, ImageStream
, ImageDataStream
, ObjectDetectionStream
, VideoStream;


Matrix.prototype.detectObject = function(classifier, opts, cb){
Expand All @@ -29,8 +34,7 @@ Matrix.prototype.inspect = function(){
}


ImageStream =
cv.ImageStream = function(){
ImageStream = cv.ImageStream = function(){
this.writable = true;
}
util.inherits(ImageStream, Stream);
Expand All @@ -45,8 +49,7 @@ ImageStream.prototype.write = function(buf){
}


ImageDataStream =
cv.ImageDataStream = function(){
ImageDataStream = cv.ImageDataStream = function(){
this.data = Buffers([]);
this.writable = true;
}
Expand All @@ -71,8 +74,7 @@ ImageDataStream.prototype.end = function(b){
}


ObjectDetectionStream =
cv.ObjectDetectionStream = function(cascade, opts){
ObjectDetectionStream = cv.ObjectDetectionStream = function(cascade, opts){
this.classifier = new cv.CascadeClassifier(cascade);
this.opts = opts || {};
this.readable = true;
Expand All @@ -94,8 +96,7 @@ ObjectDetectionStream.prototype.write = function(m){
}


VideoStream =
cv.VideoStream = function(src){
VideoStream = cv.VideoStream = function(src){
if (!(src instanceof VideoCapture)) src = new VideoCapture(src);
this.video = src;
this.readable = true;
Expand Down Expand Up @@ -134,5 +135,19 @@ VideoCapture.prototype.toStream = function(){
}



// Provide cascade data for faces etc.
cv.FACE_CASCADE = path.resolve(__dirname, '../data/haarcascade_frontalface_alt.xml')
var CASCADES = {
FACE_CASCADE: 'haarcascade_frontalface_alt.xml'
, EYE_CASCADE: 'haarcascade_eye.xml'
, EYEGLASSES_CASCADE: 'haarcascade_eye_tree_eyeglasses.xml'
, FULLBODY_CASCADE: 'haarcascade_fullbody.xml'
, CAR_SIDE_CASCADE: 'hogcascade_cars_sideview.xml'
}

Object.keys(CASCADES).forEach(function(k){
cv[k] = path.resolve(__dirname, '../data', CASCADES[k])
})



4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"author": "Peter Braden <[email protected]>",
"dependencies": {
"buffers": "0.1.1",
"nan": "^1.3.0"
"nan": "1.4.3"
},
"version": "1.0.0",
"version": "2.0.0",
"devDependencies": {
"tape": "^3.0.0",
"glob": "^4.0.6",
Expand Down
34 changes: 17 additions & 17 deletions src/BackgroundSubtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BackgroundSubtractorWrap::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(ctor, "applyMOG", ApplyMOG);

target->Set(NanNew("BackgroundSubtractor"), ctor->GetFunction());

};

NAN_METHOD(BackgroundSubtractorWrap::New) {
Expand All @@ -42,17 +42,17 @@ NAN_METHOD(BackgroundSubtractorWrap::New) {
NAN_METHOD(BackgroundSubtractorWrap::CreateMOG) {
NanScope();

int history = 200;
int nmixtures = 5;
double backgroundRatio = 0.7;
double noiseSigma = 0;

if(args.Length() > 1){
INT_FROM_ARGS(history, 0)
INT_FROM_ARGS(nmixtures, 1)
DOUBLE_FROM_ARGS(backgroundRatio, 2)
DOUBLE_FROM_ARGS(noiseSigma, 3)
}
// int history = 200;
// int nmixtures = 5;
// double backgroundRatio = 0.7;
// double noiseSigma = 0;
//
// if(args.Length() > 1){
// INT_FROM_ARGS(history, 0)
// INT_FROM_ARGS(nmixtures, 1)
// DOUBLE_FROM_ARGS(backgroundRatio, 2)
// DOUBLE_FROM_ARGS(noiseSigma, 3)
// }

Local<Object> n = NanNew(BackgroundSubtractorWrap::constructor)->GetFunction()->NewInstance();

Expand Down Expand Up @@ -83,13 +83,13 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {

Local<Object> fgMask = NanNew(Matrix::constructor)->GetFunction()->NewInstance();
Matrix *img = ObjectWrap::Unwrap<Matrix>(fgMask);


cv::Mat mat;

if(Buffer::HasInstance(args[0])){
uint8_t *buf = (uint8_t *) Buffer::Data(args[0]->ToObject());
unsigned len = Buffer::Length(args[0]->ToObject());
unsigned len = Buffer::Length(args[0]->ToObject());
cv::Mat *mbuf = new cv::Mat(len, 1, CV_64FC1, buf);
mat = cv::imdecode(*mbuf, -1);
//mbuf->release();
Expand All @@ -116,13 +116,13 @@ NAN_METHOD(BackgroundSubtractorWrap::ApplyMOG) {
TryCatch try_catch;

cb->Call(NanGetCurrentContext()->Global(), 2, argv);

if (try_catch.HasCaught()) {
FatalException(try_catch);
}

NanReturnUndefined();
}
}
catch( cv::Exception& e ){
const char* err_msg = e.what();
NanThrowError(err_msg);
Expand Down
Loading

0 comments on commit 091447b

Please sign in to comment.