首先使用skimage进行计算和显示,需要安装 scikit-image
conda install scikit-image
代码参考 https://blog.csdn.net/mago2015/article/details/85320347
from skimage.feature import hog
from skimage import io
from PIL import Image
import cv2
img = cv2.imread('a.jpeg', cv2.IMREAD_GRAYSCALE)
print(img.shape)
normalised_blocks, hog_image = hog(img, orientations=9, pixels_per_cell=(8, 8), cells_per_block=(8, 8), block_norm='L2-Hys',visualize=True)
print(hog_image.shape)
io.imshow(hog_image)
io.show()
原始图片为:
计算后的图片为:
下面是使用OpenCV进行计算,仅供参考:
import cv2
hog = cv2.HOGDescriptor()
im = cv2.imread("a.jpeg")
h = hog.compute(im)
print(h.shape)