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