hog.py 1.11 KB
Newer Older
1 2 3 4 5 6
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
"""
    Extract HOG (Histogram of Oriented Gradient) feature.
    
7 8
    Dalal, N and Triggs, B, Histograms of Oriented Gradients for Human Detection, IEEE Computer Society Conference on Computer Vision and Pattern Recognition 2005 San Diego, CA, USA
    
9 10 11 12 13 14 15 16 17 18 19 20
    Name: hog.py
    Author: Alessandro dos Santos Ferreira ( santosferreira.alessandro@gmail.com )
"""
from skimage import feature

from util.utils import ImageUtils

from extractor import Extractor

class HOG(Extractor):

    
21 22
    def __init__(self):
        pass        
23 24
        
    
25
    def run(self, image):
26
        
27 28
        image_grayscale = ImageUtils.image_grayscale(image, bgr = True)
        image_128x128 = ImageUtils.image_resize(image_grayscale, 128, 128)
29
        
30
        values, _ = feature.hog(image_128x128, orientations=8, pixels_per_cell=(32, 32),
31
                    cells_per_block=(1, 1), visualise=True)
32 33 34
                    
        labels = [m+n for m,n in zip(['hog_'] * len(values),map(str,range(0,len(values))))]
        types = [Extractor.NUMERIC] * len(labels)
35 36

        return labels, types, list(values)