FLANN index with uchar, int or other data than float (Bug #1947)


Added by Stefan Siegel almost 13 years ago. Updated almost 13 years ago.


Status:Cancelled Start date:2012-05-16
Priority:Normal Due date:
Assignee:Andrey Kamaev % Done:

0%

Category:features2d
Target version:2.4.1
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

Trying to create a cv::flann::Index with a Mat object which is based on an array of uchar, integer or other data types than float results in an exception.

In the (original) FLANN 1.7.1 documentation of the C API it says in section 3.2: "[...] Because there is not template support in C, there are bindings provided for the following data types: unsigned char, int, float and double. [...]"

This means that the FLANN index of the original implementation supports these data types and that there is probably something wrong with the wrapping of the library in OpenCV.

int nRows = 100;
int nCols = 128;

float *dataFloat = new float[nRows * nCols];
uchar *dataUchar = new uchar[nRows * nCols];

for(int i = 0; i < nRows; i++)
{
    for(int j = 0; j < nCols; j++)
    {
        dataFloat[i * nCols + j] = (float)rand();
        dataUchar[i * nCols + j] = 255;
    }
}

cv::flann::LinearIndexParams indexParams;

cv::Mat dataMatFloat = cv::Mat(nRows, nCols, CV_32FC1, dataFloat);
cv::Mat dataMatUchar = cv::Mat(nRows, nCols, CV_8UC1, dataUchar);

// ok
cv::flann::Index indexFloat = cv::flann::Index(dataMatFloat, indexParams);

// runtime exception
cv::flann::Index indexUchar = cv::flann::Index(dataMatUchar, indexParams);

OpenCV 2.4.0
Visual Studio 2008
Windows XP 32 bit


Related issues

duplicated by Bug #1946: FlannBasedMatcher and OrbDescriptorExtractor Cancelled 2012-05-16

History

Updated by Andrey Kamaev almost 13 years ago

You should use LshIndexParams instead of LinearIndexParams for uchar descriptors.

  • Status changed from Open to Cancelled
  • Target version set to 2.4.1
  • Category set to features2d
  • Assignee set to Andrey Kamaev

Updated by Stefan Siegel almost 13 years ago

The LinearIndexParams and the small data set were just an simple example to demonstrate the problem.
I actually want to use the KDTreeIndexParams on large data sets with about 10^6 * 128 uchar values.
The KDTreeIndexParams work fine on float data but fail when trying to use uchar data.
I want to emphasize again that the documentation of the original FLANN library states that uchar is supported.

flan_index_t flann_build_index_byte(unsigned char* dataset,
int rows, int cols, float* speedup,
struct FLANNParameters* flann_params);

Considering the above mentioned facts, why is this issue canceled?

Updated by Andrey Kamaev almost 13 years ago

cv::flann::Index is a thin wrapper on the flann::Index and is designed to solve only one particular task - matching feature descriptors.
If you want something different from the OpenCV's implementation you should directly use flann::Index (which is renamed to cvflann::Index inside the OpenCV).

Updated by Stefan Siegel almost 13 years ago

[...] you should directly use flann::Index (which is renamed to cvflann::Index inside the OpenCV) [...]

I see.

Where are these different use cases (when and why to use which namespace and interface) documented?

It would be great if OpenCV provided a proper documentation about the correct usage of the FLANN library with some examples to make issues like this more clear.

Also available in: Atom PDF