聚类错误时使用弓来获取图像的词汇

发布于 2025-01-25 15:49:56 字数 2222 浏览 4 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文