Ask Your Question

puneetdabulya's profile - activity

2018-09-12 00:03:33 -0500 received badge  Popular Question (source)
2017-03-14 01:49:12 -0500 commented question Segfault in multithreaded cuda::HOG::compute calls

I face the same issue with ORB. Although I am using detectAndComputeAsync along with CUDA streams, when I try to perform multi-threaded detect, it crashes with similar errors.

2015-06-28 15:55:53 -0500 received badge  Student (source)
2014-05-28 18:59:42 -0500 commented question Flann descriptor save and load doesn't work

Linked bug and temporary fix: http://code.opencv.org/issues/3720

2014-05-28 12:24:13 -0500 commented question Flann descriptor save and load doesn't work

Yes I agree. That was another issue with this API. How can they expect user to know the size of Mat without loading that file. The API should take care of this. Temporary fix is :

#include "opencv2/flann/saving.h"

FILE* fin = fopen(outputFile.c_str(), "rb");
if (fin == NULL)
    return false;

IndexHeader header = load_header(fin);

int dataType = header.data_type == FLANN_UINT8 ? CV_8U :
header.data_type == FLANN_INT8 ? CV_8S :
header.data_type == FLANN_UINT16 ? CV_16U :
header.data_type == FLANN_INT16 ? CV_16S :
header.data_type == FLANN_INT32 ? CV_32S :
header.data_type == FLANN_FLOAT32 ? CV_32F :
header.data_type == FLANN_FLOAT64 ? CV_64F : -1;

Mat mat = Mat(header.rows, header.cols, dataType);
2014-05-27 16:30:18 -0500 received badge  Supporter (source)
2014-05-27 16:27:28 -0500 received badge  Editor (source)
2014-05-27 16:26:53 -0500 asked a question Flann descriptor save and load doesn't work
void testSaveAndLoad(Mat descriptors, string outputFile) {
    vector<string> images;

    flann::LshIndexParams lshIndexParams(20,10,2);
    flann::Index kdtree(descriptors, lshIndexParams, cvflann::FLANN_DIST_HAMMING);

    cout << "outputting index file to disk: " << "\n";

    // just to check whether loaded ones are same or similar    
    writeMatToFile(descriptors, "before_save.dat");
    kdtree.save(outputFile);

    // saving done .. now load
    Mat mat = Mat(descriptors.rows, descriptors.cols, CV_8UC1);

    // read saved indices
     flann::Index kdtree1(mat,
                        flann::SavedIndexParams(outputFile), cvflann::FLANN_DIST_HAMMING);

   writeMatToFile(mat, "after_save.dat");

    cout << "Loaded mat of size " << mat.rows << " " << mat.cols << "\n";

    // prepare to output indices and distances
    Mat indices = Mat(descriptors.rows, 2, CV_32S);
    Mat dists = Mat(descriptors.rows, 2, CV_32S);
    kdtree1.knnSearch(descriptors, indices, dists, 2);
 }

before_save.dat:

%YAML:1.0
mat: !!opencv-matrix
   rows: 6342
   cols: 61
   dt: u
   data: [ 1, 0, 140, 7, 1, 238, 55, 0, 0, 0, 0, 0, 0, 0, 0, 128, 25,
       122, 134, 6, 0, 0, 240, 248, 227, 1, 3, 227, 249, 255, 62, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 24, 0, 0, 128, 48, 230, 15, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 128, 25, 59, 243, 51, 6, 16, 64, 252, 255, 199, 16, 255,
       7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 6, 0, 60, 0, 0, 0, 0, 0, 0,
       0, 0, 192, 14, 160, 3, 112, 0, 7, 16, 0, 0, 0, 0, 0, 0, 254, 63,
.........



after_save.dat:

%YAML:1.0
mat: !!opencv-matrix
   rows: 6342
   cols: 61
   dt: u
   data: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
.......

And knnSearch throws segfaults during the matching.

Thanks

2014-05-27 01:14:43 -0500 asked a question Flann indexing multiple descriptors and saving in file

Hello,

I am trying to use flann to create a database of large set of descriptors and later querying it for image search. I find it really weird that I have to create a super mat (all descriptor mat's concatenated using vconcat. The problems are many:

  1. There is no way of mapping matched descriptors back to original image, but Lowe's Flann implemented (original one) does allow this. There should be a constructor which accept vector<mat> during index creation. Result indices and distances should contain imgIdx, to map it back to original image.
  2. Storing index to disk seem to work fine but when I am loading it back, it expects me to know the exact size of the dataset which was stored. How do I suppose to know that. The purpose of storing in file itself is defeated. The loading part should not expect any Size of Mat as input.
  3. When I am storing indices to file, the size of Mat is (WxH) but when I am loading it, it expects me to supply transposed size which is (HxW). This is weird.
  4. Even after doing all this, I am hitting segfaults.

Anyone who has worked on opencv flann, storing and loading from disk, with multiple images, and mapping descriptors back to original image ?

Sample codes:

void computeAndSaveIndices(string directory, string outputFile) {
    vector<string> images;
    vector<Mat> descriptors;
    getFilesofExtension(directory, images, ".key");

    for (vector<string>::iterator it1 = images.begin() ; it1 != images.end(); ++it1)
    {
        cout << "Loading descriptors from file: " << *it1 << "\n";
        string file = *it1;
        Mat mat = Mat();
        readMatFromFile(file, mat);
        if (mat.rows > 0) {
            descriptors.push_back(mat);
        }
    }

    cout << "creating index using " << descriptors.size() << " files \n";

    **Mat superMat;
    vconcat(descriptors, superMat);

    cout << "supermat size is  [" << superMat.rows  <<  " " << superMat.cols << "] \n";**

    flann::LshIndexParams lshIndexParams(20,10,2);

    flann::Index kdtree(superMat, lshIndexParams, cvflann::FLANN_DIST_HAMMING);


    cout << "outputting index file to disk: " << "\n";

    kdtree.save(outputFile);

}

float searchInSavedIndices(string indicesFile, string descriptorFile) {

    **Mat indexMat = Mat(Size(61, 76728), CV_8UC1);**

    // read saved indices
    flann::Index kdtree(indexMat,
                        flann::SavedIndexParams(indicesFile),
                        cvflann::FLANN_DIST_HAMMING);


    // read query descriptors from file
    Mat descriptors = Mat();
    readMatFromFile(descriptorFile, descriptors);

    // prepare to output indices and distances
    Mat indices = Mat(descriptors.rows, 2, CV_32S);
    Mat dists = Mat(descriptors.rows, 2, CV_32S);

    cout << "Searching " << descriptorFile << " in " << indicesFile << "\n";
    kdtree.knnSearch(descriptors, indices, dists, 2);

    // indices should contain image idx too.

    int goodMatchCount = 0;

    for (int i=0; i<dists.rows; i++)
    {
        if (dists.at<int>(i, 1) > 0 && dists.at<int>(i,0) < 50)
        {
            goodMatchCount++;
        }

    }

    float percentage = (goodMatchCount* 100.f)/descriptors.rows;
    return percentage;
}
2014-03-31 03:23:24 -0500 answered a question failed to make opencv.git with gcc48 on macosx mavericks

I am also facing this problem.. anyone with a solution? .. Can anyone post steps to compile Opencv 2.4.8 with 10.9 OSX and gcc 4.8