Ask Your Question

anaid's profile - activity

2020-10-11 11:33:08 -0600 received badge  Popular Question (source)
2012-10-17 02:04:43 -0600 commented question batchDistance assert error

Not possible, Eclipse tells me that the variable has to be initialized. (Can't compile or run until I do that and the only options are null or new Mat(), both give an error.)

2012-10-17 01:53:12 -0600 received badge  Editor (source)
2012-10-17 01:41:50 -0600 received badge  Student (source)
2012-10-17 01:31:14 -0600 received badge  Supporter (source)
2012-10-17 01:21:16 -0600 commented answer batchDistance assert error

That's not possible, the OpenCV4Android signature of batchDistance requires 5, 7 or 10 arguments. Java does not allow omitting parameters. And null cannot be passed, because this results in a NullPointerException. I've tried.

2012-10-17 00:40:55 -0600 commented question batchDistance assert error

I've thought of that, but noArray() doesn't seem to exist under Android.

2012-10-16 15:35:42 -0600 asked a question batchDistance assert error

When I use batchDistance in OpenCV4Android, I get the following assertion error:

10-16 17:33:22.770: E/cv::error()(30470): OpenCV Error: Assertion failed (_nidx.needed() == (K > 0)) in void cv::batchDistance(const cv::_InputArray&, const cv::_InputArray&, const cv::_OutputArray&, int, const cv::_OutputArray&, int, int, const cv::_InputArray&, int, bool), file X:\Dev\git\opencv-2.4\modules\core\src\stat.cpp, line 1771
10-16 17:33:22.775: E/AndroidRuntime(30470): FATAL EXCEPTION: main
10-16 17:33:22.775: E/AndroidRuntime(30470): CvException [org.opencv.core.CvException: X:\Dev\git\opencv-2.4\modules\core\src\stat.cpp:1771: error: (-215) _nidx.needed() == (K > 0) in function void cv::batchDistance(const cv::_InputArray&, const cv::_InputArray&, const cv::_OutputArray&, int, const cv::_OutputArray&, int, int, const cv::_InputArray&, int, bool)

I'm using batchDistance as follows:

    Mat distances = new Mat();
    Mat nidx = new Mat();
    assert(nidx.empty());

    Core.batchDistance(queryDescriptors, 
            mTrainDescriptors, 
            distances, 
            Core.NORM_HAMMING2,
            nidx 
            );

I've used nidx = new Mat() because I saw that in C++ the default was noArray(), which should be equal to an empty Mat. In Java, the method .needed() doesn't exist, so I don't know what's actually the problem.

Please help me fix this or help me find another way to calculate the pairwise distance of the descriptors in two Mat's.

Edit: noArray() doesn't exist under OpenCV4Android and passing in null results in a NullPointerException.

Workaround

This doesn't really solve the issue at hand, but a workaround is to call it as follows:

    Core.batchDistance(queryDescriptors, 
            mTrainDescriptors, 
            distances, 
            -1, 
            nidx, 
            Core.NORM_L1,
            1
            );

This circumvents the assertion _nidx.needed() == (K > 0) because K is set to 1. I don't really know what K represents/means though, so this does not solve the question as I would like to call batchDistance with as many default parameters as possible (= safest if you don't know the inner workings of a method yet, I think).