def test_descriptors():
img = cv2.imread(constants.TESTING_IMG_PATH)
cv2.imshow("Normal Image", img)
print("Normal Image")
option = input("Enter [1] for using ORB features and other number to use SIFT.\n")
start = time.time()
if option == 1:
orb = cv2.ORB()
kp, des = orb.detectAndCompute(img, None)
else:
sift = cv2.SIFT()
kp, des = sift.detectAndCompute(img, None)
end = time.time()
elapsed_time = utils.humanize_time(end - start)
des_name = constants.ORB_FEAT_NAME if option == ord(constants.ORB_FEAT_OPTION_KEY) else constants.SIFT_FEAT_NAME
print("Elapsed time getting descriptors {0}".format(elapsed_time))
print("Number of descriptors found {0}".format(len(des)))
if des is not None and len(des) > 0:
print("Dimension of descriptors {0}".format(len(des[0])))
print("Name of descriptors used is {0}".format(des_name))
img2 = cv2.drawKeypoints(img, kp)
# plt.imshow(img2), plt.show()
cv2.imshow("{0} descriptors".format(des_name), img2)
print("Press any key to exit ...")
cv2.waitKey()
评论列表
文章目录