import cv2
def is_inside(o,i):
ox,oy,ow,oh = o
ix,iy,iw,ih = i
return ox>ix and oy>iy and ox+ow<ix+iw and oy+oh<iy+ih
def draw_person(image,person):
x,y,w,h=person
cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),1)
# 使用opencv的hog特征进行行人检测
img = cv2.imread("test/people.jpg")
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
found, w = hog.detectMultiScale(img)
print(found,w)
foundList = []
for ri,r in enumerate(found):
flag = 0
for qi,q in enumerate(found):
if ri != qi and is_inside(r,q):
flag = 1
if(flag == 0):
foundList.append(r)
for person in foundList:
draw_person(img,person)
cv2.imwrite("./test1.jpg",img)
cv2.imshow("face", img)
cv2.waitKey(0)
cv2.destroyAllWindows
import cv2def is_inside(o,i): ox,oy,ow,oh = o ix,iy,iw,ih = i return ox>ix and oy>iy and ox+ow<ix+iw and oy+oh<iy+ihdef draw_person(image,person): x,y,w,h=person cv2.rectangle(image,(x,y),(x+w,y+h),(0,0,255),1)# 使用ope.