OpenCV4Android卡尔曼滤波器断言在matmul失败

时间:2014-12-16 07:36:46

标签: android opencv java-native-interface sigabrt kalman-filter

我遇到OpenCV4Android问题。我正在使用它的最新版本2.4.10虽然看起来,问题也发生在2.4.9。 每当我尝试在Android上使用JNI实现2d kalman过滤器时,代码都会失败,因为这样的错误(然后该方法会抛出SIGABRT并且我无能为力):

OpenCV Error: Assertion failed (type == B.type() && (type == CV_32FC1 ||
type == CV_64FC1 || type == CV_32FC2 || type == CV_64FC2)) in void
cv::gemm(cv::InputArray, cv::InputArray, double, cv::InputArray, double,
cv::OutputArray, int), file
/hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/core/src/matmul.cpp, line 711

看来,kalmanFilter.predict()方法会抛出它。

我尝试了另外两个实现 - 一个直接从互联网上获取,第二个略有不同。

我记得,(为了正确使用它)我必须先预测这一点,然后更正过滤器,这不是问题。 我的假设是,奇怪的android世界和c ++的结合处有一些奇怪的东西(也许浮动值不是android的JNI中的32位浮点数?我无法分辨......)

这是我的代码:

class Kalman{
private:
    KalmanFilter kalmanFilter;
    Mat_<float> measurement;
    bool inited;
public:
    void init(float startX, float startY){
        inited = true;
        kalmanFilter = KalmanFilter(4, 2, 0);
        float tmpArr[4][4] = {{1,0,1,0}, {0,1,0,1}, {0,0,1,0}, {0,0,0,1}};
        kalmanFilter.transitionMatrix = Mat(4,4,CV_32FC1, &tmpArr);
        measurement = Mat(2,1,CV_32FC1);
        measurement.setTo(Scalar(0));
        kalmanFilter.statePre.at<float>(0) = startX;
        kalmanFilter.statePre.at<float>(1) = startY;
        kalmanFilter.statePre.at<float>(2) = 0;
        kalmanFilter.statePre.at<float>(3) = 0;
        setIdentity(kalmanFilter.measurementMatrix);
        setIdentity(kalmanFilter.processNoiseCov, Scalar::all(1e-4));
        setIdentity(kalmanFilter.measurementNoiseCov, Scalar::all(10));
        setIdentity(kalmanFilter.errorCovPost, Scalar::all(.1));
    }
    Kalman(){}
    Kalman(float startX, float startY){
        this->init(startX, startY);
    }
    Geometry::Point newPrediction(){
        Geometry::Point res;
        if(inited){
            Log::d("Kalman", "newPrediction pre!");
            Mat prediction = kalmanFilter.predict();
            Log::d("Kalman", "newPrediction post!");
            res.x = prediction.at<float>(0);
            res.y = prediction.at<float>(1);
        }
        return res;
    }
    void correction(float x, float y){
        measurement(0) = x;
        measurement(1) = y;
        Log::d("Kalman", "correction pre!");
        kalmanFilter.correct(measurement);
        Log::d("Kalman", "correction post!");
    }

};

社区,请帮助我!

0 个答案:

没有答案