c++ - Mat.at 函数抛出异常

标签 c++ opencv

在我的代码中,我想访问 Mat 类型矩阵的每个元素。得到矩阵作为SIFT算法的输出。

SiftFeatureDetector detector; detector.compute(image, keypoints, siftFeatureDescriptor); cout<<siftFeatureDescriptor.at<double>(0,0);

当我尝试运行这段代码时,它会在 siftFeatureDescriptor.at 函数中抛出异常。

当我尝试将 double 更改为 int 时,异常消失但它显示错误值 1114898432 而实际值为 49。

使用 Mat.type 我发现矩阵的类型是 32FC1。

请帮忙。

最佳答案

如果 mat.type 是 32FC1 你应该使用 at<float> 访问它当然。

此外,我猜您可能混淆了“检测器”和“提取器”。通常你应该像这样使用它们:

// initialize detector and extractor
  FeatureDetector* detector = new SiftFeatureDetector(
                                     0, // nFeatures
                                     4, // nOctaveLayers
                                     0.04, // contrastThreshold
                                     10, //edgeThreshold
                                     1.6 //sigma
                                     );
  DescriptorExtractor* extractor = new SiftDescriptorExtractor();

  // detect the keypoints
  vector<KeyPoint> keypoints;
  detector->detect(img, keypoints);

  // now compute the descriptors for each keypoint
  Mat descriptors;
  extractor->compute(img, keypoints, descriptors);

我的代码基于 this example

关于c++ - Mat.at 函数抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26838927/

相关文章:

c++ - 优化 Brute-force TSP 解决方案

opencv - 面部表情检测

c++ - 使用Cuda Ubuntu 16/04构建C++ OpenCV 4

java - 在 JNA 中使用 TCHAR 缓冲区

c++ - 如何在不包含 Windows.h 的情况下获取 IsDebuggerPresent 的声明?

c++ - 如何去除 canny 图像中的直线或非曲线

python - 为什么 find_objects 会给出一堆无,然后是整个图像的范围?

c++ - 光照不变图像

java - 哪种数据结构用于存储矩阵对?

c++ - QDataStream : Overloading >> for decorated QVector