cflann::hierarchicalClustering with uchar data (Bug #1965)


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


Status:Cancelled Start date:2012-05-21
Priority:Normal Due date:
Assignee:Marius Muja % Done:

0%

Category:flann
Target version:2.4.4
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

Description

This issue is about using uchar data as input for the cvflann::hierarchicalClustering method.

It is related to a similar topic where it was suggested to use the cvflann namespace instead of cv::flann for creating a search index of type uchar.

Following this suggestion, trying to compile the code below creates an error:

.\OpenCvTest.cpp(34) : error C2664: 'cvflann::hierarchicalClustering' : cannot convert parameter 2 from 'cvflann::Matrix<T>' to 'cvflann::Matrix<T> &'
with
[
    T=unsigned char
]
and
[
    T=cvflann::Accumulator<unsigned char>::Type
]

If I replace the uchar arrays and matrix objects with float, then the code successfully compiles and executes.

#include <opencv2/opencv.hpp>
#include <opencv2/flann/flann.hpp>

int main(int argc, char* argv[])
{
    int nRows = 100000;
    int nCols = 128;
    int nClusters = nRows / 100;

    int valueMax = 255;

    uchar* data = new uchar[nRows * nCols];

    for(int i = 0; i < nRows; i++)
    {
        for(int j = 0; j < nCols; j++)
        {
            data[i * nCols + j] = (uchar)(rand() % (valueMax + 1));
        }
    }

    cvflann::Matrix<uchar> dataMat = cvflann::Matrix<uchar>(data, nRows, nCols);

    uchar* clusters = new uchar[nClusters * nCols];
    cvflann::Matrix<uchar> clustersMat = cvflann::Matrix<uchar>(clusters, nClusters, nCols);

    cvflann::KMeansIndexParams params = cvflann::KMeansIndexParams();

    cvflann::hierarchicalClustering<cvflann::L2<uchar>>(dataMat, clustersMat, params);

    return 0;
}

History

Updated by Stefan Siegel almost 13 years ago

system specifications:

OpenCV 2.4.0
Visual Studio 2008
Windows XP 32 bit

Updated by Stefan Siegel over 12 years ago

The issue still exists in OpenCV 2.4.2.

Is a fix planned in the near future?

Btw: There is a typo in the title of this issue ("cflann" instead of "cvflann") but there is no edit title function for standard users. Do you have the rights to change it?

Updated by Marius Muja about 12 years ago

When computing the cluster centers, FLANN wants a floating point type (as it averages the cluster data points).

If you change the clustersMat from uchar to float, it should work fine. You can convert back to uchar after the clustering operation if you need the result as uchar.

Updated by Marius Muja about 12 years ago

  • Status changed from Open to Done

Updated by Marius Muja about 12 years ago

  • Status changed from Done to Cancelled

Updated by Andrey Kamaev about 12 years ago

  • Target version set to 2.4.4

Also available in: Atom PDF