2 Star 1 Fork 1

mayanhui/smoke_recognition

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
feature_OBR_BOW.py 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
lancezhange 提交于 2015-12-08 21:50 . first commit
#!/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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/TimVerion/smoke_recognition.git
git@gitee.com:TimVerion/smoke_recognition.git
TimVerion
smoke_recognition
smoke_recognition
master

搜索帮助