HOG特征计算的python实现

        用于行人检测(Pedestrian Detection)的hog特征于2005年被N. Dalal和B. Triggs提出来。他们提出的算法可用于计算96×160图像的HOG特征提取。使用的数据集为INRIA Person Dataset。

HOG特征计算的python实现_第1张图片

下面的python代码片段用来为计算一张图片的HOG特征:

import numpy as np
from scipy import signal
import scipy.misc
def s_x(img):
    kernel = np.array([[-1, 0, 1]])
    imgx = signal.convolve2d(img, kernel, boundary='symm', mode='same')
    return imgx
def s_y(img):
    kernel = np.array([[-1, 0, 1]]).T
    imgy = signal.convolve2d(img, kernel, boundary='symm', mode='same')
    return imgy
def grad(img):
    imgx = s_x(img)
    imgy = s_y(img)
    s = np.sqrt(imgx**2 + imgy**2)
    theta = np.arctan2(imgx, imgy) #imgy, imgx)
    theta[theta<0] = np.pi + theta[theta<0]
    return (s, theta)

 

你可能感兴趣的:(python,HOG)