【问题标题】:How to draw the trajectory ( tracking path ) of an moving object in an image - Opencv?如何在图像中绘制运动物体的轨迹(跟踪路径) - Opencv?
【发布时间】:2015-10-13 13:18:46
【问题描述】:

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

我知道一个移动对象的坐标 (x,y),它在每一帧都更新新的 (x,y) 坐标。

现在如何绘制一个对象最近 20 帧或 N 帧的轨迹路径。

【问题讨论】:

    标签: image opencv draw


    【解决方案1】:
    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);
    }
    

    【讨论】:

      【解决方案2】:

      经过长时间的坐标斗争,这是我的代码.. 跟踪 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;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多