在我的代码中,我想访问 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/