('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.COLORBGR2GRAY)
, des = sift.detectAndCompute(image, None)
if des is not None:
return np.mean(des, axis=0).astype('float32')
else:
return np.zeros(128)
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)),
]
def compute_feature(frame): sift = cv2.xfeatures2d.SIFT_create() image = cv2.cvtColor(frame, cv2.COLORBGR2GRAY) , 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