diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..f86a829
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+node-opencv
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..97626ba
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml
new file mode 100644
index 0000000..d23208f
--- /dev/null
+++ b/.idea/jsLibraryMappings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..72abef0
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..b0727cb
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/node-opencv.iml b/.idea/node-opencv.iml
new file mode 100644
index 0000000..c956989
--- /dev/null
+++ b/.idea/node-opencv.iml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..950cc5f
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,723 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+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
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/optical-flow.js b/examples/optical-flow.js
index 96ce808..9efbd1c 100755
--- a/examples/optical-flow.js
+++ b/examples/optical-flow.js
@@ -1,20 +1,56 @@
var cv = require('../lib/opencv');
+var path = require('path');
-try {
- var camera = new cv.VideoCapture(0);
- var window = new cv.NamedWindow('Video', 0)
- /*
- setInterval(function() {
- camera.read(function(err, im) {
+var cap = new cv.VideoCapture(path.join(__dirname, 'files', 'motion.mov'));
+var window = new cv.NamedWindow('Video', 0);
+
+// Parameters for lucas kanade optical flow
+var lk_params = {
+ winSize: [15, 15],
+ maxLevel: 2,
+ criteria: [cv.TERM_CRITERIA_EPS | cv.TERM_CRITERIA_COUNT, 30, 0.03]
+};
+
+feature_params = {
+ maxCorners: 100,
+ qualityLevel: 0.1,
+ minDistance: 10
+};
+
+// Create some random colors
+var color = [255, 0, 0];
+
+// Take first frame and find corners in it
+cap.read(function(err, firstFrame) {
+ if (err) throw err;
+
+ var old_frame = firstFrame;
+
+ // Create a mask image for drawing purposes
+ function read() {
+ var out = old_frame.copy();
+ cap.read(function(err, newFrame) {
if (err) throw err;
- console.log(im.size())
- if (im.size()[0] > 0 && im.size()[1] > 0){
- window.show(im);
+
+ var goodFeatures = old_frame.goodFeaturesToTrack(feature_params.maxCorners, feature_params.qualityLevel, feature_params.minDistance);
+
+ // calculate optical flow
+ var flow = old_frame.calcOpticalFlowPyrLK(newFrame, goodFeatures, lk_params.winSize, lk_params.maxLevel, lk_params.criteria);
+
+ // Select good points
+
+ // draw the tracks
+ for(var i = 0; i < flow.old_points.length; i++){
+ if(flow.found[i]){
+ out.line(flow.old_points[i], flow.new_points[i], color);
+ }
}
+ window.show(out);
window.blockingWaitKey(0, 50);
+ old_frame = newFrame.copy();
+ read();
});
- }, 20);
- */
-} catch (e){
- console.log("Couldn't start camera:", e)
-}
+ }
+
+ read();
+});
\ No newline at end of file
diff --git a/src/Matrix.cc b/src/Matrix.cc
index f0134aa..cda5221 100755
--- a/src/Matrix.cc
+++ b/src/Matrix.cc
@@ -82,6 +82,7 @@ void Matrix::Init(Local