|
@@ -23,7 +23,7 @@ TKalmanFilter::TKalmanFilter(
|
|
|
}
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
-void TKalmanFilter::CreateLinear(Point_t xy0, Point_t xyv0)
|
|
|
+void TKalmanFilter::CreateLinear(cv::Point3f xy0, cv::Point3f xyv0)
|
|
|
{
|
|
|
// We don't know acceleration, so, assume it to process noise.
|
|
|
// But we can guess, the range of acceleration values thich can be achieved by tracked object.
|
|
@@ -68,7 +68,6 @@ void TKalmanFilter::CreateLinear(Point_t xy0, Point_t xyv0)
|
|
|
|
|
|
m_initialized = true;
|
|
|
}
|
|
|
-
|
|
|
//---------------------------------------------------------------------------
|
|
|
void TKalmanFilter::CreateLinear(cv::Rect_<track_t> rect0, Point_t rectv0)
|
|
|
{
|
|
@@ -132,9 +131,96 @@ void TKalmanFilter::CreateLinear(cv::Rect_<track_t> rect0, Point_t rectv0)
|
|
|
|
|
|
m_initialized = true;
|
|
|
}
|
|
|
+//---------------------------------------------------------------------------
|
|
|
+void TKalmanFilter::CreateLinear3D(Rect3D rect0, cv::Point3f rectv0)
|
|
|
+{
|
|
|
+ // We don't know acceleration, so, assume it to process noise.
|
|
|
+ // But we can guess, the range of acceleration values thich can be achieved by tracked object.
|
|
|
+ // Process noise. (standard deviation of acceleration: m/s^2)
|
|
|
+ // shows, woh much target can accelerate.
|
|
|
+
|
|
|
+ // 14 state variables (x, y, z, width, height, length, yaw, d...), 7 measurements (x, y, z, width, height, length, yaw)
|
|
|
+ m_linearKalman.init(14, 7, 0, El_t);
|
|
|
+ // Transition cv::Matrix
|
|
|
+ m_linearKalman.transitionMatrix = (cv::Mat_<track_t>(14, 14) <<
|
|
|
+ 1, 0, 0, 0, 0, 0, 0, m_deltaTime, 0, 0, 0, 0, 0, 0,
|
|
|
+ 0, 1, 0, 0, 0, 0, 0, 0, m_deltaTime, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, m_deltaTime, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, m_deltaTime, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, m_deltaTime, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, m_deltaTime, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, m_deltaTime,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
|
|
|
+
|
|
|
+ // init...
|
|
|
+ m_linearKalman.statePre.at<track_t>(0) = rect0.center.x; // x
|
|
|
+ m_linearKalman.statePre.at<track_t>(1) = rect0.center.y; // y
|
|
|
+ m_linearKalman.statePre.at<track_t>(2) = rect0.center.z; // z
|
|
|
+ m_linearKalman.statePre.at<track_t>(3) = rect0.size.width; // width
|
|
|
+ m_linearKalman.statePre.at<track_t>(4) = rect0.size.height; // height
|
|
|
+ m_linearKalman.statePre.at<track_t>(5) = rect0.size.length; // length
|
|
|
+ m_linearKalman.statePre.at<track_t>(6) = rect0.yaw; // yaw
|
|
|
+ m_linearKalman.statePre.at<track_t>(7) = rectv0.x; // dx
|
|
|
+ m_linearKalman.statePre.at<track_t>(8) = rectv0.y; // dy
|
|
|
+ m_linearKalman.statePre.at<track_t>(9) = 0; // dz
|
|
|
+ m_linearKalman.statePre.at<track_t>(10) = 0; // dw
|
|
|
+ m_linearKalman.statePre.at<track_t>(11) = 0; // dh
|
|
|
+ m_linearKalman.statePre.at<track_t>(12) = 0; // dl
|
|
|
+ m_linearKalman.statePre.at<track_t>(13) = 0; // dyaw
|
|
|
+
|
|
|
+ m_linearKalman.statePost.at<track_t>(0) = rect0.center.x;
|
|
|
+ m_linearKalman.statePost.at<track_t>(1) = rect0.center.y;
|
|
|
+ m_linearKalman.statePost.at<track_t>(2) = rect0.center.z;
|
|
|
+ m_linearKalman.statePost.at<track_t>(3) = rect0.size.width;
|
|
|
+ m_linearKalman.statePost.at<track_t>(4) = rect0.size.height;
|
|
|
+ m_linearKalman.statePost.at<track_t>(5) = rect0.size.length;
|
|
|
+ m_linearKalman.statePost.at<track_t>(6) = rect0.yaw;
|
|
|
+ m_linearKalman.statePost.at<track_t>(7) = rectv0.x;
|
|
|
+ m_linearKalman.statePost.at<track_t>(8) = rectv0.y;
|
|
|
+ m_linearKalman.statePost.at<track_t>(9) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(10) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(11) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(12) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(13) = 0;
|
|
|
+
|
|
|
+ cv::setIdentity(m_linearKalman.measurementMatrix);
|
|
|
+
|
|
|
+ track_t n1 = pow(m_deltaTime, 4.f) / 4.f;
|
|
|
+ track_t n2 = pow(m_deltaTime, 3.f) / 2.f;
|
|
|
+ track_t n3 = pow(m_deltaTime, 2.f);
|
|
|
+ m_linearKalman.processNoiseCov = (cv::Mat_<track_t>(14, 14) <<
|
|
|
+ n1, 0, 0, 0, 0, 0, 0, n2, 0, 0, 0, 0, 0, 0,
|
|
|
+ 0, n1, 0, 0, 0, 0, 0, 0, n2, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, n1, 0, 0, 0, 0, 0, 0, n2, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, n1, 0, 0, 0, 0, 0, 0, n2, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, n1, 0, 0, 0, 0, 0, 0, n2, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, n1, 0, 0, 0, 0, 0, 0, n2, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, n1, 0, 0, 0, 0, 0, 0, n2,
|
|
|
+ n2, 0, 0, 0, 0, 0, 0, n3, 0, 0, 0, 0, 0, 0,
|
|
|
+ 0, n2, 0, 0, 0, 0, 0, 0, n3, 0, 0, 0, 0, 0,
|
|
|
+ 0, 0, n2, 0, 0, 0, 0, 0, 0, n3, 0, 0, 0, 0,
|
|
|
+ 0, 0, 0, n2, 0, 0, 0, 0, 0, 0, n3, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, n2, 0, 0, 0, 0, 0, 0, n3, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, n2, 0, 0, 0, 0, 0, 0, n3, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, n2, 0, 0, 0, 0, 0, 0, n3);
|
|
|
+
|
|
|
+ m_linearKalman.processNoiseCov *= m_accelNoiseMag;
|
|
|
+
|
|
|
+ cv::setIdentity(m_linearKalman.measurementNoiseCov, cv::Scalar::all(0.1));
|
|
|
+
|
|
|
+ cv::setIdentity(m_linearKalman.errorCovPost, cv::Scalar::all(.1));
|
|
|
+
|
|
|
+ m_initialized = true;
|
|
|
+}
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
-void TKalmanFilter::CreateLinearAcceleration(Point_t xy0, Point_t xyv0)
|
|
|
+void TKalmanFilter::CreateLinearAcceleration(cv::Point3f xy0, cv::Point3f xyv0)
|
|
|
{
|
|
|
// 6 state variables, 2 measurements
|
|
|
m_linearKalman.init(6, 2, 0, El_t);
|
|
@@ -186,9 +272,83 @@ void TKalmanFilter::CreateLinearAcceleration(Point_t xy0, Point_t xyv0)
|
|
|
|
|
|
m_initialized = true;
|
|
|
}
|
|
|
-
|
|
|
//---------------------------------------------------------------------------
|
|
|
void TKalmanFilter::CreateLinearAcceleration(cv::Rect_<track_t> rect0, Point_t rectv0)
|
|
|
+{
|
|
|
+ // 12 state variables (x, y, vx, vy, ax, ay, width, height, vw, vh, aw, ah), 4 measurements (x, y, width, height)
|
|
|
+ m_linearKalman.init(12, 4, 0, El_t);
|
|
|
+ // Transition cv::Matrix
|
|
|
+ const track_t dt = m_deltaTime;
|
|
|
+ const track_t dt2 = 0.5f * m_deltaTime * m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix = (cv::Mat_<track_t>(12, 12) <<
|
|
|
+ 1, 0, 0, 0, dt, 0, 0, 0, dt2, 0, dt2, 0,
|
|
|
+ 0, 1, 0, 0, 0, dt, 0, 0, 0, dt2, 0, dt2,
|
|
|
+ 0, 0, 1, 0, 0, 0, dt, 0, 0, 0, dt2, 0,
|
|
|
+ 0, 0, 0, 1, 0, 0, 0, dt, 0, 0, 0, dt2,
|
|
|
+ 0, 0, 0, 0, 1, 0, 0, 0, dt, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 1, 0, 0, 0, dt, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, dt, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, dt,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
|
|
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
|
|
|
+
|
|
|
+ // init...
|
|
|
+ m_linearKalman.statePre.at<track_t>(0) = rect0.x; // x
|
|
|
+ m_linearKalman.statePre.at<track_t>(1) = rect0.y; // y
|
|
|
+ m_linearKalman.statePre.at<track_t>(2) = rect0.width; // width
|
|
|
+ m_linearKalman.statePre.at<track_t>(3) = rect0.height; // height
|
|
|
+ m_linearKalman.statePre.at<track_t>(4) = rectv0.x; // dx
|
|
|
+ m_linearKalman.statePre.at<track_t>(5) = rectv0.y; // dy
|
|
|
+ m_linearKalman.statePre.at<track_t>(6) = 0; // dw
|
|
|
+ m_linearKalman.statePre.at<track_t>(7) = 0; // dh
|
|
|
+ m_linearKalman.statePre.at<track_t>(8) = 0; // ax
|
|
|
+ m_linearKalman.statePre.at<track_t>(9) = 0; // ay
|
|
|
+ m_linearKalman.statePre.at<track_t>(10) = 0; // aw
|
|
|
+ m_linearKalman.statePre.at<track_t>(11) = 0; // ah
|
|
|
+
|
|
|
+ m_linearKalman.statePost.at<track_t>(0) = rect0.x;
|
|
|
+ m_linearKalman.statePost.at<track_t>(1) = rect0.y;
|
|
|
+ m_linearKalman.statePost.at<track_t>(2) = rect0.width;
|
|
|
+ m_linearKalman.statePost.at<track_t>(3) = rect0.height;
|
|
|
+ m_linearKalman.statePost.at<track_t>(4) = rectv0.x;
|
|
|
+ m_linearKalman.statePost.at<track_t>(5) = rectv0.y;
|
|
|
+ m_linearKalman.statePost.at<track_t>(6) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(7) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(8) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(9) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(10) = 0;
|
|
|
+ m_linearKalman.statePost.at<track_t>(11) = 0;
|
|
|
+
|
|
|
+ cv::setIdentity(m_linearKalman.measurementMatrix);
|
|
|
+
|
|
|
+ track_t n1 = pow(m_deltaTime, 4.f) / 4.f;
|
|
|
+ track_t n2 = pow(m_deltaTime, 3.f) / 2.f;
|
|
|
+ track_t n3 = pow(m_deltaTime, 2.f);
|
|
|
+ m_linearKalman.processNoiseCov = (cv::Mat_<track_t>(12, 12) <<
|
|
|
+ n1, 0, 0, 0, n2, 0, 0, 0, n2, 0, n2,
|
|
|
+ 0, n1, 0, 0, 0, n2, 0, 0, 0, n2, 0, n2,
|
|
|
+ 0, 0, n1, 0, 0, 0, n2, 0, 0, 0, n2, 0,
|
|
|
+ 0, 0, 0, n1, 0, 0, 0, n2, 0, 0, 0, n2,
|
|
|
+ n2, 0, 0, 0, n3, 0, 0, 0, n3, 0, n3, 0,
|
|
|
+ 0, n2, 0, 0, 0, n3, 0, 0, 0, n3, 0, n3,
|
|
|
+ 0, 0, n2, 0, 0, 0, n3, 0, 0, 0, n3, 0,
|
|
|
+ 0, 0, 0, n2, 0, 0, 0, n3, 0, 0, 0, n3,
|
|
|
+ n2, 0, 0, 0, n3, 0, 0, 0, n3, 0, 0, 0,
|
|
|
+ 0, n2, 0, 0, 0, n3, 0, 0, 0, n3, 0, 0,
|
|
|
+ 0, 0, n2, 0, 0, 0, n3, 0, 0, 0, n3, 0,
|
|
|
+ 0, 0, 0, n2, 0, 0, 0, n3, 0, 0, 0, n3);
|
|
|
+
|
|
|
+ m_linearKalman.processNoiseCov *= m_accelNoiseMag;
|
|
|
+
|
|
|
+ cv::setIdentity(m_linearKalman.measurementNoiseCov, cv::Scalar::all(0.1));
|
|
|
+
|
|
|
+ cv::setIdentity(m_linearKalman.errorCovPost, cv::Scalar::all(.1));
|
|
|
+
|
|
|
+ m_initialized = true;
|
|
|
+}
|
|
|
+//---------------------------------------------------------------------------
|
|
|
+void TKalmanFilter::CreateLinearAcceleration3D(Rect3D rect0, cv::Point3f rectv0)
|
|
|
{
|
|
|
// 12 state variables (x, y, vx, vy, ax, ay, width, height, vw, vh, aw, ah), 4 measurements (x, y, width, height)
|
|
|
m_linearKalman.init(12, 4, 0, El_t);
|
|
@@ -209,10 +369,10 @@ void TKalmanFilter::CreateLinearAcceleration(cv::Rect_<track_t> rect0, Point_t r
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
|
|
|
|
|
|
// init...
|
|
|
- m_linearKalman.statePre.at<track_t>(0) = rect0.x; // x
|
|
|
- m_linearKalman.statePre.at<track_t>(1) = rect0.y; // y
|
|
|
- m_linearKalman.statePre.at<track_t>(2) = rect0.width; // width
|
|
|
- m_linearKalman.statePre.at<track_t>(3) = rect0.height; // height
|
|
|
+ m_linearKalman.statePre.at<track_t>(0) = rect0.center.x; // x
|
|
|
+ m_linearKalman.statePre.at<track_t>(1) = rect0.center.y; // y
|
|
|
+ m_linearKalman.statePre.at<track_t>(2) = rect0.size.width; // width
|
|
|
+ m_linearKalman.statePre.at<track_t>(3) = rect0.size.height; // height
|
|
|
m_linearKalman.statePre.at<track_t>(4) = rectv0.x; // dx
|
|
|
m_linearKalman.statePre.at<track_t>(5) = rectv0.y; // dy
|
|
|
m_linearKalman.statePre.at<track_t>(6) = 0; // dw
|
|
@@ -222,10 +382,10 @@ void TKalmanFilter::CreateLinearAcceleration(cv::Rect_<track_t> rect0, Point_t r
|
|
|
m_linearKalman.statePre.at<track_t>(10) = 0; // aw
|
|
|
m_linearKalman.statePre.at<track_t>(11) = 0; // ah
|
|
|
|
|
|
- m_linearKalman.statePost.at<track_t>(0) = rect0.x;
|
|
|
- m_linearKalman.statePost.at<track_t>(1) = rect0.y;
|
|
|
- m_linearKalman.statePost.at<track_t>(2) = rect0.width;
|
|
|
- m_linearKalman.statePost.at<track_t>(3) = rect0.height;
|
|
|
+ m_linearKalman.statePost.at<track_t>(0) = rect0.center.x;
|
|
|
+ m_linearKalman.statePost.at<track_t>(1) = rect0.center.y;
|
|
|
+ m_linearKalman.statePost.at<track_t>(2) = rect0.size.width;
|
|
|
+ m_linearKalman.statePost.at<track_t>(3) = rect0.size.height;
|
|
|
m_linearKalman.statePost.at<track_t>(4) = rectv0.x;
|
|
|
m_linearKalman.statePost.at<track_t>(5) = rectv0.y;
|
|
|
m_linearKalman.statePost.at<track_t>(6) = 0;
|
|
@@ -263,275 +423,8 @@ void TKalmanFilter::CreateLinearAcceleration(cv::Rect_<track_t> rect0, Point_t r
|
|
|
m_initialized = true;
|
|
|
}
|
|
|
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
//---------------------------------------------------------------------------
|
|
|
-class AcceleratedModel: public cv::tracking::UkfSystemModel
|
|
|
-{
|
|
|
-public:
|
|
|
- AcceleratedModel(track_t deltaTime, bool rectModel)
|
|
|
- :
|
|
|
- cv::tracking::UkfSystemModel(),
|
|
|
- m_deltaTime(deltaTime),
|
|
|
- m_rectModel(rectModel)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- void stateConversionFunction(const cv::Mat& x_k, const cv::Mat& u_k, const cv::Mat& v_k, cv::Mat& x_kplus1)
|
|
|
- {
|
|
|
- track_t x0 = x_k.at<track_t>(0, 0);
|
|
|
- track_t y0 = x_k.at<track_t>(1, 0);
|
|
|
- track_t vx0 = x_k.at<track_t>(2, 0);
|
|
|
- track_t vy0 = x_k.at<track_t>(3, 0);
|
|
|
- track_t ax0 = x_k.at<track_t>(4, 0);
|
|
|
- track_t ay0 = x_k.at<track_t>(5, 0);
|
|
|
-
|
|
|
- x_kplus1.at<track_t>(0, 0) = x0 + vx0 * m_deltaTime + ax0 * sqr(m_deltaTime) / 2;
|
|
|
- x_kplus1.at<track_t>(1, 0) = y0 + vy0 * m_deltaTime + ay0 * sqr(m_deltaTime) / 2;
|
|
|
- x_kplus1.at<track_t>(2, 0) = vx0 + ax0 * m_deltaTime;
|
|
|
- x_kplus1.at<track_t>(3, 0) = vy0 + ay0 * m_deltaTime;
|
|
|
- x_kplus1.at<track_t>(4, 0) = ax0;
|
|
|
- x_kplus1.at<track_t>(5, 0) = ay0;
|
|
|
-
|
|
|
- if (m_rectModel)
|
|
|
- {
|
|
|
- x_kplus1.at<track_t>(6, 0) = x_k.at<track_t>(6, 0);
|
|
|
- x_kplus1.at<track_t>(7, 0) = x_k.at<track_t>(7, 0);
|
|
|
- }
|
|
|
-
|
|
|
- if (v_k.size() == u_k.size())
|
|
|
- {
|
|
|
- x_kplus1 += v_k + u_k;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- x_kplus1 += v_k;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- void measurementFunction(const cv::Mat& x_k, const cv::Mat& n_k, cv::Mat& z_k)
|
|
|
- {
|
|
|
- track_t x0 = x_k.at<track_t>(0, 0);
|
|
|
- track_t y0 = x_k.at<track_t>(1, 0);
|
|
|
- track_t vx0 = x_k.at<track_t>(2, 0);
|
|
|
- track_t vy0 = x_k.at<track_t>(3, 0);
|
|
|
- track_t ax0 = x_k.at<track_t>(4, 0);
|
|
|
- track_t ay0 = x_k.at<track_t>(5, 0);
|
|
|
-
|
|
|
- z_k.at<track_t>(0, 0) = x0 + vx0 * m_deltaTime + ax0 * sqr(m_deltaTime) / 2 + n_k.at<track_t>(0, 0);
|
|
|
- z_k.at<track_t>(1, 0) = y0 + vy0 * m_deltaTime + ay0 * sqr(m_deltaTime) / 2 + n_k.at<track_t>(1, 0);
|
|
|
-
|
|
|
- if (m_rectModel)
|
|
|
- {
|
|
|
- z_k.at<track_t>(2, 0) = x_k.at<track_t>(6, 0);
|
|
|
- z_k.at<track_t>(3, 0) = x_k.at<track_t>(7, 0);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-private:
|
|
|
- track_t m_deltaTime;
|
|
|
- bool m_rectModel;
|
|
|
-};
|
|
|
-
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-void TKalmanFilter::CreateUnscented(Point_t xy0, Point_t xyv0)
|
|
|
-{
|
|
|
- int MP = 2;
|
|
|
- int DP = 6;
|
|
|
- int CP = 0;
|
|
|
-
|
|
|
- cv::Mat processNoiseCov = cv::Mat::zeros(DP, DP, Mat_t(1));
|
|
|
- processNoiseCov.at<track_t>(0, 0) = 1e-14f;
|
|
|
- processNoiseCov.at<track_t>(1, 1) = 1e-14f;
|
|
|
- processNoiseCov.at<track_t>(2, 2) = 1e-6f;
|
|
|
- processNoiseCov.at<track_t>(3, 3) = 1e-6f;
|
|
|
- processNoiseCov.at<track_t>(4, 4) = 1e-6f;
|
|
|
- processNoiseCov.at<track_t>(5, 5) = 1e-6f;
|
|
|
-
|
|
|
- cv::Mat measurementNoiseCov = cv::Mat::zeros(MP, MP, Mat_t(1));
|
|
|
- measurementNoiseCov.at<track_t>(0, 0) = 1e-6f;
|
|
|
- measurementNoiseCov.at<track_t>(1, 1) = 1e-6f;
|
|
|
-
|
|
|
- cv::Mat initState(DP, 1, Mat_t(1));
|
|
|
- initState.at<track_t>(0, 0) = xy0.x;
|
|
|
- initState.at<track_t>(1, 0) = xy0.y;
|
|
|
- initState.at<track_t>(2, 0) = xyv0.x;
|
|
|
- initState.at<track_t>(3, 0) = xyv0.y;
|
|
|
- initState.at<track_t>(4, 0) = 0;
|
|
|
- initState.at<track_t>(5, 0) = 0;
|
|
|
-
|
|
|
- cv::Mat P = 1e-6f * cv::Mat::eye(DP, DP, Mat_t(1));
|
|
|
-
|
|
|
- cv::Ptr<AcceleratedModel> model(new AcceleratedModel(m_deltaTime, false));
|
|
|
- cv::tracking::UnscentedKalmanFilterParams params(DP, MP, CP, 0, 0, model);
|
|
|
- params.dataType = Mat_t(1);
|
|
|
- params.stateInit = initState.clone();
|
|
|
- params.errorCovInit = P.clone();
|
|
|
- params.measurementNoiseCov = measurementNoiseCov.clone();
|
|
|
- params.processNoiseCov = processNoiseCov.clone();
|
|
|
-
|
|
|
- params.alpha = 1.0;
|
|
|
- params.beta = 2.0;
|
|
|
- params.k = -2.0;
|
|
|
-
|
|
|
- m_uncsentedKalman = cv::tracking::createUnscentedKalmanFilter(params);
|
|
|
-
|
|
|
- m_initialized = true;
|
|
|
-}
|
|
|
-
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-void TKalmanFilter::CreateUnscented(cv::Rect_<track_t> rect0, Point_t rectv0)
|
|
|
-{
|
|
|
- int MP = 4;
|
|
|
- int DP = 8;
|
|
|
- int CP = 0;
|
|
|
-
|
|
|
- cv::Mat processNoiseCov = cv::Mat::zeros(DP, DP, Mat_t(1));
|
|
|
- processNoiseCov.at<track_t>(0, 0) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(1, 1) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(2, 2) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(3, 3) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(4, 4) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(5, 5) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(6, 6) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(7, 7) = 1e-3f;
|
|
|
-
|
|
|
- cv::Mat measurementNoiseCov = cv::Mat::zeros(MP, MP, Mat_t(1));
|
|
|
- measurementNoiseCov.at<track_t>(0, 0) = 1e-3f;
|
|
|
- measurementNoiseCov.at<track_t>(1, 1) = 1e-3f;
|
|
|
- measurementNoiseCov.at<track_t>(2, 2) = 1e-3f;
|
|
|
- measurementNoiseCov.at<track_t>(3, 3) = 1e-3f;
|
|
|
-
|
|
|
- cv::Mat initState(DP, 1, Mat_t(1));
|
|
|
- initState.at<track_t>(0, 0) = rect0.x;
|
|
|
- initState.at<track_t>(1, 0) = rect0.y;
|
|
|
- initState.at<track_t>(2, 0) = rectv0.x;
|
|
|
- initState.at<track_t>(3, 0) = rectv0.y;
|
|
|
- initState.at<track_t>(4, 0) = 0;
|
|
|
- initState.at<track_t>(5, 0) = 0;
|
|
|
- initState.at<track_t>(6, 0) = rect0.width;
|
|
|
- initState.at<track_t>(7, 0) = rect0.height;
|
|
|
-
|
|
|
- cv::Mat P = 1e-3f * cv::Mat::eye(DP, DP, Mat_t(1));
|
|
|
-
|
|
|
- cv::Ptr<AcceleratedModel> model(new AcceleratedModel(m_deltaTime, true));
|
|
|
- cv::tracking::UnscentedKalmanFilterParams params(DP, MP, CP, 0, 0, model);
|
|
|
- params.dataType = Mat_t(1);
|
|
|
- params.stateInit = initState.clone();
|
|
|
- params.errorCovInit = P.clone();
|
|
|
- params.measurementNoiseCov = measurementNoiseCov.clone();
|
|
|
- params.processNoiseCov = processNoiseCov.clone();
|
|
|
-
|
|
|
- params.alpha = 1;
|
|
|
- params.beta = 2.0;
|
|
|
- params.k = -2.0;
|
|
|
-
|
|
|
- m_uncsentedKalman = cv::tracking::createUnscentedKalmanFilter(params);
|
|
|
-
|
|
|
- m_initialized = true;
|
|
|
-}
|
|
|
-
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-void TKalmanFilter::CreateAugmentedUnscented(Point_t xy0, Point_t xyv0)
|
|
|
-{
|
|
|
- int MP = 2;
|
|
|
- int DP = 6;
|
|
|
- int CP = 0;
|
|
|
-
|
|
|
- cv::Mat processNoiseCov = cv::Mat::zeros(DP, DP, Mat_t(1));
|
|
|
- processNoiseCov.at<track_t>(0, 0) = 1e-14f;
|
|
|
- processNoiseCov.at<track_t>(1, 1) = 1e-14f;
|
|
|
- processNoiseCov.at<track_t>(2, 2) = 1e-6f;
|
|
|
- processNoiseCov.at<track_t>(3, 3) = 1e-6f;
|
|
|
- processNoiseCov.at<track_t>(4, 4) = 1e-6f;
|
|
|
- processNoiseCov.at<track_t>(5, 5) = 1e-6f;
|
|
|
-
|
|
|
- cv::Mat measurementNoiseCov = cv::Mat::zeros(MP, MP, Mat_t(1));
|
|
|
- measurementNoiseCov.at<track_t>(0, 0) = 1e-6f;
|
|
|
- measurementNoiseCov.at<track_t>(1, 1) = 1e-6f;
|
|
|
-
|
|
|
- cv::Mat initState(DP, 1, Mat_t(1));
|
|
|
- initState.at<track_t>(0, 0) = xy0.x;
|
|
|
- initState.at<track_t>(1, 0) = xy0.y;
|
|
|
- initState.at<track_t>(2, 0) = xyv0.x;
|
|
|
- initState.at<track_t>(3, 0) = xyv0.y;
|
|
|
- initState.at<track_t>(4, 0) = 0;
|
|
|
- initState.at<track_t>(5, 0) = 0;
|
|
|
-
|
|
|
- cv::Mat P = 1e-6f * cv::Mat::eye(DP, DP, Mat_t(1));
|
|
|
-
|
|
|
- cv::Ptr<AcceleratedModel> model(new AcceleratedModel(m_deltaTime, false));
|
|
|
- cv::tracking::AugmentedUnscentedKalmanFilterParams params(DP, MP, CP, 0, 0, model);
|
|
|
- params.dataType = Mat_t(1);
|
|
|
- params.stateInit = initState.clone();
|
|
|
- params.errorCovInit = P.clone();
|
|
|
- params.measurementNoiseCov = measurementNoiseCov.clone();
|
|
|
- params.processNoiseCov = processNoiseCov.clone();
|
|
|
-
|
|
|
- params.alpha = 1;
|
|
|
- params.beta = 2.0;
|
|
|
- params.k = -2.0;
|
|
|
-
|
|
|
- m_uncsentedKalman = cv::tracking::createAugmentedUnscentedKalmanFilter(params);
|
|
|
-
|
|
|
- m_initialized = true;
|
|
|
-}
|
|
|
-
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-void TKalmanFilter::CreateAugmentedUnscented(cv::Rect_<track_t> rect0, Point_t rectv0)
|
|
|
-{
|
|
|
- int MP = 4;
|
|
|
- int DP = 8;
|
|
|
- int CP = 0;
|
|
|
-
|
|
|
- cv::Mat processNoiseCov = cv::Mat::zeros(DP, DP, Mat_t(1));
|
|
|
- processNoiseCov.at<track_t>(0, 0) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(1, 1) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(2, 2) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(3, 3) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(4, 4) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(5, 5) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(6, 6) = 1e-3f;
|
|
|
- processNoiseCov.at<track_t>(7, 7) = 1e-3f;
|
|
|
-
|
|
|
- cv::Mat measurementNoiseCov = cv::Mat::zeros(MP, MP, Mat_t(1));
|
|
|
- measurementNoiseCov.at<track_t>(0, 0) = 1e-3f;
|
|
|
- measurementNoiseCov.at<track_t>(1, 1) = 1e-3f;
|
|
|
- measurementNoiseCov.at<track_t>(2, 2) = 1e-3f;
|
|
|
- measurementNoiseCov.at<track_t>(3, 3) = 1e-3f;
|
|
|
-
|
|
|
- cv::Mat initState(DP, 1, Mat_t(1));
|
|
|
- initState.at<track_t>(0, 0) = rect0.x;
|
|
|
- initState.at<track_t>(1, 0) = rect0.y;
|
|
|
- initState.at<track_t>(2, 0) = rectv0.x;
|
|
|
- initState.at<track_t>(3, 0) = rectv0.y;
|
|
|
- initState.at<track_t>(4, 0) = 0;
|
|
|
- initState.at<track_t>(5, 0) = 0;
|
|
|
- initState.at<track_t>(6, 0) = rect0.width;
|
|
|
- initState.at<track_t>(7, 0) = rect0.height;
|
|
|
-
|
|
|
- cv::Mat P = 1e-3f * cv::Mat::eye(DP, DP, Mat_t(1));
|
|
|
-
|
|
|
- cv::Ptr<AcceleratedModel> model(new AcceleratedModel(m_deltaTime, true));
|
|
|
- cv::tracking::AugmentedUnscentedKalmanFilterParams params(DP, MP, CP, 0, 0, model);
|
|
|
- params.dataType = Mat_t(1);
|
|
|
- params.stateInit = initState.clone();
|
|
|
- params.errorCovInit = P.clone();
|
|
|
- params.measurementNoiseCov = measurementNoiseCov.clone();
|
|
|
- params.processNoiseCov = processNoiseCov.clone();
|
|
|
-
|
|
|
- params.alpha = 1;
|
|
|
- params.beta = 2.0;
|
|
|
- params.k = -2.0;
|
|
|
-
|
|
|
- m_uncsentedKalman = cv::tracking::createAugmentedUnscentedKalmanFilter(params);
|
|
|
-
|
|
|
- m_initialized = true;
|
|
|
-}
|
|
|
-#endif
|
|
|
-
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-Point_t TKalmanFilter::GetPointPrediction()
|
|
|
+cv::Point3f TKalmanFilter::GetPointPrediction()
|
|
|
{
|
|
|
if (m_initialized)
|
|
|
{
|
|
@@ -542,19 +435,9 @@ Point_t TKalmanFilter::GetPointPrediction()
|
|
|
case tracking::KalmanLinear:
|
|
|
prediction = m_linearKalman.predict();
|
|
|
break;
|
|
|
-
|
|
|
- case tracking::KalmanUnscented:
|
|
|
- case tracking::KalmanAugmentedUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- prediction = m_uncsentedKalman->predict();
|
|
|
-#else
|
|
|
- prediction = m_linearKalman.predict();
|
|
|
- std::cerr << "UnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
- break;
|
|
|
}
|
|
|
|
|
|
- m_lastPointResult = Point_t(prediction.at<track_t>(0), prediction.at<track_t>(1));
|
|
|
+ m_lastPointResult = cv::Point3f(prediction.at<track_t>(0), prediction.at<track_t>(1), prediction.at<track_t>(2));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -564,7 +447,7 @@ Point_t TKalmanFilter::GetPointPrediction()
|
|
|
}
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
-Point_t TKalmanFilter::Update(Point_t pt, bool dataCorrect)
|
|
|
+cv::Point3f TKalmanFilter::Update(cv::Point3f pt, bool dataCorrect)
|
|
|
{
|
|
|
if (!m_initialized)
|
|
|
{
|
|
@@ -583,8 +466,8 @@ Point_t TKalmanFilter::Update(Point_t pt, bool dataCorrect)
|
|
|
track_t ky = 0;
|
|
|
track_t by = 0;
|
|
|
get_lin_regress_params(m_initialPoints, 0, MIN_INIT_VALS, kx, bx, ky, by);//predict p,v
|
|
|
- Point_t xy0(kx * (MIN_INIT_VALS - 1) + bx, ky * (MIN_INIT_VALS - 1) + by);
|
|
|
- Point_t xyv0(kx, ky);
|
|
|
+ cv::Point3f xy0(kx * (MIN_INIT_VALS - 1) + bx, ky * (MIN_INIT_VALS - 1) + by, m_lastPointResult.z);
|
|
|
+ cv::Point3f xyv0(kx, ky,0);
|
|
|
|
|
|
switch (m_type)
|
|
|
{
|
|
@@ -594,30 +477,6 @@ Point_t TKalmanFilter::Update(Point_t pt, bool dataCorrect)
|
|
|
else
|
|
|
CreateLinear(xy0, xyv0);
|
|
|
break;
|
|
|
-
|
|
|
- case tracking::KalmanUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- CreateUnscented(xy0, xyv0);
|
|
|
-#else
|
|
|
- if (m_useAcceleration)
|
|
|
- CreateLinearAcceleration(xy0, xyv0);
|
|
|
- else
|
|
|
- CreateLinear(xy0, xyv0);
|
|
|
- std::cerr << "UnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
- break;
|
|
|
-
|
|
|
- case tracking::KalmanAugmentedUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- CreateAugmentedUnscented(xy0, xyv0);
|
|
|
-#else
|
|
|
- if (m_useAcceleration)
|
|
|
- CreateLinearAcceleration(xy0, xyv0);
|
|
|
- else
|
|
|
- CreateLinear(xy0, xyv0);
|
|
|
- std::cerr << "AugmentedUnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
- break;
|
|
|
}
|
|
|
m_lastDist = 0;
|
|
|
}
|
|
@@ -663,16 +522,6 @@ Point_t TKalmanFilter::Update(Point_t pt, bool dataCorrect)
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- case tracking::KalmanUnscented:
|
|
|
- case tracking::KalmanAugmentedUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- estimated = m_uncsentedKalman->correct(measurement);
|
|
|
-#else
|
|
|
- estimated = m_linearKalman.correct(measurement);
|
|
|
- std::cerr << "UnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
- break;
|
|
|
}
|
|
|
|
|
|
m_lastPointResult.x = estimated.at<track_t>(0); //update using measurements
|
|
@@ -687,7 +536,6 @@ Point_t TKalmanFilter::Update(Point_t pt, bool dataCorrect)
|
|
|
}
|
|
|
return m_lastPointResult;
|
|
|
}
|
|
|
-
|
|
|
//---------------------------------------------------------------------------
|
|
|
cv::Rect TKalmanFilter::GetRectPrediction()
|
|
|
{
|
|
@@ -700,16 +548,6 @@ cv::Rect TKalmanFilter::GetRectPrediction()
|
|
|
case tracking::KalmanLinear:
|
|
|
prediction = m_linearKalman.predict();
|
|
|
break;
|
|
|
-
|
|
|
- case tracking::KalmanUnscented:
|
|
|
- case tracking::KalmanAugmentedUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- prediction = m_uncsentedKalman->predict();
|
|
|
-#else
|
|
|
- prediction = m_linearKalman.predict();
|
|
|
- std::cerr << "UnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
- break;
|
|
|
}
|
|
|
|
|
|
m_lastRectResult = cv::Rect_<track_t>(prediction.at<track_t>(0), prediction.at<track_t>(1), prediction.at<track_t>(2), prediction.at<track_t>(3));
|
|
@@ -761,34 +599,10 @@ cv::Rect TKalmanFilter::Update(cv::Rect rect, bool dataCorrect)
|
|
|
switch (m_type)
|
|
|
{
|
|
|
case tracking::KalmanLinear:
|
|
|
- if (m_useAcceleration)
|
|
|
- CreateLinearAcceleration(rect0, rectv0);
|
|
|
- else
|
|
|
- CreateLinear(rect0, rectv0);
|
|
|
- break;
|
|
|
-
|
|
|
- case tracking::KalmanUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- CreateUnscented(rect0, rectv0);
|
|
|
-#else
|
|
|
- if (m_useAcceleration)
|
|
|
- CreateLinearAcceleration(rect0, rectv0);
|
|
|
- else
|
|
|
- CreateLinear(rect0, rectv0);
|
|
|
- std::cerr << "UnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
- break;
|
|
|
-
|
|
|
- case tracking::KalmanAugmentedUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- CreateAugmentedUnscented(rect0, rectv0);
|
|
|
-#else
|
|
|
- if (m_useAcceleration)
|
|
|
- CreateLinearAcceleration(rect0, rectv0);
|
|
|
- else
|
|
|
- CreateLinear(rect0, rectv0);
|
|
|
- std::cerr << "AugmentedUnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
+ if (m_useAcceleration)
|
|
|
+ CreateLinearAcceleration(rect0, rectv0);
|
|
|
+ else
|
|
|
+ CreateLinear(rect0, rectv0);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -824,10 +638,167 @@ cv::Rect TKalmanFilter::Update(cv::Rect rect, bool dataCorrect)
|
|
|
m_lastRectResult.width = estimated.at<track_t>(2);
|
|
|
m_lastRectResult.height = estimated.at<track_t>(3);
|
|
|
|
|
|
+ // Inertia correction
|
|
|
+ if (!m_useAcceleration)
|
|
|
+ {
|
|
|
+ track_t currDist = sqrtf(sqr(estimated.at<track_t>(0) - rect.x) + sqr(estimated.at<track_t>(1) - rect.y) + sqr(estimated.at<track_t>(2) - rect.width) + sqr(estimated.at<track_t>(3) - rect.height));
|
|
|
+ if (currDist > m_lastDist)
|
|
|
+ {
|
|
|
+ m_deltaTime = std::min(m_deltaTime + m_deltaStep, m_deltaTimeMax);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ m_deltaTime = std::max(m_deltaTime - m_deltaStep, m_deltaTimeMin);
|
|
|
+ }
|
|
|
+ m_lastDist = currDist;
|
|
|
+
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(0, 4) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(1, 5) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(2, 6) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(3, 7) = m_deltaTime;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (dataCorrect)
|
|
|
+ {
|
|
|
+ m_lastRectResult.x = static_cast<track_t>(rect.x);
|
|
|
+ m_lastRectResult.y = static_cast<track_t>(rect.y);
|
|
|
+ m_lastRectResult.width = static_cast<track_t>(rect.width);
|
|
|
+ m_lastRectResult.height = static_cast<track_t>(rect.height);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return cv::Rect(static_cast<int>(m_lastRectResult.x), static_cast<int>(m_lastRectResult.y), static_cast<int>(m_lastRectResult.width), static_cast<int>(m_lastRectResult.height));
|
|
|
+}
|
|
|
+//---------------------------------------------------------------------------
|
|
|
+Rect3D TKalmanFilter::GetRect3DPrediction()
|
|
|
+{
|
|
|
+ if (m_initialized)
|
|
|
+ {
|
|
|
+ cv::Mat prediction;
|
|
|
+
|
|
|
+ switch (m_type)
|
|
|
+ {
|
|
|
+ case tracking::KalmanLinear:
|
|
|
+ prediction = m_linearKalman.predict();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_lastRect3DResult = Rect3D(cv::Point3f(prediction.at<track_t>(0), prediction.at<track_t>(1), prediction.at<track_t>(2)), Size3D(prediction.at<track_t>(3), prediction.at<track_t>(4), prediction.at<track_t>(5)), prediction.at<track_t>(6));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ return m_lastRect3DResult;
|
|
|
+}
|
|
|
+
|
|
|
+//---------------------------------------------------------------------------
|
|
|
+Rect3D TKalmanFilter::Update(Rect3D rect, bool dataCorrect)
|
|
|
+{
|
|
|
+ if (!m_initialized)
|
|
|
+ {
|
|
|
+ if (m_initialRect3Ds.size() < MIN_INIT_VALS)
|
|
|
+ {
|
|
|
+ if (dataCorrect)
|
|
|
+ {
|
|
|
+ m_initialRect3Ds.push_back(rect);
|
|
|
+ m_lastRect3DResult.center.x = static_cast<track_t>(rect.center.x);
|
|
|
+ m_lastRect3DResult.center.y = static_cast<track_t>(rect.center.y);
|
|
|
+ m_lastRect3DResult.center.z = static_cast<track_t>(rect.center.z);
|
|
|
+ m_lastRect3DResult.size.width = static_cast<track_t>(rect.size.width);
|
|
|
+ m_lastRect3DResult.size.height = static_cast<track_t>(rect.size.height);
|
|
|
+ m_lastRect3DResult.size.length = static_cast<track_t>(rect.size.length);
|
|
|
+ m_lastRect3DResult.yaw = static_cast<track_t>(rect.yaw);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (m_initialRect3Ds.size() == MIN_INIT_VALS)
|
|
|
+ {
|
|
|
+ std::vector<Point_t> initialPoints;
|
|
|
+ cv::Point3f averageSize(0, 0, 0);
|
|
|
+ float averageZ = 0;
|
|
|
+ float averageYaw = 0;
|
|
|
+ for (const auto& r : m_initialRect3Ds)
|
|
|
+ {
|
|
|
+ initialPoints.emplace_back(static_cast<track_t>(r.center.x), static_cast<track_t>(r.center.y));
|
|
|
+ averageZ += r.center.z;
|
|
|
+ averageSize.x += r.size.width;
|
|
|
+ averageSize.y += r.size.height;
|
|
|
+ averageSize.z += r.size.length;
|
|
|
+ averageYaw += r.yaw;
|
|
|
+ }
|
|
|
+ averageZ /= MIN_INIT_VALS;
|
|
|
+ averageSize.x /= MIN_INIT_VALS;
|
|
|
+ averageSize.y /= MIN_INIT_VALS;
|
|
|
+ averageSize.z /= MIN_INIT_VALS;
|
|
|
+ averageYaw /= MIN_INIT_VALS;
|
|
|
+
|
|
|
+ track_t kx = 0;
|
|
|
+ track_t bx = 0;
|
|
|
+ track_t ky = 0;
|
|
|
+ track_t by = 0;
|
|
|
+ get_lin_regress_params(initialPoints, 0, MIN_INIT_VALS, kx, bx, ky, by);
|
|
|
+ Rect3D rect0(cv::Point3f(kx * (MIN_INIT_VALS - 1) + bx, ky * (MIN_INIT_VALS - 1) + by, averageZ), Size3D(averageSize.x, averageSize.y,averageSize.z), averageYaw);
|
|
|
+ cv::Point3f rectv0(kx, ky, 0);
|
|
|
+
|
|
|
+ switch (m_type)
|
|
|
+ {
|
|
|
+ case tracking::KalmanLinear:
|
|
|
+ if (m_useAcceleration)
|
|
|
+ CreateLinearAcceleration3D(rect0, rectv0);
|
|
|
+ else
|
|
|
+ CreateLinear3D(rect0, rectv0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (m_initialized)
|
|
|
+ {
|
|
|
+ cv::Mat measurement(7, 1, Mat_t(1));
|
|
|
+ if (!dataCorrect)
|
|
|
+ {
|
|
|
+ measurement.at<track_t>(0) = m_lastRect3DResult.center.x; // update using prediction
|
|
|
+ measurement.at<track_t>(1) = m_lastRect3DResult.center.y;
|
|
|
+ measurement.at<track_t>(2) = m_lastRect3DResult.center.z;
|
|
|
+ measurement.at<track_t>(3) = m_lastRect3DResult.size.width;
|
|
|
+ measurement.at<track_t>(4) = m_lastRect3DResult.size.height;
|
|
|
+ measurement.at<track_t>(5) = m_lastRect3DResult.size.length;
|
|
|
+ measurement.at<track_t>(6) = m_lastRect3DResult.yaw;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ measurement.at<track_t>(0) = static_cast<track_t>(rect.center.x); // update using measurements
|
|
|
+ measurement.at<track_t>(1) = static_cast<track_t>(rect.center.y);
|
|
|
+ measurement.at<track_t>(2) = static_cast<track_t>(rect.center.z);
|
|
|
+ measurement.at<track_t>(3) = static_cast<track_t>(rect.size.width);
|
|
|
+ measurement.at<track_t>(4) = static_cast<track_t>(rect.size.height);
|
|
|
+ measurement.at<track_t>(5) = static_cast<track_t>(rect.size.length);
|
|
|
+ measurement.at<track_t>(6) = static_cast<track_t>(rect.yaw);
|
|
|
+ }
|
|
|
+ // Correction
|
|
|
+ cv::Mat estimated;
|
|
|
+ switch (m_type)
|
|
|
+ {
|
|
|
+ case tracking::KalmanLinear:
|
|
|
+ {
|
|
|
+ estimated = m_linearKalman.correct(measurement);
|
|
|
+
|
|
|
+ m_lastRect3DResult.center.x = estimated.at<track_t>(0); //update using measurements
|
|
|
+ m_lastRect3DResult.center.y = estimated.at<track_t>(1);
|
|
|
+ m_lastRect3DResult.center.z = estimated.at<track_t>(2);
|
|
|
+ m_lastRect3DResult.size.width = estimated.at<track_t>(3);
|
|
|
+ m_lastRect3DResult.size.height = estimated.at<track_t>(4);
|
|
|
+ m_lastRect3DResult.size.length = estimated.at<track_t>(5);
|
|
|
+ m_lastRect3DResult.yaw = estimated.at<track_t>(6);
|
|
|
+
|
|
|
// Inertia correction
|
|
|
if (!m_useAcceleration)
|
|
|
{
|
|
|
- track_t currDist = sqrtf(sqr(estimated.at<track_t>(0) - rect.x) + sqr(estimated.at<track_t>(1) - rect.y) + sqr(estimated.at<track_t>(2) - rect.width) + sqr(estimated.at<track_t>(3) - rect.height));
|
|
|
+ track_t currDist = sqrtf(sqr(estimated.at<track_t>(0) - rect.center.x) + sqr(estimated.at<track_t>(1) - rect.center.y)+ sqr(estimated.at<track_t>(2) - rect.center.z) + sqr(estimated.at<track_t>(3) - rect.size.width) + sqr(estimated.at<track_t>(4) - rect.size.height) + sqr(estimated.at<track_t>(5) - rect.size.length) + sqr(estimated.at<track_t>(6) - rect.yaw));
|
|
|
if (currDist > m_lastDist)
|
|
|
{
|
|
|
m_deltaTime = std::min(m_deltaTime + m_deltaStep, m_deltaTimeMax);
|
|
@@ -838,46 +809,32 @@ cv::Rect TKalmanFilter::Update(cv::Rect rect, bool dataCorrect)
|
|
|
}
|
|
|
m_lastDist = currDist;
|
|
|
|
|
|
- m_linearKalman.transitionMatrix.at<track_t>(0, 4) = m_deltaTime;
|
|
|
- m_linearKalman.transitionMatrix.at<track_t>(1, 5) = m_deltaTime;
|
|
|
- m_linearKalman.transitionMatrix.at<track_t>(2, 6) = m_deltaTime;
|
|
|
- m_linearKalman.transitionMatrix.at<track_t>(3, 7) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(0, 7) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(1, 8) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(2, 9) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(3, 10) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(4, 11) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(5, 12) = m_deltaTime;
|
|
|
+ m_linearKalman.transitionMatrix.at<track_t>(6, 13) = m_deltaTime;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
- case tracking::KalmanUnscented:
|
|
|
- case tracking::KalmanAugmentedUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- estimated = m_uncsentedKalman->correct(measurement);
|
|
|
-
|
|
|
- m_lastRectResult.x = estimated.at<track_t>(0); //update using measurements
|
|
|
- m_lastRectResult.y = estimated.at<track_t>(1);
|
|
|
- m_lastRectResult.width = estimated.at<track_t>(6);
|
|
|
- m_lastRectResult.height = estimated.at<track_t>(7);
|
|
|
-#else
|
|
|
- estimated = m_linearKalman.correct(measurement);
|
|
|
-
|
|
|
- m_lastRectResult.x = estimated.at<track_t>(0); //update using measurements
|
|
|
- m_lastRectResult.y = estimated.at<track_t>(1);
|
|
|
- m_lastRectResult.width = estimated.at<track_t>(2);
|
|
|
- m_lastRectResult.height = estimated.at<track_t>(3);
|
|
|
- std::cerr << "UnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (dataCorrect)
|
|
|
{
|
|
|
- m_lastRectResult.x = static_cast<track_t>(rect.x);
|
|
|
- m_lastRectResult.y = static_cast<track_t>(rect.y);
|
|
|
- m_lastRectResult.width = static_cast<track_t>(rect.width);
|
|
|
- m_lastRectResult.height = static_cast<track_t>(rect.height);
|
|
|
+ m_lastRect3DResult.center.x = static_cast<track_t>(rect.center.x);
|
|
|
+ m_lastRect3DResult.center.y = static_cast<track_t>(rect.center.y);
|
|
|
+ m_lastRect3DResult.center.z = static_cast<track_t>(rect.center.z);
|
|
|
+ m_lastRect3DResult.size.width = static_cast<track_t>(rect.size.width);
|
|
|
+ m_lastRect3DResult.size.height = static_cast<track_t>(rect.size.height);
|
|
|
+ m_lastRect3DResult.size.length = static_cast<track_t>(rect.size.length);
|
|
|
+ m_lastRect3DResult.yaw = static_cast<track_t>(rect.yaw);
|
|
|
}
|
|
|
}
|
|
|
- return cv::Rect(static_cast<int>(m_lastRectResult.x), static_cast<int>(m_lastRectResult.y), static_cast<int>(m_lastRectResult.width), static_cast<int>(m_lastRectResult.height));
|
|
|
+ return m_lastRect3DResult;
|
|
|
}
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
@@ -894,27 +851,22 @@ cv::Vec<track_t, 2> TKalmanFilter::GetVelocity() const
|
|
|
{
|
|
|
int indX = 2;
|
|
|
int indY = 3;
|
|
|
- if (m_linearKalman.statePre.rows > 4)
|
|
|
+ if (m_linearKalman.statePre.rows > 5)
|
|
|
{
|
|
|
indX = 4;
|
|
|
indY = 5;
|
|
|
+ if (m_linearKalman.statePre.rows > 8)
|
|
|
+ {
|
|
|
+ indX = 7;
|
|
|
+ indY = 8;
|
|
|
+ }
|
|
|
+ res[0] = m_linearKalman.statePre.at<track_t>(indX);
|
|
|
+ res[1] = m_linearKalman.statePre.at<track_t>(indY);
|
|
|
}
|
|
|
- res[0] = m_linearKalman.statePre.at<track_t>(indX);
|
|
|
- res[1] = m_linearKalman.statePre.at<track_t>(indY);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- case tracking::KalmanUnscented:
|
|
|
- case tracking::KalmanAugmentedUnscented:
|
|
|
-#ifdef USE_OCV_UKF
|
|
|
- cv::Mat state = m_uncsentedKalman->getState();
|
|
|
- res[0] = state.at<track_t>(2);
|
|
|
- res[1] = state.at<track_t>(3);
|
|
|
-#else
|
|
|
- std::cerr << "UnscentedKalmanFilter was disabled in CMAKE! Set KalmanLinear in constructor." << std::endl;
|
|
|
-#endif
|
|
|
- break;
|
|
|
}
|
|
|
}
|
|
|
return res;
|