Skip to content

Instantly share code, notes, and snippets.

@Thelta
Created June 11, 2018 14:16
Show Gist options
  • Select an option

  • Save Thelta/ac57ab908de9d5b7900fa8f2b7d547c7 to your computer and use it in GitHub Desktop.

Select an option

Save Thelta/ac57ab908de9d5b7900fa8f2b7d547c7 to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
surf = cv2.xfeatures2d.SURF_create()
trainer = cv2.BOWKMeansTrainer(300)
for i in range(0, 300):
image = np.random.randint(255, size=(400, 400), dtype=np.uint8)
_, desc = surf.detectAndCompute(image, None)
trainer.add(desc)
print(str(i) + " " + str(len(desc)))
dict_ = trainer.cluster()
fs_write = cv2.FileStorage('dict.json', cv2.FILE_STORAGE_WRITE)
fs_write.write("dict", dict_)
fs_write.release()
print(dict_.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment