Ask Your Question

Revision history [back]

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program, error:

OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in cv::gemm, file ........\opencv\modules\core\src\matmul.cpp, line 882

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ........\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

My class:

public class Kalman extends KalmanFilter { private KalmanFilter kalman; private Mat measurement; private Point LastResult; private double deltatime;

public void init() {

}

public Kalman(Point pt, double dt, double Accel_noise_mag) {
    kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
    deltatime = dt;

    Mat transitionMatrix = new Mat(4, 4, CvType.CV_8UC1, new Scalar(0));
    float[][] tM = { new float[] { 1, 0, 1, 0 },
            new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
            new float[] { 0, 0, 0, 1 } };

    for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
            transitionMatrix.put(j, k, tM[j][k]);
        }
    }

    kalman.set_transitionMatrix(transitionMatrix);
    measurement = new MatOfFloat(2, 1, CvType.CV_32F);

    LastResult = pt;
    Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
    statePre.put(0, 0, pt.x);
    statePre.put(1, 0, pt.y);
    statePre.put(2, 0, 0);
    statePre.put(3, 0, 0);
    kalman.set_statePre(statePre);

    Mat statePost = new MatOfFloat(2, 1);
    statePost.put(0, 0, pt.x);
    statePost.put(1, 0, pt.y);
    kalman.set_statePost(statePost);

    Mat processNoiseCov = new Mat(4, 1, CvType.CV_32F);
    float[][] dTime = {
            new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                    (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
            new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                    (float) (Math.pow(deltatime, 3.0) / 2.0) },
            new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                    (float) Math.pow(deltatime, 2.0), 0 },
            new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                    (float) Math.pow(deltatime, 2.0) } };

    for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
            processNoiseCov.put(j, k, dTime[j][k]);
        }
    }

    processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
    kalman.set_processNoiseCov(processNoiseCov);

    kalman.set_measurementNoiseCov(new Mat(2, 1, CvType.CV_32F, new Scalar(
            0.1)));
    kalman.set_errorCovPost(new Mat(2, 1, CvType.CV_32F, new Scalar(0.1)));
}

public Point getPrediction() {
    Mat prediction = kalman.predict();
    LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
    return LastResult;
}

public Point update(Point p, boolean dataCorrect) {
    measurement = new MatOfFloat(2, 1, CvType.CV_32F);
    if (!dataCorrect) {
        measurement.put(0, 0, LastResult.x);
        measurement.put(1, 0, LastResult.y);
    } else {
        measurement.put(0, 0, p.x);
        measurement.put(1, 0, p.y);
    }
    // Correction
    Mat estimated = kalman.correct(measurement);
    LastResult.x = estimated.get(0, 0)[0];
    LastResult.y = estimated.get(1, 0)[0];
    return LastResult;
}

public Point correction(){
    Mat estimated = kalman.correct(measurement);
    LastResult.x = estimated.get(0, 0)[0];
    LastResult.y = estimated.get(1, 0)[0];
    return LastResult;
}

}

And main class:

if (array.size() > 0) { Iterator<rect> it2 = array.iterator(); while (it2.hasNext()) { Rect obj = it2.next(); Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar( 0, 255, 0), 2);

int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2); int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

Point pt = new Point(ObjectCenterX, ObjectCenterY); Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2); // kalman

// initial KalmanFilter KF = new Kalman(pt, 0.2, 0.5); pt = KF.getPrediction(); pt = KF.correction(); // KF.update(pt, true); // Imgproc.rectangle(imag, obj.br(), obj.tl(), new // Scalar( // 255, 255, 0), 2); Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2); }

Help me fix this, thank you so much!

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program, error:

OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in cv::gemm, file ........\opencv\modules\core\src\matmul.cpp, line 882

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ........\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

My class:

public class Kalman extends KalmanFilter { private KalmanFilter kalman; private Mat measurement; private Point LastResult; private double deltatime;

public void init() {

}

public Kalman(Point pt, double dt, double Accel_noise_mag) {
    kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
    deltatime = dt;

    Mat transitionMatrix = new Mat(4, 4, CvType.CV_8UC1, new Scalar(0));
    float[][] tM = { new float[] { 1, 0, 1, 0 },
            new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
            new float[] { 0, 0, 0, 1 } };

    for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
            transitionMatrix.put(j, k, tM[j][k]);
        }
    }

    kalman.set_transitionMatrix(transitionMatrix);
    measurement = new MatOfFloat(2, 1, CvType.CV_32F);

    LastResult = pt;
    Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
    statePre.put(0, 0, pt.x);
    statePre.put(1, 0, pt.y);
    statePre.put(2, 0, 0);
    statePre.put(3, 0, 0);
    kalman.set_statePre(statePre);

    Mat statePost = new MatOfFloat(2, 1);
    statePost.put(0, 0, pt.x);
    statePost.put(1, 0, pt.y);
    kalman.set_statePost(statePost);

    Mat processNoiseCov = new Mat(4, 1, CvType.CV_32F);
    float[][] dTime = {
            new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                    (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
            new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                    (float) (Math.pow(deltatime, 3.0) / 2.0) },
            new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                    (float) Math.pow(deltatime, 2.0), 0 },
            new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                    (float) Math.pow(deltatime, 2.0) } };

    for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
            processNoiseCov.put(j, k, dTime[j][k]);
        }
    }

    processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
    kalman.set_processNoiseCov(processNoiseCov);

    kalman.set_measurementNoiseCov(new Mat(2, 1, CvType.CV_32F, new Scalar(
            0.1)));
    kalman.set_errorCovPost(new Mat(2, 1, CvType.CV_32F, new Scalar(0.1)));
}

public Point getPrediction() {
    Mat prediction = kalman.predict();
    LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
    return LastResult;
}

public Point update(Point p, boolean dataCorrect) {
    measurement = new MatOfFloat(2, 1, CvType.CV_32F);
    if (!dataCorrect) {
        measurement.put(0, 0, LastResult.x);
        measurement.put(1, 0, LastResult.y);
    } else {
        measurement.put(0, 0, p.x);
        measurement.put(1, 0, p.y);
    }
    // Correction
    Mat estimated = kalman.correct(measurement);
    LastResult.x = estimated.get(0, 0)[0];
    LastResult.y = estimated.get(1, 0)[0];
    return LastResult;
}

public Point correction(){
    Mat estimated = kalman.correct(measurement);
    LastResult.x = estimated.get(0, 0)[0];
    LastResult.y = estimated.get(1, 0)[0];
    return LastResult;
}

}

And main class:

 if (array.size() > 0) {
                    Iterator<rect> Iterator<Rect> it2 = array.iterator();
                 while (it2.hasNext()) {
                     Rect obj = it2.next();
                     Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar(
                             0, 255, 0), 2);

2); int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2); int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

2); Point pt = new Point(ObjectCenterX, ObjectCenterY); Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2); // kalman

kalman // initial KalmanFilter KF = new Kalman(pt, 0.2, 0.5); pt = KF.getPrediction(); pt = KF.correction(); // KF.update(pt, true); // Imgproc.rectangle(imag, obj.br(), obj.tl(), new // Scalar( // 255, 255, 0), 2); Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2); }

Help me fix this, thank you so much!

click to hide/show revision 3
No.3 Revision

updated 2015-03-20 04:07:19 -0600

berak gravatar image

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program, error:

OpenCV Error: Assertion failed (type
  == (type== B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2
  CV_32FC2 || type == CV_64FC2)) CV_64FC2))
in cv::gemm,
  file
  ........\opencv\modules\core\src\matmul.cpp,
  cv::gemm, file  ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 882

882 Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ........\opencv\modules\core\src\matmul.cpp:882: ..\..\..\..\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

cv::gemm ]

My class:

public class Kalman extends KalmanFilter {
    private KalmanFilter kalman;
    private Mat measurement;
    private Point LastResult;
    private double deltatime;

deltatime;

    public void init() {

 }

 public Kalman(Point pt, double dt, double Accel_noise_mag) {
     kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
     deltatime = dt;

     Mat transitionMatrix = new Mat(4, 4, CvType.CV_8UC1, new Scalar(0));
     float[][] tM = { new float[] { 1, 0, 1, 0 },
             new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
             new float[] { 0, 0, 0, 1 } };

     for (int j = 0; j < 4; j++) {
         for (int k = 0; k < 4; k++) {
             transitionMatrix.put(j, k, tM[j][k]);
         }
     }

     kalman.set_transitionMatrix(transitionMatrix);
     measurement = new MatOfFloat(2, 1, CvType.CV_32F);

     LastResult = pt;
     Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
     statePre.put(0, 0, pt.x);
     statePre.put(1, 0, pt.y);
     statePre.put(2, 0, 0);
     statePre.put(3, 0, 0);
     kalman.set_statePre(statePre);

     Mat statePost = new MatOfFloat(2, 1);
     statePost.put(0, 0, pt.x);
     statePost.put(1, 0, pt.y);
     kalman.set_statePost(statePost);

     Mat processNoiseCov = new Mat(4, 1, CvType.CV_32F);
     float[][] dTime = {
             new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                     (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
             new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                     (float) (Math.pow(deltatime, 3.0) / 2.0) },
             new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                     (float) Math.pow(deltatime, 2.0), 0 },
             new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                     (float) Math.pow(deltatime, 2.0) } };

     for (int j = 0; j < 4; j++) {
         for (int k = 0; k < 4; k++) {
             processNoiseCov.put(j, k, dTime[j][k]);
         }
     }

     processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
     kalman.set_processNoiseCov(processNoiseCov);

     kalman.set_measurementNoiseCov(new Mat(2, 1, CvType.CV_32F, new Scalar(
             0.1)));
     kalman.set_errorCovPost(new Mat(2, 1, CvType.CV_32F, new Scalar(0.1)));
 }

 public Point getPrediction() {
     Mat prediction = kalman.predict();
     LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
     return LastResult;
 }

 public Point update(Point p, boolean dataCorrect) {
     measurement = new MatOfFloat(2, 1, CvType.CV_32F);
     if (!dataCorrect) {
         measurement.put(0, 0, LastResult.x);
         measurement.put(1, 0, LastResult.y);
     } else {
         measurement.put(0, 0, p.x);
         measurement.put(1, 0, p.y);
     }
     // Correction
     Mat estimated = kalman.correct(measurement);
     LastResult.x = estimated.get(0, 0)[0];
     LastResult.y = estimated.get(1, 0)[0];
     return LastResult;
 }

 public Point correction(){
     Mat estimated = kalman.correct(measurement);
     LastResult.x = estimated.get(0, 0)[0];
     LastResult.y = estimated.get(1, 0)[0];
     return LastResult;
 }

}

} And main class:

</br>

    if (array.size() > 0) {
                 Iterator<Rect> it2 = array.iterator();
                 while (it2.hasNext()) {
                     Rect obj = it2.next();
                     Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar(
                             0, 255, 0), 2);

                     int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2);
                     int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

                     Point pt = new Point(ObjectCenterX, ObjectCenterY);
                     Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2);
                     // kalman

                     // initial KalmanFilter
                     KF = new Kalman(pt, 0.2, 0.5);
                     pt = KF.getPrediction();
                     pt = KF.correction();
                     // KF.update(pt, true);
                     // Imgproc.rectangle(imag, obj.br(), obj.tl(), new
                     // Scalar(
                     // 255, 255, 0), 2);
                     Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2);
                 }

Help me fix this, thank you so much!

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program, error:


Error (fixed): OpenCV Error: Assertion failed (type== B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in cv::gemm, file ..\..\..\..\opencv\modules\core\src\matmul.cpp, ........\opencv\modules\core\src\matmul.cpp, line 882 882

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

New bug

OpenCV Error: Assertion failed (a_size.width == len) in cv::gemm, file ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 889 

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:889: error: (-215) a_size.width == len in function cv::gemm

My class:

public class Kalman extends KalmanFilter {
    private KalmanFilter kalman;
    private Mat measurement;
    private Point LastResult;
    private double deltatime;

    public void init() {

    }

    public Kalman(Point pt, double dt, double Accel_noise_mag) {
        kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
        deltatime = dt;

        Mat transitionMatrix = new Mat(4, 4, CvType.CV_8UC1, new Scalar(0));
        float[][] tM = { new float[] { 1, 0, 1, 0 },
                new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 1 } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                transitionMatrix.put(j, k, tM[j][k]);
            }
        }

        kalman.set_transitionMatrix(transitionMatrix);
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);

        LastResult = pt;
        Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
        statePre.put(0, 0, pt.x);
        statePre.put(1, 0, pt.y);
        statePre.put(2, 0, 0);
        statePre.put(3, 0, 0);
        kalman.set_statePre(statePre);

        Mat statePost = new MatOfFloat(2, 1);
        statePost.put(0, 0, pt.x);
        statePost.put(1, 0, pt.y);
        kalman.set_statePost(statePost);

        Mat processNoiseCov = new Mat(4, 1, CvType.CV_32F);
        float[][] dTime = {
                new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0) },
                new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0) } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                processNoiseCov.put(j, k, dTime[j][k]);
            }
        }

        processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
        kalman.set_processNoiseCov(processNoiseCov);

        kalman.set_measurementNoiseCov(new Mat(2, 1, CvType.CV_32F, new Scalar(
                0.1)));
        kalman.set_errorCovPost(new Mat(2, 1, CvType.CV_32F, new Scalar(0.1)));
    }

    public Point getPrediction() {
        Mat prediction = kalman.predict();
        LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
        return LastResult;
    }

    public Point update(Point p, boolean dataCorrect) {
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);
        if (!dataCorrect) {
            measurement.put(0, 0, LastResult.x);
            measurement.put(1, 0, LastResult.y);
        } else {
            measurement.put(0, 0, p.x);
            measurement.put(1, 0, p.y);
        }
        // Correction
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }

    public Point correction(){
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }
}
 

And main class: </br>

     if (array.size() > 0) {
                    Iterator<Rect> it2 = array.iterator();
                    while (it2.hasNext()) {
                        Rect obj = it2.next();
                        Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar(
                                0, 255, 0), 2);

                        int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2);
                        int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

                        Point pt = new Point(ObjectCenterX, ObjectCenterY);
                        Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2);
                        // kalman

                        // initial KalmanFilter
                        KF = new Kalman(pt, 0.2, 0.5);
                        pt = KF.getPrediction();
                        pt = KF.correction();
                        // KF.update(pt, true);
                        // Imgproc.rectangle(imag, obj.br(), obj.tl(), new
                        // Scalar(
                        // 255, 255, 0), 2);
                        Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2);
                    }

Help me fix this, thank you so much!

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program,


Error (fixed): (fixed):

OpenCV Error: Assertion failed (type== B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2))
 in cv::gemm, file  ........\opencv\modules\core\src\matmul.cpp, ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 882

882
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

New bug

OpenCV Error: Assertion failed (a_size.width == len) in cv::gemm, file ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 889 

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:889: error: (-215) a_size.width == len in function cv::gemm

My class:

public class Kalman extends KalmanFilter {
    private KalmanFilter kalman;
    private Mat measurement;
    private Point LastResult;
    private double deltatime;

    public void init() {

    }

    public Kalman(Point pt, double dt, double Accel_noise_mag) {
        kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
        deltatime = dt;

        Mat transitionMatrix = new Mat(4, 4, CvType.CV_8UC1, new Scalar(0));
        float[][] tM = { new float[] { 1, 0, 1, 0 },
                new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 1 } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                transitionMatrix.put(j, k, tM[j][k]);
            }
        }

        kalman.set_transitionMatrix(transitionMatrix);
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);

        LastResult = pt;
        Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
        statePre.put(0, 0, pt.x);
        statePre.put(1, 0, pt.y);
        statePre.put(2, 0, 0);
        statePre.put(3, 0, 0);
        kalman.set_statePre(statePre);

        Mat statePost = new MatOfFloat(2, 1);
        statePost.put(0, 0, pt.x);
        statePost.put(1, 0, pt.y);
        kalman.set_statePost(statePost);

        Mat processNoiseCov = new Mat(4, 1, CvType.CV_32F);
        float[][] dTime = {
                new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0) },
                new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0) } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                processNoiseCov.put(j, k, dTime[j][k]);
            }
        }

        processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
        kalman.set_processNoiseCov(processNoiseCov);

        kalman.set_measurementNoiseCov(new Mat(2, 1, CvType.CV_32F, new Scalar(
                0.1)));
        kalman.set_errorCovPost(new Mat(2, 1, CvType.CV_32F, new Scalar(0.1)));
    }

    public Point getPrediction() {
        Mat prediction = kalman.predict();
        LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
        return LastResult;
    }

    public Point update(Point p, boolean dataCorrect) {
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);
        if (!dataCorrect) {
            measurement.put(0, 0, LastResult.x);
            measurement.put(1, 0, LastResult.y);
        } else {
            measurement.put(0, 0, p.x);
            measurement.put(1, 0, p.y);
        }
        // Correction
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }

    public Point correction(){
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }
}

And main class:

                       if (array.size() > 0) {
                    Iterator<Rect> it2 = array.iterator();
                    while (it2.hasNext()) {
                        Rect obj = it2.next();
                        Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar(
                                0, 255, 0), 2);

                        int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2);
                        int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

                        Point pt = new Point(ObjectCenterX, ObjectCenterY);
                        Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2);
                        // kalman

                        // initial KalmanFilter
                        KF = new Kalman(pt, 0.2, 0.5);
                        pt = KF.getPrediction();
                        pt = KF.correction();
                        // KF.update(pt, true);
                        // Imgproc.rectangle(imag, obj.br(), obj.tl(), new
                        // Scalar(
                        // 255, 255, 0), 2);
                        Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2);
                    }

Help me fix this, thank you so much!

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program,


Error (fixed):

OpenCV Error: Assertion failed (type== B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2))
in cv::gemm, file  ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 882
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

New bug

OpenCV Error: Assertion failed (a_size.width == len) in cv::gemm, file ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 889 

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:889: error: (-215) a_size.width == len in function cv::gemm

My class:

public class Kalman extends KalmanFilter {
    private KalmanFilter kalman;
    private Mat measurement;
    private Point LastResult;
    private double deltatime;

    public void init() {

    }

    public Kalman(Point pt, double dt, double Accel_noise_mag) {
        kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
        deltatime = dt;

        Mat transitionMatrix = new Mat(4, 4, CvType.CV_8UC1, CvType.CV_32F, new Scalar(0));
        float[][] tM = { new float[] { 1, 0, 1, 0 },
                new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 1 } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                transitionMatrix.put(j, k, tM[j][k]);
            }
        }

        kalman.set_transitionMatrix(transitionMatrix);
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);

        LastResult = pt;
        Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
        statePre.put(0, 0, pt.x);
        statePre.put(1, 0, pt.y);
        statePre.put(2, 0, 0);
        statePre.put(3, 0, 0);
        kalman.set_statePre(statePre);

        Mat statePost = new MatOfFloat(2, 1);
        statePost.put(0, 0, pt.x);
        statePost.put(1, 0, pt.y);
        kalman.set_statePost(statePost);

        Mat processNoiseCov = new Mat(4, 1, CvType.CV_32F);
        float[][] dTime = {
                new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0) },
                new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0) } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                processNoiseCov.put(j, k, dTime[j][k]);
            }
        }

        processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
        kalman.set_processNoiseCov(processNoiseCov);

        kalman.set_measurementNoiseCov(new Mat(2, 1, CvType.CV_32F, new Scalar(
                0.1)));
        kalman.set_errorCovPost(new Mat(2, 1, CvType.CV_32F, new Scalar(0.1)));
    }

    public Point getPrediction() {
        Mat prediction = kalman.predict();
        LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
        return LastResult;
    }

    public Point update(Point p, boolean dataCorrect) {
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);
        if (!dataCorrect) {
            measurement.put(0, 0, LastResult.x);
            measurement.put(1, 0, LastResult.y);
        } else {
            measurement.put(0, 0, p.x);
            measurement.put(1, 0, p.y);
        }
        // Correction
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }

    public Point correction(){
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }
}

And main class:

                       if (array.size() > 0) {
                    Iterator<Rect> it2 = array.iterator();
                    while (it2.hasNext()) {
                        Rect obj = it2.next();
                        Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar(
                                0, 255, 0), 2);

                        int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2);
                        int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

                        Point pt = new Point(ObjectCenterX, ObjectCenterY);
                        Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2);
                        // kalman

                        // initial KalmanFilter
                        KF = new Kalman(pt, 0.2, 0.5);
                        pt = KF.getPrediction();
                        pt = KF.correction();
                        // KF.update(pt, true);
                        // Imgproc.rectangle(imag, obj.br(), obj.tl(), new
                        // Scalar(
                        // 255, 255, 0), 2);
                        Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2);
                    }

Help me fix this, thank you so much!

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program,


Error (fixed):

OpenCV Error: Assertion failed (type== B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2))
in cv::gemm, file  ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 882
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

New bugbug in line

        Mat prediction = kalman.predict();

OpenCV Error: Assertion failed (a_size.width == len) in cv::gemm, file ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 889 

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:889: error: (-215) a_size.width == len in function cv::gemm

My class:

public class Kalman extends KalmanFilter {
    private KalmanFilter kalman;
    private Mat measurement;
    private Point LastResult;
    private double deltatime;

    public void init() {

    }

    public Kalman(Point pt, double dt, double Accel_noise_mag) {
        kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
        deltatime = dt;

        Mat transitionMatrix = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
        float[][] tM = { new float[] { 1, 0, 1, 0 },
                new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 1 } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                transitionMatrix.put(j, k, tM[j][k]);
            }
        }

        kalman.set_transitionMatrix(transitionMatrix);
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);

        LastResult = pt;
        Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
        statePre.put(0, 0, pt.x);
        statePre.put(1, 0, pt.y);
        statePre.put(2, 0, 0);
        statePre.put(3, 0, 0);
        kalman.set_statePre(statePre);

        Mat statePost = new MatOfFloat(2, 1);
        statePost.put(0, 0, pt.x);
        statePost.put(1, 0, pt.y);
        kalman.set_statePost(statePost);

        Mat processNoiseCov = new Mat(4, 1, CvType.CV_32F);
        float[][] dTime = {
                new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0) },
                new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0) } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                processNoiseCov.put(j, k, dTime[j][k]);
            }
        }

        processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
        kalman.set_processNoiseCov(processNoiseCov);

        kalman.set_measurementNoiseCov(new Mat(2, 1, CvType.CV_32F, new Scalar(
                0.1)));
        kalman.set_errorCovPost(new Mat(2, 1, CvType.CV_32F, new Scalar(0.1)));
    }

    public Point getPrediction() {
        Mat prediction = kalman.predict();
        LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
        return LastResult;
    }

    public Point update(Point p, boolean dataCorrect) {
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);
        if (!dataCorrect) {
            measurement.put(0, 0, LastResult.x);
            measurement.put(1, 0, LastResult.y);
        } else {
            measurement.put(0, 0, p.x);
            measurement.put(1, 0, p.y);
        }
        // Correction
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }

    public Point correction(){
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }
}

And main class:

                       if (array.size() > 0) {
                    Iterator<Rect> it2 = array.iterator();
                    while (it2.hasNext()) {
                        Rect obj = it2.next();
                        Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar(
                                0, 255, 0), 2);

                        int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2);
                        int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

                        Point pt = new Point(ObjectCenterX, ObjectCenterY);
                        Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2);
                        // kalman

                        // initial KalmanFilter
                        KF = new Kalman(pt, 0.2, 0.5);
                        pt = KF.getPrediction();
                        pt = KF.correction();
                        // KF.update(pt, true);
                        // Imgproc.rectangle(imag, obj.br(), obj.tl(), new
                        // Scalar(
                        // 255, 255, 0), 2);
                        Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2);
                    }

Help me fix this, thank you so much!

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program,


Error (fixed):

OpenCV Error: Assertion failed (type== B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2))
in cv::gemm, file  ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 882
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

New bug in line

        Mat prediction = kalman.predict();

OpenCV Error: Assertion failed (a_size.width == len) in cv::gemm, file ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 889 

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:889: error: (-215) a_size.width == len in function cv::gemm

My class:

public class Kalman extends KalmanFilter {
    private KalmanFilter kalman;
    private Mat measurement;
    private Point LastResult;
    private double deltatime;

    public void init() {

    }

    public Kalman(Point pt, double dt, double Accel_noise_mag) {
        kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
        deltatime = dt;

        Mat transitionMatrix = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
        float[][] tM = { new float[] { 1, 0, 1, 0 },
                new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 1 } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                transitionMatrix.put(j, k, tM[j][k]);
            }
        }

        kalman.set_transitionMatrix(transitionMatrix);
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);

        LastResult = pt;
        Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
        statePre.put(0, 0, pt.x);
        statePre.put(1, 0, pt.y);
        statePre.put(2, 0, 0);
        statePre.put(3, 0, 0);
        kalman.set_statePre(statePre);

        Mat statePost = new MatOfFloat(2, 1);
        statePost.put(0, 0, pt.x);
        statePost.put(1, 0, pt.y);
        kalman.set_statePost(statePost);

        Mat processNoiseCov = new Mat(4, 1, 4, CvType.CV_32F);
        float[][] dTime = {
                new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0) },
                new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0) } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                processNoiseCov.put(j, k, dTime[j][k]);
            }
        }

        processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
        kalman.set_processNoiseCov(processNoiseCov);

        kalman.set_measurementNoiseCov(new Mat(2, 1, CvType.CV_32F, new Scalar(
                0.1)));
        kalman.set_errorCovPost(new Mat(2, 1, CvType.CV_32F, new Scalar(0.1)));
    }

    public Point getPrediction() {
        Mat prediction = kalman.predict();
        LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
        return LastResult;
    }

    public Point update(Point p, boolean dataCorrect) {
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);
        if (!dataCorrect) {
            measurement.put(0, 0, LastResult.x);
            measurement.put(1, 0, LastResult.y);
        } else {
            measurement.put(0, 0, p.x);
            measurement.put(1, 0, p.y);
        }
        // Correction
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }

    public Point correction(){
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }
}

And main class:

                       if (array.size() > 0) {
                    Iterator<Rect> it2 = array.iterator();
                    while (it2.hasNext()) {
                        Rect obj = it2.next();
                        Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar(
                                0, 255, 0), 2);

                        int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2);
                        int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

                        Point pt = new Point(ObjectCenterX, ObjectCenterY);
                        Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2);
                        // kalman

                        // initial KalmanFilter
                        KF = new Kalman(pt, 0.2, 0.5);
                        pt = KF.getPrediction();
                        pt = KF.correction();
                        // KF.update(pt, true);
                        // Imgproc.rectangle(imag, obj.br(), obj.tl(), new
                        // Scalar(
                        // 255, 255, 0), 2);
                        Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2);
                    }

Help me fix this, thank you so much!

Assertion Error in Kalman Filter Java OpenCV 3.0

Hi everyone! I have a problem with OpenCV3.0.
I used KalmanFilter in OpenCV3.0, when i run my program,


Error (fixed):

OpenCV Error: Assertion failed (type== B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2))
in cv::gemm, file  ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 882
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:882: error: (-215) type == B.type() && (type == CV_32FC1 || type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2) in function cv::gemm ]

New bug in line

        Mat prediction = kalman.predict();

OpenCV Error: Assertion failed (a_size.width == len) in cv::gemm, file ..\..\..\..\opencv\modules\core\src\matmul.cpp, line 889 

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matmul.cpp:889: error: (-215) a_size.width == len in function cv::gemm

My class:

public class Kalman extends KalmanFilter {
    private KalmanFilter kalman;
    private Mat measurement;
    private Point LastResult;
    private double deltatime;

    public void init() {

    }

    public Kalman(Point pt, double dt, double Accel_noise_mag) {
        kalman = new KalmanFilter(4, 2, 0, CvType.CV_32F);
        deltatime = dt;

        Mat transitionMatrix = new Mat(4, 4, CvType.CV_32F, new Scalar(0));
        float[][] tM = { new float[] { 1, 0, 1, 0 },
                new float[] { 0, 1, 0, 1 }, new float[] { 0, 0, 1, 0 },
                new float[] { 0, 0, 0, 1 } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                transitionMatrix.put(j, k, tM[j][k]);
            }
        }

        kalman.set_transitionMatrix(transitionMatrix);
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);

        LastResult = pt;
        Mat statePre = new MatOfFloat(4, 1); // Toa do (x,y), van toc (0,0)
        statePre.put(0, 0, pt.x);
        statePre.put(1, 0, pt.y);
        statePre.put(2, 0, 0);
        statePre.put(3, 0, 0);
        kalman.set_statePre(statePre);

        Mat statePost = new MatOfFloat(2, 1);
        statePost.put(0, 0, pt.x);
        statePost.put(1, 0, pt.y);
        kalman.set_statePost(statePost);

        Mat processNoiseCov = new Mat(4, 4, CvType.CV_32F);
        float[][] dTime = {
                new float[] { (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 4.0) / 4.0), 0,
                        (float) (Math.pow(deltatime, 3.0) / 2.0) },
                new float[] { (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0), 0 },
                new float[] { 0, (float) (Math.pow(deltatime, 3.0) / 2.0), 0,
                        (float) Math.pow(deltatime, 2.0) } };

        for (int j = 0; j < 4; j++) {
            for (int k = 0; k < 4; k++) {
                processNoiseCov.put(j, k, dTime[j][k]);
            }
        }

        processNoiseCov.mul(processNoiseCov, Accel_noise_mag);
        kalman.set_processNoiseCov(processNoiseCov);

        kalman.set_measurementNoiseCov(new Mat(2, 1, 2, CvType.CV_32F, new Scalar(
                0.1)));
        kalman.set_errorCovPost(new Mat(2, 1, Mat(4, 4, CvType.CV_32F, new Scalar(0.1)));
    }

    public Point getPrediction() {
        Mat prediction = kalman.predict();
        LastResult = new Point(prediction.get(0, 0)[0], prediction.get(1, 0)[0]);
        return LastResult;
    }

    public Point update(Point p, boolean dataCorrect) {
        measurement = new MatOfFloat(2, 1, CvType.CV_32F);
        if (!dataCorrect) {
            measurement.put(0, 0, LastResult.x);
            measurement.put(1, 0, LastResult.y);
        } else {
            measurement.put(0, 0, p.x);
            measurement.put(1, 0, p.y);
        }
        // Correction
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }

    public Point correction(){
        Mat estimated = kalman.correct(measurement);
        LastResult.x = estimated.get(0, 0)[0];
        LastResult.y = estimated.get(1, 0)[0];
        return LastResult;
    }
}

And main class:

                       if (array.size() > 0) {
                    Iterator<Rect> it2 = array.iterator();
                    while (it2.hasNext()) {
                        Rect obj = it2.next();
                        Imgproc.rectangle(imag, obj.br(), obj.tl(), new Scalar(
                                0, 255, 0), 2);

                        int ObjectCenterX = (int) ((obj.tl().x + obj.br().x) / 2);
                        int ObjectCenterY = (int) ((obj.tl().y + obj.br().y) / 2);

                        Point pt = new Point(ObjectCenterX, ObjectCenterY);
                        Imgproc.circle(imag, pt, 1, new Scalar(0, 0, 255), 2);
                        // kalman

                        // initial KalmanFilter
                        KF = new Kalman(pt, 0.2, 0.5);
                        pt = KF.getPrediction();
                        pt = KF.correction();
                        // KF.update(pt, true);
                        // Imgproc.rectangle(imag, obj.br(), obj.tl(), new
                        // Scalar(
                        // 255, 255, 0), 2);
                        Imgproc.circle(frame, pt, 2, new Scalar(0, 255, 255), 2);
                    }

Help me fix this, thank you so much!