def _sift_read(f, mode='SIFT'):
 if (not hasattr(f, 'readline')):
  f = open(f, 'r')
 if (mode == 'SIFT'):
  (nr_features, feature_len) = map(int, f.readline().split())
  datatype = np.dtype([('row', float), ('column', float), ('scale', float), ('orientation', float), ('data', (float, feature_len))])
 else:
  mode = 'SURF'
  feature_len = (int(f.readline()) - 1)
  nr_features = int(f.readline())
  datatype = np.dtype([('column', float), ('row', float), ('second_moment', (float, 3)), ('sign', float), ('data', (float, feature_len))])
 data = np.fromfile(f, sep=' ')
 if (data.size != ((nr_features * datatype.itemsize) / np.dtype(float).itemsize)):
  raise IOError(('Invalid %s feature file.' % mode))
 f.close()
 return data.view(datatype)

def _sift_read ( f , mode = 'SIFT' ) : if ( not hasattr ( f , 'readline' ) ) : f = open ( f , 'r' ) if ( mode == 'SIFT' ) : ( nr_features , feature_len ) = map ( int , f . readline ( ) . split ( ) ) datatype = np . dtype ( [ ( 'row' , float ) , ( 'column' , float ) , ( 'scale' , float ) , ( 'orientation' , float ) , ( 'data' , ( float , feature_len ) ) ] ) else : mode = 'SURF' feature_len = ( int ( f . readline ( ) ) - 1 ) nr_features = int ( f . readline ( ) ) datatype = np . dtype ( [ ( 'column' , float ) , ( 'row' , float ) , ( 'second_moment' , ( float , 3 ) ) , ( 'sign' , float ) , ( 'data' , ( float , feature_len ) ) ] ) data = np . fromfile ( f , sep = ' ' ) if ( data . size != ( ( nr_features * datatype . itemsize ) / np . dtype ( float ) . itemsize ) ) : raise IOError ( ( 'Invalid %s feature file.' % mode ) ) f . close ( ) return data . view ( datatype )
read sift or surf features from externally generated file .