-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhog_utils.py
35 lines (28 loc) · 1.18 KB
/
hog_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cv2
from skimage.feature import hog
def compute_hog_features(image, orient, pixels_per_cell, cells_per_block):
"""Computes hog features from a single image.
:param image: image in grayscale
:param orient: number of HoG orientations
:param pixels_per_cell: number of pixels per cell
:param cells_per_block: number of HoG cells per block
:returns: a list of feature vectors.
"""
grayscale = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
return hog(
grayscale,
orientations=orient,
pixels_per_cell=(pixels_per_cell, pixels_per_cell),
cells_per_block=(cells_per_block, cells_per_block),
transform_sqrt=True,
feature_vector=True
)
def extract_features(images, orient, pixels_per_cell, cells_per_block):
"""Extracts hog features from the given list of images.
:param images: a list of images in grayscale
:param orient: number of HoG orientations
:param pixels_per_cell: number of pixels per cell
:param cells_per_block: number of HoG cells per block
:returns: a list of feature vectors.
"""
return [compute_hog_features(image, orient, pixels_per_cell, cells_per_block) for image in images]