When I use bowtrainer.cluster(), if there are a lot of images, the application will exit with a segmentation error (core dump). [closed]
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)?
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.e.g. you might release the images before calling
bowtrainer.cluster();
I hava 562 images , 64bit os , i don't release the images momory .
The application use memory 178MiB .
562 clusters
When I have 100 images, the app is unstable.
and where exactly does it segfault ? in the clustering ?
562 images x 512x512 == 150mb mem for the images already
I test code
out put:
I have 16GB memory for this application
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
issues: https://github.com/opencv/opencv_cont...