聚类错误时使用弓来获取图像的词汇
void SceneRecognition::BowRepresentation()
{
Mat dstGray2;
//Folder path is written and file names are taken according to that.
vector <String> fileNames;
String folder("airCond/Train/*.jpg");
glob(folder, fileNames,false);
//File names are checked.
for (auto t : fileNames)
{
cout << t << endl;
}
//Object is opened.
Ptr<SiftFeatureDetector> detector;
//Gray image holder is opened.
Mat dst, dstGray;
//Detector is created.
detector = SiftFeatureDetector::create();
//Keypoint vector is created.
vector<KeyPoint> keypoints;
//Object is opened.
Mat Desp;
Ptr<SiftDescriptorExtractor> extractor;
//Extractor is created.
extractor = SiftDescriptorExtractor::create();
Mat training_descriptors(1, extractor->descriptorSize(), extractor->descriptorType());
// Image matrices are read in a loop.
for (size_t i = 0; i < fileNames.size(); i++)
{
Mat im = imread(fileNames[i]);
//Image is converted to gray.
cvtColor(im, dstGray, COLOR_BGR2GRAY);
detector->detect(dstGray, keypoints);
//Descriptors are extracted.
extractor->compute(dstGray, keypoints, Desp);
training_descriptors.push_back(Desp);
}
cout << training_descriptors.size << endl;
/*Number of clusters are chosen as 1000.*/
//TermCriteria tc(TermCriteria::MAX_ITER + TermCriteria::EPS, 10, 0.001);
//int retries = 1;
//int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bowTrainer(100);
bowTrainer.add(training_descriptors);
//Created descriptors are added.
cout << "a" << endl;
//Vocabulary is created by k-means clustering.
Mat vocabulary = bowTrainer.cluster();
}
当我运行代码时,我会收到一个错误:openCV(4.5.5)错误:迭代不会收敛(Kmeans:无法更新群集中心(检查巨大或NAN值的输入))cv :: generatecenterspp,file,文件C:\ Users \ Lenovo \ Desktop \ OpenNCVV \ OpenCV-4.5.5 \模块\ core \ src \ src \ kmeans.cpp,第147行,
我尝试了不同的方法,但无法提出答案。有什么建议吗? 输入图像的一行
图像大小之一是75*144。将图像作为输入时,我应该更改某些内容吗?
void SceneRecognition::BowRepresentation()
{
Mat dstGray2;
//Folder path is written and file names are taken according to that.
vector <String> fileNames;
String folder("airCond/Train/*.jpg");
glob(folder, fileNames,false);
//File names are checked.
for (auto t : fileNames)
{
cout << t << endl;
}
//Object is opened.
Ptr<SiftFeatureDetector> detector;
//Gray image holder is opened.
Mat dst, dstGray;
//Detector is created.
detector = SiftFeatureDetector::create();
//Keypoint vector is created.
vector<KeyPoint> keypoints;
//Object is opened.
Mat Desp;
Ptr<SiftDescriptorExtractor> extractor;
//Extractor is created.
extractor = SiftDescriptorExtractor::create();
Mat training_descriptors(1, extractor->descriptorSize(), extractor->descriptorType());
// Image matrices are read in a loop.
for (size_t i = 0; i < fileNames.size(); i++)
{
Mat im = imread(fileNames[i]);
//Image is converted to gray.
cvtColor(im, dstGray, COLOR_BGR2GRAY);
detector->detect(dstGray, keypoints);
//Descriptors are extracted.
extractor->compute(dstGray, keypoints, Desp);
training_descriptors.push_back(Desp);
}
cout << training_descriptors.size << endl;
/*Number of clusters are chosen as 1000.*/
//TermCriteria tc(TermCriteria::MAX_ITER + TermCriteria::EPS, 10, 0.001);
//int retries = 1;
//int flags = KMEANS_PP_CENTERS;
BOWKMeansTrainer bowTrainer(100);
bowTrainer.add(training_descriptors);
//Created descriptors are added.
cout << "a" << endl;
//Vocabulary is created by k-means clustering.
Mat vocabulary = bowTrainer.cluster();
}
When I run my code I get an error as followed: OpenCV(4.5.5) Error: Iterations do not converge (kmeans: can't update cluster center (check input for huge or NaN values)) in cv::generateCentersPP, file C:\Users\LENOVO\Desktop\openncvv\opencv-4.5.5\modules\core\src\kmeans.cpp, line 147
I tried different approaches but couldn't come up with an answer. Any suggestions?
One row of an input image
One of the image size is 75*144. Should I change something when I taking the image as input ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论