python类feature()的实例源码

feature_extractor.py 文件源码 项目:cv-utils 作者: gmichaeljaison 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def factory(feature):
    """
    Factory to choose feature extractor

    :param feature: name of the feature
    :return: Feature extractor function
    """
    if feature == 'hog':
        return hog
    elif feature == 'deep':
        return deep
    elif feature == 'gray':
        return gray
    elif feature == 'lab':
        return lab
    elif feature == 'luv':
        return luv
    elif feature == 'hsv':
        return hsv
    elif feature == 'hls':
        return hls
    else:
        return rgb
feature_extractor.py 文件源码 项目:cv-utils 作者: gmichaeljaison 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def hog(img, options=None):
    """
    HOG feature extractor.

    :param img:
    :param options:
    :return: HOG Feature for given image
        The output will have channels same as number of orientations.
        Height and Width will be reduced based on block-size and cell-size
    """
    op = _DEF_HOG_OPTS.copy()
    if options is not None:
        op.update(options)

    img = gray(img)
    img_fd = skimage.feature.hog(img,
                                 orientations=op['orientations'],
                                 pixels_per_cell=op['cell_size'],
                                 cells_per_block=op['block_size'],
                                 visualise=False)
    h, w = img.shape

    cx, cy = op['cell_size']
    n_cellsx, n_cellsy = w // cx, h // cy

    bx, by = op['block_size']
    n_blksx, n_blksy = (n_cellsx - bx) + 1, (n_cellsy - by) + 1

    hog_shape = n_blksy * by, n_blksx * bx, op['orientations']

    image_hog = np.reshape(img_fd, hog_shape)
    return image_hog


问题


面经


文章

微信
公众号

扫码关注公众号