Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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)?