Question

How to draw the trajectory ( tracking path ) in an image - Opencv ?

i know the co-ordinates of an moving object ( x,y), every frame it is updating new (x ,y ) co-ordinates.

now How to draw the trajectory path of an object for last 20 frames or N number of frames.

Was it helpful?

Solution

cv::Mat imageToDraw; //this is your image to draw, don't forget to load it
std::vector<cv::Point> pointsInLast20Frames; //fill this vector with points, they should be ordered
cv::Scalar color(0, 0, 255); //red
for(int i = 0; i < pointsInLast20Frames.size() - 1; ++i)
{
   cv::line(imageToDraw, pointsInLast20Frames[i], pointsInLast20Frames[i+1], color);
}

OTHER TIPS

After a long fight with co-ordinates, Here my code .. Tracking N number of frames

    int nTrackCount = 0;

    int nTrackFrames = 20;      
    vector<Rect> boundRect1( nTrackFrames );

    Detect_Object(frame)
    {    

         if ( nTrackCount < nTrackFrames )
        {
            boundRect1[nTrackCount].x = PredictKP.x;
            boundRect1[nTrackCount].y = PredictKP.y;
        }
        nTrackCount++;

        for ( int iTrack = 0; iTrack < nTrackCount ; iTrack++)
        {
            Point Pt;
            Pt.x = boundRect1[iTrack].x;
            Pt.y = boundRect1[iTrack].y;
// Drawing Cross ( X ) for tracking 
            drawCross(frame, Pt, Scalar(255, 255, 255), 5); // Corrected                                
       }
       if(nTrackCount ==nTrackFrames)
        nTrackCount = 0;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top