HOG--行人检测
import cv2
import numpy as np
def is_inside(o,i):
ox,oy,ow,oh = o
ix,iy,iw,ih = i
if ox>ix and oy>iy and ox+ow<ix+iw and oy+oh <iy+ih:
return True
return False
def draw_peron(img,p):
x,y,w,h = p
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
img = cv2.imread("../images/people.jpg")
hog = cv2.HOGDescriptor()
# 设置hog为检测人的默认的检测器
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
k,d = hog.detectMultiScale(img)
person = []
for i,m in enumerate(k):
for j,n in enumerate(k):
if i != j and is_inside(m,n):
break
else:
person.append(m)
for p in person:
draw_peron(img,p)
cv2.imshow("people",img)
cv2.waitKey()
cv2.destroyAllWindows()