Skip to content

Instantly share code, notes, and snippets.

@GertjanBrouwer
Last active August 7, 2019 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GertjanBrouwer/5c09af534fe5a7dc0343155b9b0edb7f to your computer and use it in GitHub Desktop.
Save GertjanBrouwer/5c09af534fe5a7dc0343155b9b0edb7f to your computer and use it in GitHub Desktop.
write_sift_desc_to_fvecs.py
grayImg = cv2.imread('../my-images/' + row[1], 0)
keypoints, descriptors = sift.detectAndCompute(grayImg, None)
descriptors = np.insert(descriptors, 0, 128, 1)
vectorArray = np.concatenate((vectorArray, descriptors), axis = 0)
vectorArray.astype(np.int32).tofile('./my_sift_descriptors.fvecs')
#the above code is faulty and should first insert an int32 of with the dimension as value and subsequently float32 values of the vector itself
#the following code is correct:
#assuming you calculated descriptors with SIFT and have opened an output file with 'wb' flag
for descriptor in descriptors:
dimension_array = array('i', [128])
dimension_array.tofile(output_file)
float_array = array('f', descriptor)
float_array.tofile(output_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment