I am using KLT (Kanade-Lucas-Tomasi Tracking) Tracking algorithm to track the motion of traffic in India. I am tracking flow of one side of traffic properly, but other side of traffic, that is moving in frame is not detected at all.
Algorithm consist of cv2.goodFeaturesToTrack
and cv2.calcOpticalFlowPyrLK
to achieve the result.
In the image you can see that Red and Silver car have no tracking feature on them. Yellow Auto on left is also not tracked. Any reason for this? Corners are still there.
Feature Parameters for cv2.goodFeaturesToTrack
:
feature_params = dict( maxCorners = 500, # How many pts. to locate
qualityLevel = 0.1, # b/w 0 & 1, min. quality below which everyone is rejected
minDistance = 7, # Min eucledian distance b/w corners detected
blockSize = 3 ) # Size of an average block for computing a derivative covariation matrix over each pixel neighborhood
Feature Parameters for cv2.calcOpticalFlowPyrLK
:
lk_params = dict( winSize = (15,15), # size of the search window at each pyramid level
maxLevel = 2, # 0, pyramids are not used (single level), if set to 1, two levels are used, and so on
criteria = (cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.03))
Video I have to use is 60 min. long and KLT stops tracking after 5 min.. Any suggestions or help would be great. Thanks.
Basically you are doing everything right you just need to reinitialize the good points for tracking like this
after say every 5th frame or whatever you like Hope it helps ! following is my code: