opecv c ++匹配文件中的描述符

时间:2015-04-28 15:23:57

标签: c++ opencv file-storage orb feature-descriptor

我提取descriptors,然后将它们保存到文件中:

detector->detect(img, imgKpts);
extractor->compute(img, imgKpts, imgMat);
fsKpts << filename << imgMat;

但当我read他们再次回来时:

std::vector<cv::Mat> filesDVec;
cv::Mat temp;
fs[filename] >> temp;
filesDVec.push_back(temp);

match descriptors加载了图片:

cv::Mat givenIn, givenInMat;
givenIn = cv::imread(dataDirGivenIn, CV_LOAD_IMAGE_GRAYSCALE);
cv::vector<cv::KeyPoint> givenInKpts;
detector->detect(givenIn, givenInKpts);
extractor->compute(givenIn, givenInKpts, givenInMat);
cv::vector<cv::DMatch> matchesVector;

以2 cv::Mat为单位:

matcher->match(filesDVec[i], givenInMat, matchesVector);

A.K.A match(Scene, Object, ...)输出为:minDist = 100 maxDist = 0(不是单一匹配)。

但是他们就这样:

matcher->match(givenInMat, filesDVec[i], matchesVector);

A.K.A match(Object, Scene, ...)抛出此错误:

opencv error:assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type = CV_8U)) in void cv::batchDistance

我希望保存每张图片的描述性信息,以便加载,我做错了什么?

修改

我想补充说,这不是尝试匹配和映像到自身的情况,因为众所周知,如果对象和源图像相等于测试目的,matcher不起作用。

修改2

档案内容:

Image_0: !!opencv-matrix
   rows: 315
   cols: 32
   dt: u
   data: [ 0, 128, 196, 159, 108, 136, 172, 39, 188, 3, 114, 16, 172,
       234, 0, 66, 74, 43, 46, 128, 64, 172, 67, 239, 4, 54, 218, 8, 84,
       0, 225, 136, 160, 133, 68, 155, 204, 136, 232, 47, 61, 17, 115,
       18, 236, 106, 8, 81, 107, 131, 46, 128, 114, 56, 67, 213, 12, 50,
       218, 64, 21, 8, 209, 136, 180, 69, 70, 142, 28, 130, 238, 96, 141,
       128, 243, 2, 74, 74, 37, 65, 120, 161, 78, 226, 104, 163, 0, 204,
...
etc

读:

std::vector<cv::Mat> filesDVec(imgVec.size());
cv::Mat temp;
cv::FileStorage fs("tileDesc.yml", cv::FileStorage::READ);
for(size_t i = 0; i < (imgVec.size()); i++){
    cv::string iValue = std::to_string(i);
    cv::string filename = "Image_" + iValue;
    fs[filename] >> temp;
    filesDVec.push_back(temp);  
}
fs.release();

1 个答案:

答案 0 :(得分:1)

问题在于您使用cat_name元素分配和构建NULL(它们为空filesDVec s)。然后,每个描述符(您在imgVec.size()循环中加载)将添加到向量cv::Mat的末尾。

因此,您尝试将一些空的forfilesDVec匹配,并且很可能会导致应用程序崩溃或断言。尝试阅读如下:

cv::Mat
相关问题