😏Svm Hog Pedestrian

import cv2

# default 디덱터λ₯Ό μœ„ν•œ HOG 객체 생성 및 μ„€μ •--- β‘ 
hogdef = cv2.HOGDescriptor()
hogdef.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

# dailer 디덱터λ₯Ό μœ„ν•œ HOG 객체 생성 및 μ„€μ •--- β‘‘
hogdaim  = cv2.HOGDescriptor((48,96), (16,16), (8,8), (8,8), 9)
hogdaim.setSVMDetector(cv2.HOGDescriptor_getDaimlerPeopleDetector())

cap = cv2.VideoCapture('../img/walking.avi')
mode = True  # λͺ¨λ“œ λ³€ν™˜μ„ μœ„ν•œ ν”Œλž˜κ·Έ λ³€μˆ˜ 
print('Toggle Space-bar to change mode.')
while cap.isOpened():
    ret, img = cap.read()
    if ret :
        if mode:
            # default λ””ν…ν„°λ‘œ λ³΄ν–‰μž κ²€μΆœ --- β‘’
            found, _ = hogdef.detectMultiScale(img)
            for (x,y,w,h) in found:
                cv2.rectangle(img, (x,y), (x+w, y+h), (0,255,255))
        else:
            # daimler λ””ν…ν„°λ‘œ λ³΄ν–‰μž κ²€μΆœ --- β‘£
            found, _ = hogdaim.detectMultiScale(img)
            for (x,y,w,h) in found:
                cv2.rectangle(img, (x,y), (x+w, y+h), (0,255,0))
        cv2.putText(img, 'Detector:%s'%('Default' if mode else 'Daimler'), \
                        (10,50 ), cv2.FONT_HERSHEY_DUPLEX,1, (0,255,0),1)
        cv2.imshow('frame', img)
        key = cv2.waitKey(1) 
        if key == 27:
            break
        elif key == ord(' '):
            mode = not mode
    else:
        break
cap.release()
cv2.destroyAllWindows()

μ‹€μŠ΅κ²°κ³Ό