Hog+SVM行人检测
2020-03-22 本文已影响0人
陨星落云
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 16:17:14 2020
@author: 陨星落云
"""
import cv2
img = cv2.imread("people-brasil-guys-avpaulista-109919.jpg")
cv2.namedWindow('input',cv2.WINDOW_NORMAL)
cv2.imshow("input", img)
hog = cv2.HOGDescriptor()
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
# 行人检测
(rects, weights) = hog.detectMultiScale(img,
winStride=(4, 4),
padding=(8, 8),
scale=1.25,
useMeanshiftGrouping=False)
for (x, y, w, h) in rects:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.namedWindow('hog-detector',cv2.WINDOW_NORMAL)
cv2.imshow("hog-detector", img)
cv2.imwrite('hog-detector_result.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
结果:
hog-detector_result.jpg