C++ 跟踪对象时如何绘制运动?
我使用网络摄像头和openCV检索每个帧并跟踪对象的位置 所以基本上,每一帧我有一个点。但是我怎样才能实时绘制运动图像呢 我是否需要计时器来记录特定时间内的几个点并画线 就像在while循环中一样,我只检索一帧,我不认为如果我在当前帧上画一条线,我仍然可以在下一帧中保持这条线。那么我应该如何显示运动呢C++ 跟踪对象时如何绘制运动?,c++,physics,C++,Physics,我使用网络摄像头和openCV检索每个帧并跟踪对象的位置 所以基本上,每一帧我有一个点。但是我怎样才能实时绘制运动图像呢 我是否需要计时器来记录特定时间内的几个点并画线 就像在while循环中一样,我只检索一帧,我不认为如果我在当前帧上画一条线,我仍然可以在下一帧中保持这条线。那么我应该如何显示运动呢 while( true ) { //Read the video stream capture = cvCaptureFromCAM(1);
while( true )
{
//Read the video stream
capture = cvCaptureFromCAM(1);
frame = cvQueryFrame( capture );
//Apply the classifier to the frame
detectAndDisplay(frame); // I got a point from this function
// waitkey enter
int c = waitKey(10);
if( (char)c == 27 ) { exit(0); }
}
使用矢量保持位置,然后在每一帧上绘制它们。 请注意,函数需要返回检测到的点。我改变了它的名字,因为它在那个点上画不出来。你可以稍后再解决
矢量轨迹;
Vec3b-霉色(100,0,0);
while(true)
{
//读取视频流
捕获=cvCaptureFromCAM(1);
帧=cvQueryFrame(捕获);
//将分类器应用于框架
CvPoint cur_pnt=detect(frame);//我从这个函数中得到了一个点
轨迹。推回(当前点);
//抽签。
for(int i=0;iThanks!但是IplImage没有at函数,所以我把它改为:for(int c=0;cimageData[traction[i].y*frame->widthStep+3*traction[i].x+c]=255;}没问题。如果这对你有效,请投票并接受。
vector<CvPoint> trajectory;
Vec3b mycolor(100,0,0);
while( true )
{
//Read the video stream
capture = cvCaptureFromCAM(1);
frame = cvQueryFrame( capture );
//Apply the classifier to the frame
CvPoint cur_pnt=detect(frame); // I got a point from this function
trajectory.push_back(cur_point);
//Draw points.
for (int i=0;i<trajectory.size();i++)
frame.at<Vec3b>(trajectory[i].x,trajectory[i].y)=mycolor;
// waitkey enter
int c = waitKey(10);
if( (char)c == 27 ) { exit(0); }
}