PacktPublishing/Learn-OpenCV-4-By-Building-Projects-Second-Edition

Ch9 farnebackTracker.cpp calcOpticalFlowFarneback(...) has memory error

vk8051 opened this issue · 1 comments

Ch9
farnebackTracker.cpp

// Calculate optical flow map using Farneback algorithm
calcOpticalFlowFarneback(prevGray, curGray, flowImage, pyrScale, numLevels, windowSize, numIterations, neighborhoodSize, stdDeviation, OPTFLOW_USE_INITIAL_FLOW);

has memory error

The author forgot to initiate flowImage as CV_32FC2 type, adding the following solves the problem:

flowImage = Mat::zeros(frame.size(), CV_32FC2);

// Calculate optical flow map using Farneback algorithm
calcOpticalFlowFarneback(prevGray, curGray, flowImage, pyrScale, windowSize, numIterations,
neighborhoodSize, stdDeviation, OPTFLOW_USE_INITIAL_FLOW);