【问题标题】:Why I derive unhandled exception when try to compute clusters为什么我在尝试计算集群时得出未处理的异常
【发布时间】:2013-03-20 13:11:57
【问题描述】:

我尝试使用 OpenCV 制作描述符字典。 当我使用 BOWKmeansTrainer 的方法 .cluster() 时,我的应用程序抛出未处理的异常

OpenCV 错误:断言失败 (data.dims 0) in un 已知函数,文件......\src\opencv\modules\core\src\matrix.cpp,第 2485 行 未知异常

我不明白为什么会这样。我尝试更改参数,但没有帮助。

您能给我一些想法,我可以如何解决这个问题吗?

int main(int argc, char* argv[]) {

const int countClusters = 2;

vector<string> fileList;

GetFilesInFolder(folder_one, fileList);

vector<bool> trainMask(fileList.size());
InitRandomBoolVector(trainMask, 0.1);

Ptr<FeatureDetector> keypointsDetector = FeatureDetector::create("HARRIS");

Ptr<DescriptorExtractor> descriptorsExtractor = DescriptorExtractor::create("BRIEF");

Mat descriptors;
Mat voc;

TermCriteria tc(TermCriteria::COUNT + TermCriteria::EPS, 10, 0.001);
BOWKMeansTrainer bowTrainer(vocSize,tc);
for(int i = 0;i < filesList.size();i++)
{
    if(is_voc.at(i))
    {
        vector<KeyPoint> keypoints;
        Mat image = imread(filesList.at(i));

        keypointsDetector->detect(image,keypoints);
        descriptorsExtractor->compute(image,keypoints,descriptors);
        bowTrainer.add(descriptors);
    }
}
try
{
    voc = bowTrainer.cluster();
}
catch(std::exception ex)
{
    printf(ex.what());
}


return 0;

}

【问题讨论】:

  • 异常信息告诉你问题出在哪里。慢慢仔细阅读。
  • 我帮助他:dimensions &lt;= 2 AND type == CV_32F AND K &gt; 0。所以要么选择另一种类型,要么获得更多维度。
  • 我也有同样的异常,很难理解。特别是,我不明白尺寸

标签: opencv machine-learning computer-vision cluster-computing


【解决方案1】:

您是否检查过您输入 BOWKMeansTrainer 的关键点和描述符是否有效?我认为这可能是一个很好的起点。

我能够使用 SIFT 将描述符输入 BOWKMeansTrainer,但不确定是否将其与 HARRIS/BRIEF 一起使用。下面是SIFT方法的代码:

    Mat allDescriptors;
    SiftDescriptorExtractor detector;
    for (int i = 1; i <= 10; i++) {
        // get keypoints
        vector<KeyPoint> keypoints;
        // assuming you have a function intToString that converts your iterator to a string,
        // this line creates a file path, e.g. /home/ubuntu/1.jpg to /home.ubuntu/10.jpg
        string imagePath = "<put path to your image here>" + "/" + intToString(i) + ".jpg";
        Mat imageToUse = imread(imagePath, CV_LOAD_IMAGE_GRAYSCALE); //Load as grayscale
        detector.detect(imageToUse, keypoints);
        // get descriptors
        Mat descriptors;
        detector.compute(imageToUse, keypoints,descriptors);
        // load descriptors into your descriptor array
        allDescriptors.push_back(descriptors);
    }

此代码使用 SiftDescriptorExtractor 进行关键点检测和描述符提取。如果将关键点和描述符保存到文件中,您可以看到它们是维度为 128*n 的 Mats。尝试将描述符保存在文件中并检查它们是否具有您期望的尺寸。

如果不是这个,那么它可能是您用于训练器的参数。

祝你好运。 BOWKMeans 真的很难设置。

【讨论】:

  • 碰巧我也遇到了同样的错误,这是因为我的描述符垫是空的。
猜你喜欢
  • 2012-02-12
  • 2016-07-04
  • 1970-01-01
  • 2020-08-16
  • 2011-01-19
  • 2014-02-08
  • 2020-02-26
  • 2011-11-23
  • 1970-01-01
相关资源
最近更新 更多