Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIFT difinition no SIFT.get_distance_fn #45

Open
scutzhe opened this issue Mar 20, 2019 · 0 comments
Open

SIFT difinition no SIFT.get_distance_fn #45

scutzhe opened this issue Mar 20, 2019 · 0 comments

Comments

@scutzhe
Copy link

scutzhe commented Mar 20, 2019

def get_feature_and_dist_fns(feature_type):
if feature_type == 'hog':
return (HOG.compute_feature, HOG.get_distance_fn, HOG.DIST_METRICS)
elif feature_type == 'sift':
return (SIFT.compute_feature, SIFT.get_distance_fn, SIFT.DIST_METRICS)
elif feature_type == 'ch':
return (ColorHistogram.compute_feature, ColorHistogram.get_distance_fn, ColorHistogram.DIST_METRICS)
elif feature_type == 'raw':
return (RawImage.compute_feature, RawImage.get_distance_fn, RawImage.DIST_METRICS)

import cv2
import numpy as np
from scipy.spatial.distance import euclidean, cityblock, chebyshev, cosine

DIST_METRICS = [
('euclidean', euclidean),
('manhattan', cityblock),
('chebyshev', chebyshev),
('cosine', lambda x, y: -1*cosine(x, y)),
#('chisqr', lambda x, y: cv2.compareHist(x, y, cv2.HISTCMP_CHISQR)),
#('bhatta', lambda x, y: cv2.compareHist(x, y, cv2.HISTCMP_BHATTACHARYYA))
]

def compute_feature(frame):
sift = cv2.xfeatures2d.SIFT_create()
image = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
_, des = sift.detectAndCompute(image, None)
if des is not None:
return np.mean(des, axis=0).astype('float32')
else:
return np.zeros(128)

SIFT difinition no SIFT.get_distance_fn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant