如何在图像中绘制运动物体的轨迹(跟踪路径) - Opencv?

时间:2014-04-30 11:57:18

标签: image opencv draw

如何在图像中绘制轨迹(跟踪路径) - Opencv?

我知道移动物体(x,y)的坐标,每帧都在更新新的(x,y)坐标。

now如何绘制最近20帧或N帧数的对象的轨迹路径。

2 个答案:

答案 0 :(得分:2)

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);
}

答案 1 :(得分:0)

经过与坐标的长时间斗争,在这里我的代码..跟踪N帧数

    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;
}