~example fixed

This commit is contained in:
Dmitry Ivanovm 2017-03-08 16:40:59 -05:00
parent 9edf312229
commit 833c81d596

View File

@ -35,25 +35,31 @@ cap.read(function(err, firstFrame) {
cap.read(function(err, newFrame) { cap.read(function(err, newFrame) {
if (err) throw err; 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 if ( frameSize[0] > 0 && frameSize[1] > 0) {
var flow = old_frame.calcOpticalFlowPyrLK(newFrame, goodFeatures, lk_params.winSize, lk_params.maxLevel, lk_params.criteria); 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 // Select good points
for(var i = 0; i < flow.old_points.length; i++){
if(flow.found[i]){ // draw the tracks
out.line(flow.old_points[i], flow.new_points[i], color); 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.show(out);
window.blockingWaitKey(0, 50); window.blockingWaitKey(0, 50);
*/ */
old_frame = newFrame.copy();
read(); old_frame = newFrame.copy();
read();
}
}); });
} }