1 ImportCv22 ImportNumPy as NP3 4 5 defOLBP (src):6DST = Np.zeros (src.shape,dtype=Src.dtype)7 forIinchRange (1,src.shape[0]-1):8 forJinchRange (1,src.shape[1]-1):9 PassTenCenter =src[i][j] oneCode =0; aCode |= (src[i-1][j-1] >= center) << 7; -Code |= (src[i-1][j] >= center) << 6; -Code |= (src[i-1][j+1] >= center) << 5; theCode |= (src[i][j+1] >= center) << 4; -Code |= (src[i+1][j+1] >= center) << 3; -Code |= (src[i+1][j] >= center) << 2; -Code |= (src[i+1][j-1] >= center) << 1; +Code |= (src[i][j-1] >= center) <<0; - +dst[i-1][j-1]=code; a returnDST at - -Lena = Cv2.imread ('d:/lena.jpg') -Cv2.namedwindow ('Lena') -Cv2.imshow ('Lena', Lena) - Cv2.waitkey (0) in -Gray =Cv2.cvtcolor (lena,cv2. Color_rgb2gray) tox =OLBP (gray) + -Cv2.namedwindow ('OLBP') theCv2.imshow ('OLBP', X) *Cv2.waitkey (0)
Implementation of LBP feature point calculation with Python