0

我正在使用 OpenCV 的 FlannBasedMatcher 来匹配来自 Kinect 的相机图像和一些示例图像之间的关键点。我编写了以下方法来处理cv::Mat图像:

cv::SurfFeatureDetector feature_detector;
cv::SurfDescriptorExtractor descriptor_extractor;

// Contains all the information we need about an image
struct ImageInfo
{
  int                       width,
                            height;
  std::vector<cv::KeyPoint> keypoints;
  cv::Mat                   descriptors;
  cv::FlannBasedMatcher     matcher;
};

void ObjectRecognizer::getImageInfo(const cv::Mat& image, ImageInfo& image_info)
{
  image_info.width  = image.cols;
  image_info.height = image.rows;
  // Detect keypoints
  feature_detector.detect(image, image_info.keypoints);
  // Compute descriptors
  descriptor_extractor.compute(image, image_info.keypoints, image_info.descriptors);
  // Train matcher
  std::vector<cv::Mat> descriptor_vector;
  descriptor_vector.push_back(image_info.descriptors);
  image_info.matcher.add(descriptor_vector);
  image_info.matcher.train();
}

ImageInfo我调用这个方法从我的相机图像和我的示例图像中获取一个结构。

如果我使用相机图像中的描述符训练匹配器并使用示例图像中的描述符调用该方法,则一切正常(因为它不仅运行,我实际上能够检测到相机图像中的示例图像):

cam_img_info.matcher.knnMatch(sample_info.descriptors, matches, 2);

如果我反其道而行之,并尝试使用使用样本图像描述符训练的匹配器,则会出现分段错误:

sample_info.matcher.knnMatch(cam_img_info.descriptors, matches, 2);

cv::Mat如果我使用空来匹配经过训练的样本描述符,它运行得非常好(但当然我无法检测到相机图像中的任何对象) :

cv::Mat descs;
sample_info.matcher.knnMatch(descs, matches, 2);

关于可能是什么问题的任何想法?

4

0 回答 0