python 계산 포인트 그래프와haar 특징
2386 단어 ml
import cv2
import numpy as np
import matplotlib.pyplot as plt
#
#
#
def integral(img):
integ_graph = np.zeros((img.shape[0],img.shape[1]),dtype = np.int32)
for x in range(img.shape[0]):
sum_clo = 0
for y in range(img.shape[1]):
sum_clo = sum_clo + img[x][y]
integ_graph[x][y] = integ_graph[x-1][y] + sum_clo;
return integ_graph
# Types of Haar-like rectangle features
# --- ---
# | | |
# | - | + |
# | | |
# --- ---
#
# haar
#
def getHaarFeaturesArea(width,height):
widthLimit = width-1
heightLimit = height/2-1
features = []
for w in range(1,int(widthLimit)):
for h in range(1,int(heightLimit)):
wMoveLimit = width - w
hMoveLimit = height - 2*h
for x in range(0, wMoveLimit):
for y in range(0, hMoveLimit):
features.append([x, y, w, h])
return features
#
# haar
#
def calHaarFeatures(integral_graph,features_graph):
haarFeatures = []
for num in range(len(features_graph)):
#
haar1 = integral_graph[features_graph[num][0]][features_graph[num][1]]-\
integral_graph[features_graph[num][0]+features_graph[num][2]][features_graph[num][1]] -\
integral_graph[features_graph[num][0]][features_graph[num][1]+features_graph[num][3]] +\
integral_graph[features_graph[num][0]+features_graph[num][2]][features_graph[num][1]+features_graph[num][3]]
#
haar2 = integral_graph[features_graph[num][0]][features_graph[num][1]+features_graph[num][3]]-\
integral_graph[features_graph[num][0]+features_graph[num][2]][features_graph[num][1]+features_graph[num][3]] -\
integral_graph[features_graph[num][0]][features_graph[num][1]+2*features_graph[num][3]] +\
integral_graph[features_graph[num][0]+features_graph[num][2]][features_graph[num][1]+2*features_graph[num][3]]
#
haarFeatures.append(haar2-haar1)
return haarFeatures
img = cv2.imread("faces/face00001.bmp",0)
integeralGraph = integral(img)
featureAreas = getHaarFeaturesArea(img.shape[0],img.shape[1])
haarFeatures = calHaarFeatures(integeralGraph,featureAreas)
print(haarFeatures)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
로드 cifar10 데이터 세트텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.