From 833c81d5966ae1570d1d705d60264c5bef3fa147 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanovm Date: Wed, 8 Mar 2017 16:40:59 -0500 Subject: [PATCH] ~example fixed --- examples/optical-flow.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/examples/optical-flow.js b/examples/optical-flow.js index 9e4b3b3..3e2f48b 100755 --- a/examples/optical-flow.js +++ b/examples/optical-flow.js @@ -35,25 +35,31 @@ cap.read(function(err, firstFrame) { cap.read(function(err, newFrame) { if (err) throw err; - var goodFeatures = old_frame.goodFeaturesToTrack(feature_params.maxCorners, feature_params.qualityLevel, feature_params.minDistance); + var frameSize = newFrame.size(); - // calculate optical flow - var flow = old_frame.calcOpticalFlowPyrLK(newFrame, goodFeatures, lk_params.winSize, lk_params.maxLevel, lk_params.criteria); + if ( frameSize[0] > 0 && frameSize[1] > 0) { + var goodFeatures = old_frame.goodFeaturesToTrack(feature_params.maxCorners, feature_params.qualityLevel, feature_params.minDistance); - // Select good points + // calculate optical flow + var flow = old_frame.calcOpticalFlowPyrLK(newFrame, goodFeatures, lk_params.winSize, lk_params.maxLevel, lk_params.criteria); - // 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); + // 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); + window.show(out); + window.blockingWaitKey(0, 50); */ - old_frame = newFrame.copy(); - read(); + + old_frame = newFrame.copy(); + read(); + } }); }