diff --git a/README.md b/README.md
index 37d61ef3..0dcd12a5 100755
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@ $ npm install opencv
```
## Examples
+Run the examples from the parent directory.
### Face Detection
diff --git a/data/hogcascade_cars_sideview.xml b/data/hogcascade_cars_sideview.xml
index 167705bd..8860c161 100644
--- a/data/hogcascade_cars_sideview.xml
+++ b/data/hogcascade_cars_sideview.xml
@@ -1,6 +1,6 @@
-
+
+ 16 8 16 8 28
+
+
diff --git a/examples/addweighted.js b/examples/addweighted.js
index dc9379ff..ac6c309d 100755
--- a/examples/addweighted.js
+++ b/examples/addweighted.js
@@ -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');
});
});
diff --git a/examples/camera.js b/examples/camera.js
index abe885bb..96ce8086 100755
--- a/examples/camera.js
+++ b/examples/camera.js
@@ -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)
+}
diff --git a/examples/car-detection.js b/examples/car-detection.js
index 58c2d61f..df296d62 100644
--- a/examples/car-detection.js
+++ b/examples/car-detection.js
@@ -1,3 +1,6 @@
+/* For some reason the cascade file is broken on linux :(
+
+
var cv = require('../lib/opencv');
cv.readImage("./files/car1.jpg", function(err, im){
@@ -16,3 +19,4 @@ cv.readImage("./files/car1.jpg", function(err, im){
console.log('Image saved to ./tmp/car-detection.jpg');
});
});
+*/
diff --git a/examples/face-proxy.js b/examples/face-proxy.js
index 541ba7b4..307c64fe 100755
--- a/examples/face-proxy.js
+++ b/examples/face-proxy.js
@@ -3,7 +3,7 @@ var http = require('http'),
request = require('request'),
cv = require('../lib/opencv');
-http.createServer(function(req, resp){
+var server = http.createServer(function(req, resp){
var url = req.url.slice(1);
request({uri:url, encoding:'binary'}, function(err, r, body){
if (err) return resp.end(err.stack);
@@ -27,4 +27,7 @@ http.createServer(function(req, resp){
});
});
-}).listen(3000, function(){ console.log('Listening on http://localhost:3000'); })
+})
+
+
+//server.listen(3000, function(){ console.log('Listening on http://localhost:3000'); })
diff --git a/examples/salt.js b/examples/salt.js
index d3212b25..737e834e 100755
--- a/examples/salt.js
+++ b/examples/salt.js
@@ -1,7 +1,7 @@
var cv = require('../lib/opencv');
cv.readImage("./files/mona.png", function(err, im) {
- salt(im, 1000);
+ salt(im, 100);
im.save("./tmp/salt.png");
console.log('Image saved to ./tmp/salt.png');
});
diff --git a/examples/take-face-pics.js b/examples/take-face-pics.js
index 418809b4..79167d67 100644
--- a/examples/take-face-pics.js
+++ b/examples/take-face-pics.js
@@ -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)
+}
diff --git a/examples/warp-image.js b/examples/warp-image.js
index 5b6d32d2..8549bf9c 100644
--- a/examples/warp-image.js
+++ b/examples/warp-image.js
@@ -1,6 +1,6 @@
var cv = require('../lib/opencv');
-cv.readImage("./mona.png", function(err, im) {
+cv.readImage("./files/mona.png", function(err, im) {
if (err) throw err;
var width = im.width();
@@ -11,6 +11,6 @@ cv.readImage("./mona.png", function(err, im) {
var dstArray = [0, 0, width * 0.9, height * 0.1, width, height, width * 0.2, height * 0.8];
var xfrmMat = im.getPerspectiveTransform(srcArray, dstArray);
im.warpPerspective(xfrmMat, width, height, [255, 255, 255]);
- im.save("./warp-image.png");
+ im.save("./tmp/warp-image.png");
console.log('Image saved to ./tmp/warp-image.png');
});
diff --git a/package.json b/package.json
index ab830786..5f835b84 100755
--- a/package.json
+++ b/package.json
@@ -11,6 +11,8 @@
"devDependencies": {
"tape": "^3.0.0",
"aws-sdk": "~2.0.21"
+ "glob": "^4.0.6",
+ "request": "^2.45.0"
},
"bundledDependencies":["node-pre-gyp"],
"license": "MIT",
diff --git a/src/HighGUI.cc b/src/HighGUI.cc
index bb1197b4..3b99c9ef 100644
--- a/src/HighGUI.cc
+++ b/src/HighGUI.cc
@@ -53,7 +53,13 @@ NamedWindow::NamedWindow(const std::string& name, int f){
NAN_METHOD(NamedWindow::Show){
SETUP_FUNCTION(NamedWindow)
Matrix *im = ObjectWrap::Unwrap(args[0]->ToObject());
- cv::imshow(self->winname, im->mat);
+
+ try{
+ cv::imshow(self->winname, im->mat);
+ } catch(cv::Exception& e ){
+ const char* err_msg = e.what();
+ NanThrowError(err_msg);
+ }
NanReturnValue(args.Holder());
}
diff --git a/src/Matrix.cc b/src/Matrix.cc
index 1f0b9d95..d378a630 100755
--- a/src/Matrix.cc
+++ b/src/Matrix.cc
@@ -69,6 +69,7 @@ Matrix::Init(Handle