a. Tracking, trivial way
Motion track in OpenCV is articulated around the CalcOpticalFlowPyrLK function that calculate the flow between to image and allow to track the movement of an object. The following program works as explained below and I have used a video where a simple object is crossing the screen from left to right.
- A frame is queried from the video
- GoodFeaturesToTrack is called to find interesting points on the frame
- The CalcOpticalFlowPyrLK is computed with the previous frame and the newly found points to allow the algorithm to compute the movement
- Points that didn’t moved are deleted from the list of points
- Then a line is drawn between the old position of the point and the new position of the point.
- Finally all the lines are kept in a list so that they can be drawn on the following frames
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
b. Another way
This example is slightly different in the way that lines are not kept in memory and they are drawn from the first position of a point to the last recorded position of a point.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
<<Operations On Videos | Home | Movement Detection With Background>>