简体   繁体   English

使用Opencv / c ++在Stream中的两个点之间绘制aline

[英]draw aline between two points in Stream using Opencv /c++

I am getting crazy...I want to draw a line between the (center.x and center.y) in the last frame and (center.x and center.y)in the current frame... 我疯了......我想在最后一帧中的(center.x和center.y)和当前帧中的(center.x和center.y)之间绘制一条线...

for(int j=0; j<Frames; j++){ 
       for( size_t i = 0; i < circles.size(); i++ ){
          Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
          cout << "center" << center.x << ", " << center.y << endl;
          Vector.push_back(std::make_pair(center.x,center.y));               
          int radius = cvRound(circles[i][2]);
          circle( dis, center, 3,  1 , -1, 8, 0 );            
          circle( dis, center, radius,  1  , 3, 8, 0 );  
          cv::Point2i p1(center.x, center.y);
          }    
    }
  cv::Mat base(100, 100, CV_32F);
      cv::Point2i p2(center.x, center.y);  //for the previous frame

      cv::line(base, p1, p2, cv::Scalar(1.0), 1, CV_AA);   // CV_AA == Anti-aliased flag

The first time when the code runs, p1 for the current frame will make! 代码第一次运行时,当前帧的p1将成为! but I do not know how to save this in a buffer to keep it and then when the code runs for the second time draw a line between these two points. 但我不知道如何将其保存在缓冲区以保持它,然后当代码第二次运行时在这两点之间画一条线。

thanks in advance.. 提前致谢..

If you declare a cv::Point globally: 如果全局声明一个cv :: Point:

cv::Point prevCenter;

and set it within your loop 并将其设置在循环中

prevCenter.x = center.x;
prevCenter.y = center.y;

You should be able to use it for drawing the line, if you add the cv::line statement within the loop of j (right now, it is outside the loop) 如果在j的循环中添加cv :: line语句(现在,它在循环之外),你应该可以用它来绘制线条

if (j > 0)
{
    cv::line(base, center, prevCenter, cv::Scalar(1.0), 1, CV_AA); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM