读取sift点数据函数
2017-08-10 16:34
141 查看
从硬盘读取SIFT特征点数据,这些数据是David Lowe的程序生成的,不包含读取描述。
http://www.cs.ubc.ca/~lowe/keypoints/
readsift.h
#pragma once
#include <vector>
struct SiftPoint {
double x;
double y;
double scale;
double orientation;
};
bool loadSiftPoints(const char* nameFile, std::vector<SiftPoint>& siftPoints);
readsift.cpp
#include "readsift.h"
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
bool loadSiftPoints(const char* nameFile, std::vector<SiftPoint>& siftPoints)
{
siftPoints.clear();
std::ifstream ifile(nameFile);
int numPoints;
if(ifile.good())
{
std::string str;
std::getline(ifile, str);
std::istringstream s(str);
s >> numPoints;
while (ifile.good())
{
std::string str;
std::getline(ifile, str);
if (ifile.good())
{
std::istringstream s(str);
SiftPoint sp;
s >> sp.x >> sp.y >> sp.scale >> sp.orientation;
if (!s.fail())
siftPoints.push_back(sp);
}
}
}
ifile.close();
return (!siftPoints.empty()) && (numPoints== siftPoints.size());
}
http://www.cs.ubc.ca/~lowe/keypoints/
readsift.h
#pragma once
#include <vector>
struct SiftPoint {
double x;
double y;
double scale;
double orientation;
};
bool loadSiftPoints(const char* nameFile, std::vector<SiftPoint>& siftPoints);
readsift.cpp
#include "readsift.h"
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
bool loadSiftPoints(const char* nameFile, std::vector<SiftPoint>& siftPoints)
{
siftPoints.clear();
std::ifstream ifile(nameFile);
int numPoints;
if(ifile.good())
{
std::string str;
std::getline(ifile, str);
std::istringstream s(str);
s >> numPoints;
while (ifile.good())
{
std::string str;
std::getline(ifile, str);
if (ifile.good())
{
std::istringstream s(str);
SiftPoint sp;
s >> sp.x >> sp.y >> sp.scale >> sp.orientation;
if (!s.fail())
siftPoints.push_back(sp);
}
}
}
ifile.close();
return (!siftPoints.empty()) && (numPoints== siftPoints.size());
}
相关文章推荐
- Matlab中读取文件中数据的函数用法
- [黑马程序员]01 [c语言][重要的知识点]printf函数和scanf函数的数据输出与读取问题
- 6、关于《程序设计实践》中作者叙述gets读取数据会覆盖掉函数返回地址的思考,我认为作者叙述有误
- c语言 实现按行读取文件。把内容按照第三种内存模型打包数据传出,把行数通过函数参数传出
- 使用attach()函数时数据读取错误
- Discuz 5.0 中读取纯真IP数据函数分析
- linux sh : 由未实现函数引起bash读取2进制附加数据引起的报错
- R数据导入读取read.table函数详解
- 利用COM组件IPicture读取jpg、gif、bmp图片文件数据和显示图片的两个函数
- 【R】数据导入读取read.table函数详解,如何读取不规则的数据(fill=T)
- 函数:保存和读取yaml格式数据
- [C++] 使用C++编写的模拟 awk 的读取每行数据并分割成字段的函数
- C语言read()函数:读文件函数(由已打开的文件读取数据)
- 使用fscanf()函数从磁盘文件读取格式化数据
- matlab 函数或者GUI从工作空间读取参数数据
- 如何从文本文件读取数据到二维数组,如何在函数处理后返回二维数组的示例
- Matlab中xlsread 函数读取excel表格数据或者字符串
- R 数据导入读取read.table函数详解
- C语言sscanf()函数:从字符串中读取指定格式的数据&&C语言strtok()函数:字符串分割
- 数据库连接函数并读取TXT文本中的数据