nawara
nawara

Reputation: 1167

OpenCV--program stop running @ the step of detecting image key-points

I'm trying to develop a c++ implementation of bag of visual word using the opencv library

I started by testing keypoints detection function but when I insert this instruction

detector->detect(img, keypoints);, the program stop running @ the first image without throwing any exception.

Can any one help me how to fix this problem ?

Thanks

void extractTrainingVocabulary(const path& basepath) {
for (directory_iterator iter = directory_iterator(basepath); iter
        != directory_iterator(); iter++) {
    directory_entry entry = *iter;

    if (is_directory(entry.path())) {

        cout << "Processing directory " << entry.path().string() << endl;
        extractTrainingVocabulary(entry.path());

    } else {

        path entryPath = entry.path();
        if (entryPath.extension() == ".jpg") {

            cout << "Processing file " << entryPath.string() << endl;

            Mat img = imread(entryPath.string());
            if (!img.empty())
            {

                cout << "not empty"<< endl;


                try{
                    // ...
                    vector<KeyPoint> keypoints;
                    cout << "not empty"<< keypoints.empty()<<endl;
                    //detector->detect(img, keypoints);
                } catch (const std::exception& ex) {
                }



            }
            else
            {
                cout << " empty"<< endl;

            }
        }
    }
}
}

Upvotes: 0

Views: 181

Answers (1)

David Nilosek
David Nilosek

Reputation: 1412

Going to assume that the detector->detect() function in that code is actually not commented out in your implementation. My only guess would be that the img.empty() function is not returning the correct value. The OpenCV method of checking to see if an image loaded correctly is using the image.data data member, as such:

if(! image.data )  // Check for invalid input
{
    cout <<  "Could not open or find the image" << std::endl ;
    return -1;
}

Upvotes: 1

Related Questions