![](/img/trans.png)
[英]Tracking multiple moving objects with KalmanFilter in OpenCV/C++ - How to assign tracks individually to detected objects
[英]Tracking of multiple objects in openCV using C++
我正在OpenCV 中做一个项目,使用捕获的视频估计移动车辆的速度。 这里相机是静止的。 我已经使用质心和欧几里德距离估计了单个物体的速度。 现在的问题是,我不知道如何对多个对象执行相同的操作。 在这里,我需要计算 2 个后续帧之间对象的欧几里得距离。 如果有人愿意帮忙,我将不胜感激。
我创建了类-
class centroids
{
public:
vector<Point2f> ce;
vector<float> area;
};
centroids c[100];
这是我写的代码。 如果有人帮助我处理代码,我将不胜感激:
findContours( fgMaskMOG2,
contours,
hierarchy,
CV_RETR_CCOMP,
CV_CHAIN_APPROX_SIMPLE );
int morph_size = 6;
Mat element = getStructuringElement( MORPH_RECT,
Size( 2*morph_size+1, 2*morph_size+1 ),
Point( morph_size, morph_size ) );
Scalar color( 255, 255, 255 ); // color of the contour in the
//Draw the contour and rectangle
for( int i = 0; i < contours.size(); i++ )
{
drawContours( fgMaskMOG2,
contours,
i,
color,
CV_FILLED,
8,
hierarchy );
}
//imshow("morpho window",dst);
vector<Moments> mu( contours.size() );
vector<Point2f> mc( contours.size() );
vector<Point2f> m ;
vector<double> time;
vector<Point2f> centroid( mc.size() );
//vector< vector<Point> >::iterator itc = contours.begin();
// iterate through each contour.
double time1[1000];
for( int i = 0; i < contours.size(); i++ )
{
// Find the area of contour
double a = contourArea( contours[i], false );
if( a > 500 )
{
mu[i] = moments( contours[i], false );
mc[i] = Point2f( (mu[i].m10 / mu[i].m00), (mu[i].m01 / mu[i].m00) );
m.push_back( mc[i] );
Point2f diff;
double euclidian = 0;
for( int f = 0; f < m.size(); f++ )
{
if( k == 1 )
{
c[f].ce.push_back( m[f] );
cout << "cen" << c[f].ce << endl;
euclidian = 0;
}
else
{
c[f+1].ce.push_back( m[f] );
cout << "cent" << c[f+1].ce << endl;
diff = c[f].ce[f] - c[f-1].ce[f-1];
euclidian = abs( sqrt( (diff.x*diff.x) + (diff.y*diff.y) ) );
cout << "euclidian" << euclidian << endl;
}
}
cout << "\n centroid" << m << endl;
circle( fgMaskMOG2,
mc[i],
5,
Scalar( 0, 0, 255 ),
1,
8,
0 );
}
}
提前致谢 :)
只有在整个计算过程中车辆和摄像机之间的近似距离是恒定的,即车辆沿垂直于摄像机视线的直线移动时,您才能根据视频帧估计移动车辆的速度。 因此,如果摄像机从侧面看,所有车辆将处于不同的距离,并且对于多个车辆的计算将变得非常不准确。 即使车辆会重叠,它们的分割也会很困难。
您的计算可能在两种情况下起作用 -
http://www.codeproject.com/Articles/751744/Image-Segmentation-using-Unsupervised-Watershed-Al
如果您有完整的车辆视频序列,您可以在第一帧中自动分割出不同的车辆或手动识别它们,然后对这些识别出的物体应用运动跟踪。 您可以使用 Opencv 的运动分析功能和对象跟踪功能来执行此操作。 因此,您将获得每一帧中所有跟踪车辆的位置。 因此,您可以轻松运行和测试您的速度计算算法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.