OPECV C++ 匹配文件中的描述符
opecv c++ matching descriptors from file
>我提取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);
又名 match(Scene, Object, ...)
输出为:minDist = 100 maxDist = 0
(不是单个匹配项)。
但对于他们来说:
matcher->match(givenInMat, filesDVec[i], matchesVector);
又名 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();
问题是你用imgVec.size()
元素分配和构造filesDVec
(它们是空的cv::Mat
s)。然后每个描述符(您在for
循环中加载)都将添加到向量filesDVec
的末尾。
因此,您尝试将一些空cv::Mat
与givenInMat
匹配,这很可能导致应用程序崩溃或断言。尝试阅读如下:
std::vector<cv::Mat> filesDVec;
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();
您是否在读取模式下打开了文件?否则 opencv 将在读取文件之前清空文件。
FileStorage fsKpts(filename, FileStorage::READ);
fsKpts[filename] >> temp;
而不是
FileStorage fsKpts(filename, FileStorage::WRITE);
相关文章:
- 使用VerQueryValue检索应用程序的文件描述
- 如何在C/C++中用FD_set Unix设置套接字文件描述符
- I2C 文件描述符上的 I2C 总线可写/可读标志
- 许多文件描述符在调用sys_clone时
- AMQP-CPP >处理程序中的错误文件描述符
- 如何使用 WINAPI 和 C++ 提取可执行文件的文件描述?
- 正在等待在非阻塞文件描述符上长时间运行ioctl
- 有没有适用于Windows.lib文件的GNU二进制文件描述符(BFD)
- 如何强制文件描述符缓冲我的输出
- 如何从 boost::asio::ssl::stream<boost::asio::ip::tcp::socket> 获取本机套接字文件描述器?
- 哪个更适合从C++写入敏感的日志文件,在文件描述符上写()或文件上的fprintf()?
- 将 select() 与非基于文件描述符的输入一起使用
- accept(..) 似乎正在修改我给它的文件描述符参数
- 使用 Select 多路复用未命名的管道和其他文件描述符
- 提升 ASIO 绑定:错误的文件描述符
- 使用文件描述符移动对象
- 无法从零MQ ZMQ_SERVER套接字中获取文件描述符
- read() 上的不同行为取决于写入不可写内存时表示文件、匿名管道或套接字的文件描述符
- 我是否需要在使用它的 R 包的描述文件中导入 RccpEigen,或者"LinkingTo"足够?
- GCC链接器描述文件强制符号位于特定地址