Last active
August 7, 2019 13:29
-
-
Save GertjanBrouwer/5c09af534fe5a7dc0343155b9b0edb7f to your computer and use it in GitHub Desktop.
write_sift_desc_to_fvecs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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