代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: lancezhange
# @Date: 2015-08-18 11:28:02
# @Last Modified by: root
# @Last Modified time: 2015-08-25 14:48:57
from __future__ import division
import cv2
import numpy as np
from skimage.feature import hog
def getFeature(image, blocks=5):
'''
Given an cv2 Image object it returns its feature vector.
Args:
image (ndarray): image to process.
blocks (int, optional): number of block to subdivide the RGB space into.
Returns:
numpy array.
'''
image_resized = cv2.resize(image, (64, 64))
imgray = cv2.cvtColor(image_resized, cv2.COLOR_RGB2GRAY)
feature = np.zeros(blocks * blocks * blocks + 144) # 144 for hog
width, height, channel = image_resized.shape
pixel_count = width * height
r = ((image[:, :, 2]) / (256 / blocks)).astype("int")
g = ((image[:, :, 1]) / (256 / blocks)).astype("int")
b = ((image[:, :, 0]) / (256 / blocks)).astype("int")
result = r + g * blocks + b * blocks * blocks
unique, counts = np.unique(result, return_counts=True)
feature[unique] = counts
feature = feature / (pixel_count)
feature_hog = hog(
imgray, orientations=9,
pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualise=False)
feature[blocks**3:] = feature_hog
return feature
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。