Is there any Python demo to read the .sift file from VisualSFM?
ZeroSteven618 opened this issue · 1 comments
After VisualSFM each image will generate a sift file and the SIFT feature points descriptors data is in the file.
It seems vital to get the descriptors into h5 files as "img-kp-minsc-2.0.h5" files to finish LIFT training pre-processing.
However, the sift files from VisualSFM are binary files and according to: http://ccwu.me/vsfm/doc.html#usage
The sift files are in the format in description in **"Use your own feature detectors"** part as follows:
[Header][Location Data][Descriptor Data][EOF]
[Header] = int[5] = {name, version, npoint, 5, 128};
name = ('S'+ ('I'<<8)+('F'<<16)+('T'<<24));
version = ('V'+('4'<<8)+('.'<<16)+('0'<<24)); or ('V'+('5'<<8)+('.'<<16)+('0'<<24)) if containing color info
npoint = number of features.
[Location Data] is a npoint x 5 float matrix and each row is [x, y, color, scale, orientation].
Write color by casting the float to unsigned char[4]
scale & orientation are only used for visualization, so you can simply write 0 for them
- Sort features in the order of decreasing importance, since VisualSFM may use only part of those features.
- VisualSFM sorts the features in the order of decreasing scales.
[Descriptor Data] is a npoint x 128 unsigned char matrix. Note the feature descriptors are normalized to 512.
[EOF] int eof_marker = (0xff+('E'<<8)+('O'<<16)+('F'<<24));
But I still can not understand the instruction.
How to read the sift file properly in Python code?
What is the encoding parameter of the open("r", encoding) function? 'utf-8' is not right to read the sift files.
I tried encoding='utf-16' but also failed.
With the help of Notepad++ Hex-Editor plugin, I understand the [Header] part but I still can not work out the rest parts.
Can someone help me with the sift file data reading with Python? Thanks a lot!
Does anybody have this?