如何在图像中绘制轨迹(跟踪路径(-Opencv?
我知道一个移动物体的坐标(x,y(,每一帧它都在更新新的坐标(x,y(。
现在如何绘制对象最后20帧或N帧的轨迹路径。
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);
}
经过与坐标的长期斗争,这里是我的代码。。跟踪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;
}