17 #include "openmvg_descriptor.hpp"
27 name_ =
'S' + (
'I' << 8) + (
'F' << 16) + (
'T' << 24);
28 version_ =
'V' + (
'5' << 8) + (
'.' << 16) + (
'0' << 24);
32 dp_ =
nullptr; lp_ =
nullptr;
37 name_(obj.name_), version_(obj.version_), npoint_(obj.npoint_),
38 nLocDim_(obj.nLocDim_), nDesDim_(obj.nDesDim_)
41 dp_ =
new DTYPE [obj.npoint_ * nDesDim_];
42 memcpy(dp_, obj.dp_,
sizeof(
DTYPE) * obj.npoint_ * nDesDim_);
45 lp_ =
new LTYPE [obj.npoint_ * nLocDim_];
46 memcpy(lp_, obj.lp_,
sizeof(
LTYPE) * obj.npoint_ * nLocDim_);
53 version_ = rhs.version_;
54 npoint_ = rhs.npoint_;
55 nLocDim_ = rhs.nLocDim_;
56 nDesDim_ = rhs.nDesDim_;
59 dp_ =
new DTYPE [rhs.npoint_ * nDesDim_];
60 memcpy(dp_, rhs.dp_,
sizeof(
DTYPE) * rhs.npoint_ * nDesDim_);
63 lp_ =
new LTYPE [rhs.npoint_ * nLocDim_];
64 memcpy(lp_, rhs.lp_,
sizeof(
LTYPE) * rhs.npoint_ * nLocDim_);
72 if (
nullptr != dp_)
delete [] dp_;
73 if (
nullptr != lp_)
delete [] lp_;
84 name_ =
'S' + (
'I' << 8) + (
'F' << 16) + (
'T' << 24);
85 version_ =
'V' + (
'5' << 8) + (
'.' << 16) + (
'0' << 24);
87 if((fd = fopen(szFileName.c_str(),
"rb")) ==
nullptr)
89 std::cerr <<
"[ReadSiftFile] Can't read sift file " << szFileName <<
'\n';
92 int f = fread(&name_,
sizeof(
int), 1, fd);
93 int g = fread(&version_,
sizeof(
int), 1, fd);
96 std::cerr <<
"[ReadSiftFile] Reading error\n";
100 if(name_ == (
'S'+ (
'I'<<8)+(
'F'<<16)+(
'T'<<24)))
103 a = fread(&npoint_,
sizeof(
int), 1, fd);
104 b = fread(&nLocDim_,
sizeof(
int), 1, fd);
105 c = fread(&nDesDim_,
sizeof(
int), 1, fd);
106 if(a != 1 || b != 1 || c!= 1)
108 std::cerr <<
"[ReadSiftFile] Reading error\n";
112 lp_ =
new LTYPE [npoint_ * nLocDim_];
113 dp_ =
new DTYPE [npoint_ * nDesDim_];
114 if(npoint_ >= 0 && nLocDim_ > 0 && nDesDim_ ==
FDIM)
117 d = fread(lp_,
sizeof(
LTYPE), nLocDim_ * npoint_, fd);
118 e = fread(dp_,
sizeof(
DTYPE), nDesDim_ * npoint_, fd);
119 if(d != nLocDim_ * npoint_ || e != nDesDim_ * npoint_)
121 std::cerr <<
"[ReadSiftFile] Reading error\n";
148 name_ =
'S' + (
'I' << 8) + (
'F' << 16) + (
'T' << 24);
149 version_ =
'V' + (
'5' << 8) + (
'.' << 16) + (
'0' << 24);
151 if((fd = fopen(szFileName.c_str(),
"rb")) ==
nullptr)
153 std::cout <<
"[ReadSiftFile] Can't read sift file " << szFileName <<
'\n';
156 int f = fread(&name_,
sizeof(
int), 1, fd);
157 int g = fread(&version_,
sizeof(
int), 1, fd);
160 std::cerr <<
"[ReadSiftFile] Reading error\n";
164 if(name_ == (
'S'+ (
'I'<<8)+(
'F'<<16)+(
'T'<<24)))
167 a = fread(&npoint_,
sizeof(
int), 1, fd);
168 b = fread(&nLocDim_,
sizeof(
int), 1, fd);
169 c = fread(&nDesDim_,
sizeof(
int), 1, fd);
170 if(a != 1 || b != 1 || c!= 1)
172 std::cerr <<
"[ReadSiftFile] Reading error\n";
176 lp_ =
new LTYPE [npoint_ * nLocDim_];
177 dp_ =
new DTYPE [npoint_ * nDesDim_];
178 unsigned char *temp_dp =
new unsigned char [npoint_ * nDesDim_];
179 if(npoint_ >= 0 && nLocDim_ > 0 && nDesDim_ ==
FDIM)
182 d = fread(lp_,
sizeof(
LTYPE), nLocDim_ * npoint_, fd);
183 e = fread(temp_dp,
sizeof(
unsigned char), nDesDim_ * npoint_, fd);
184 if(d != nLocDim_ * npoint_ || e != nDesDim_ * npoint_)
186 std::cerr <<
"[ReadSiftFile] Reading error\n";
190 for(
int i = 0; i < npoint_; i++)
192 DTYPE magnitude = 0.0;
193 for(
int j = 0; j < nDesDim_; j++)
195 magnitude += (
DTYPE) temp_dp[i*nDesDim_+j];
197 for(
int j = 0; j < nDesDim_; j++)
199 dp_[i*nDesDim_+j] = sqrt((
double) temp_dp[i*nDesDim_+j] / magnitude);
224 template <
typename T, std::
size_t N>
227 assert(
sizeof(T) ==
sizeof(
DTYPE) && N ==
FDIM &&
228 "Internal and external feature parameters are not consistent\n");
229 typedef std::vector<openMVG::Descriptor<T, N>> DescriptorsT;
230 typedef typename DescriptorsT::value_type VALUE;
231 DescriptorsT vec_desc;
234 std::ifstream fileIn(szFileName.c_str(), std::ios::in | std::ios::binary);
235 if(!fileIn.is_open())
237 std::cerr <<
"[ReadOpenmvgDesc] Fail to load openmvg desc file.\n";
241 std::size_t cardDesc = 0;
242 fileIn.read((
char*) &cardDesc,
sizeof(std::size_t));
246 lp_ =
new LTYPE [npoint_ * nLocDim_];
247 for(
size_t i = 0; i < npoint_ * nLocDim_; i++)
251 dp_ =
new DTYPE [npoint_ * nDesDim_];
252 fileIn.read((
char*)dp_, VALUE::static_size*
sizeof(
typename VALUE::bin_type)*npoint_);
253 bool bOk = !fileIn.bad();
262 if((fd = fopen(szFileName.c_str(),
"wb")) ==
nullptr)
264 std::cerr <<
"[SaveSiftFile] Can't open file " << szFileName <<
" for saving\n";
267 int f = fwrite(&name_,
sizeof(
int), 1, fd);
268 int g = fwrite(&version_,
sizeof(
int), 1, fd);
271 std::cerr <<
"[SaveSiftFile] Writing error\n";
275 if(name_ == (
'S'+ (
'I'<<8)+(
'F'<<16)+(
'T'<<24)))
278 a = fwrite(&npoint_,
sizeof(
int), 1, fd);
279 b = fwrite(&nLocDim_,
sizeof(
int), 1, fd);
280 c = fwrite(&nDesDim_,
sizeof(
int), 1, fd);
281 if(a != 1 || b != 1 || c!= 1)
283 std::cerr <<
"[SaveSiftFile] Write error\n";
287 if(npoint_ >= 0 && nLocDim_ > 0 && nDesDim_ ==
FDIM)
290 d = fwrite((
void*) lp_,
sizeof(
LTYPE), nLocDim_ * npoint_, fd);
291 e = fwrite((
void*) dp_,
sizeof(
DTYPE), nDesDim_ * npoint_, fd);
292 if(d != nLocDim_ * npoint_ || e != nDesDim_ * npoint_)
294 std::cerr <<
"[SaveSiftFile] Writing error\n";
324 if (
nullptr != dp_)
delete [] dp_;
325 if (
nullptr != lp_)
delete [] lp_;
326 dp_ =
nullptr; lp_ =
nullptr;
DTYPE *& getDesPointer()
Definition: data_types.h:331
#define LTYPE
Definition: global_params.h:42
#define DTYPE
Definition: global_params.h:41
void setLocDim(int loc_dim)
Definition: data_types.h:316
SiftData & operator=(const SiftData &rhs)
Definition: data_types.h:50
#define FDIM
Definition: global_params.h:43
void setDesDim(int des_dim)
Definition: data_types.h:318
const int getLocDim() const
Definition: data_types.h:315
void setVersion(int version)
Definition: data_types.h:320
bool ReadOpenmvgDesc(std::string const &szFileName)
ReadOpenmvgDesc: read desc file of openmvg.
Definition: data_types.h:225
void clear()
Definition: data_types.h:322
bool ReadSiftFile(std::string const &szFileName)
ReadSiftFile: read sift file, this function is compatible with the sfm version of sift file...
Definition: data_types.h:82
~SiftData()
Definition: data_types.h:70
LTYPE *& getLocPointer()
Definition: data_types.h:330
Sift data structure used in libvot.
Definition: data_types.h:22
const int getFeatureNum() const
Definition: data_types.h:313
global parameters and utility functions
namespace tw is mostly related to some utility functions developed by the repository owner...
Definition: opencv_libvot_api.cpp:12
SiftData()
Definition: data_types.h:25
void setFeatureNum(int feat_num)
Definition: data_types.h:314
bool SaveSiftFile(std::string const &szFileName)
Definition: data_types.h:259
const int getDesDim() const
Definition: data_types.h:317
SiftData(const SiftData &obj)
Definition: data_types.h:36
const int getVersion() const
Definition: data_types.h:319
bool ReadChar2DTYPE(std::string const &szFileName)
ConvertChar2Float: Read a char sift file and convert it to DTYPE(float/double) sift. The descriptors are L1 normalized and then square-rooted (RootSift)
Definition: data_types.h:146