forked from avinashkranjan/Amazing-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_hog.py
executable file
·52 lines (41 loc) · 1.07 KB
/
get_hog.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# *^_^* coding:utf-8 *^_^*
from __future__ import print_function
__author__ = 'stone'
__date__ = '16-1-22'
import cv2
import numpy as np
import os
direction = 'clips'
hog_save_directory = 'hog/'
def hog_feature(img):
"""
Extract HOG feature
"""
win_size = (16, 16)
block_size = (16, 16)
block_stride = (8, 8)
cell_size = (8, 8)
nbins = 9
descriptor = cv2.HOGDescriptor(
win_size, block_size, block_stride, cell_size, nbins)
hog = descriptor.compute(img)
return hog
def file_path(directory):
"""
generate a full directory path
"""
files = os.listdir(directory)
path = []
for name in files:
full_name = os.path.join(directory, name)
path.append(full_name)
print('%s 的文件数: %d\n' % (directory, len(path)))
return path
if __name__ == '__main__':
path = file_path(direction)
for i in path:
img = cv2.imread(i)
hog = hog_feature(img)
hog_file = '%s%s.txt' % (hog_save_directory, i.split('/')[-1])
print(hog)
np.savetxt(hog_file, hog)