from skimage import feature import matplotlib.pyplot as plt import numpy as np import cv2 method_distance=[cv2.HISTCMP_CORREL, cv2.HISTCMP_CHISQR, cv2.HISTCMP_INTERSECT, cv2.HISTCMP_BHATTACHARYYA, cv2.HISTCMP_HELLINGER, cv2.HISTCMP_CHISQR_ALT, cv2.HISTCMP_KL_DIV] method_lbp=['default', 'ror', 'uniform', 'var'] cap=cv2.VideoCapture(0) numPoints=24 radius=3 image_ref=None width=320 height=240 windowsize_r=30 windowsize_c=30 rows=int(height/windowsize_r) cols=int(width/windowsize_c) tab_score=np.empty((rows, cols), dtype=np.float32) id_method_distance=6 id_method_lbp=2 seuil=0.3 while True: ret, frame=cap.read() image=cv2.resize(frame, (width, height)) if image_ref is not None: gray=cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) for r in range(rows): for c in range(cols): window=gray[r*windowsize_r:(r+1)*windowsize_r, c*windowsize_c:(c+1)*windowsize_c] lbp=feature.local_binary_pattern(window, numPoints, radius, method=method_lbp[id_method_lbp]) hist, _=np.histogram(lbp, normed=True, bins=numPoints, range=(0, numPoints)) score=cv2.compareHist(hist.astype(np.float32), hist_ref.astype(np.float32), method_distance[id_method_distance]) tab_score[r, c]=score if image_ref is not None: tab_score2=np.zeros_like(tab_score) tab_score2[tab_score