灰度特征
代码如下:
def img2cols(self, img):
img = img.reshape(img.size, order="C")
# convert the data type as np.float64
img = img.astype(np.float64)
return img
HOG特征
代码如下:
def HOG_features(self, im):
hog = cv2.HOGDescriptor()
winStride = (8, 8)
padding = (8, 8)
hist = hog.compute(im, winStride, padding)
hist = hist.reshape((-1,))
return hist
LBP特征
def LBP_features(self, im):
im = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
# settings for LBP
radius = 3
n_points = 8 * radius
lbp_img = local_binary_pattern(im, n_points, radius)
lbp = self.img2cols(lbp_img)
# cv2.imshow("", lbp)
# cv2.waitKey(0)
return lbp