When I use bowtrainer.cluster(), if there are a lot of images, the application will exit with a segmentation error (core dump). [closed]

asked 2019-11-16 20:28:05 -0500

HelloWorld gravatar image

code:

cv::Ptr<cv::FeatureDetector> detector = cv::xfeatures2d::SURF::create(
        minHessian);
cv::Ptr<cv::DescriptorExtractor> extractor = cv::xfeatures2d::SURF::create(
        minHessian);
cv::Mat trainingDescriptors(1, extractor->descriptorSize(),
        extractor->descriptorType());
trainingDescriptors.convertTo(trainingDescriptors, CV_32F);

vocabulary.create(0, 1, extractor->descriptorType());
for (auto &it : traingImages) {
    std::vector<cv::KeyPoint> keypoints;
    detector->detect(it, keypoints);

    if (keypoints.size() > 10) {
        cv::Mat descriptors;
        extractor->compute(it, keypoints, descriptors);
        if (!descriptors.empty()) {
            descriptors.convertTo(descriptors, CV_32F);
            trainingDescriptors.push_back(descriptors);
        } else {
            std::cout << "- No descriptors found." << std::endl;
        }
    } else {
        std::cout << "- No keypoints found." << std::endl;
    }
}
if (trainingDescriptors.empty()) {
    std::cout << "- Training descriptors are empty." << std::endl;
    return false;
}

cv::BOWKMeansTrainer bowtrainer(10);
bowtrainer.add(trainingDescriptors);
vocabulary = bowtrainer.cluster();

When there are many pictures, why does the application exit due to a segmentation error (core dump)?

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by HelloWorld
close date 2019-11-23 00:55:20.173688

Comments

how many images ? how many clusters ? 32bit os ? what else do you keep in memory (images?)

btw, please delete those trainingDescriptors.convertTo(trainingDescriptors, CV_32F); lines, theyre not nessecary.

berak gravatar imageberak ( 2019-11-17 02:16:23 -0500 )edit

e.g. you might release the images before calling bowtrainer.cluster();

berak gravatar imageberak ( 2019-11-17 02:19:39 -0500 )edit

I hava 562 images , 64bit os , i don't release the images momory .

The application use memory 178MiB .

HelloWorld gravatar imageHelloWorld ( 2019-11-17 03:04:41 -0500 )edit

562 clusters

HelloWorld gravatar imageHelloWorld ( 2019-11-17 03:05:20 -0500 )edit

When I have 100 images, the app is unstable.

HelloWorld gravatar imageHelloWorld ( 2019-11-17 03:09:15 -0500 )edit

and where exactly does it segfault ? in the clustering ?

562 images x 512x512 == 150mb mem for the images already

berak gravatar imageberak ( 2019-11-17 03:15:31 -0500 )edit
1

I test code

    cv::BOWKMeansTrainer bowtrainer(10);

bowtrainer.add(trainingDescriptors);

cout << "images szie:" << traingImages.size() << endl;

cout << "run success add()" << endl;

vocabulary = bowtrainer.cluster();

cout << "run success cluster()" << endl;

out put:

    load images finish;

    images szie: 562

    run success add()

    Segmentation fault (core dumped)
HelloWorld gravatar imageHelloWorld ( 2019-11-17 03:27:46 -0500 )edit

I have 16GB memory for this application

HelloWorld gravatar imageHelloWorld ( 2019-11-17 09:22:24 -0500 )edit

ArchLinux 5.3.9-1-default #1 SMP Thu Nov 7 07:06:36 UTC 2019 (b0d4923) x86_64 x86_64 x86_64 GNU/Linux

HelloWorld gravatar imageHelloWorld ( 2019-11-18 07:57:52 -0500 )edit
HelloWorld gravatar imageHelloWorld ( 2019-11-20 02:57:50 -0500 )edit