import cv2 as cv
#读入数据,并转为灰度图
img = cv.imread("1.jpg", cv.COLOR_BGR2GRAY)
#展示原图
cv.imshow("原图",img)
#声明一个HOG描述器
hog = cv.HOGDescriptor()
#将训练好的模型导入
#hog.load('myHogDector.bin')
hog.setSVMDetector(cv.HOGDescriptor_getDefaultPeopleDetector())
#对img多尺度进行预测
rects, _ = hog.detectMultiScale(img, winStride=(4, 4), padding=(8, 8), scale=1.05)
#修正识别框(参数可调)
for (x,y,w,h) in rects:
x = int(x + w * 0.1)
y = int(y + h * 0.05)
w = int(w * 0.7)
h = int(h * 0.8)
#将识别到的框绘制到img图像上
cv.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
#cv.imshow('{}'.format(0),img)
#显示识别结果
cv.imshow("识别结果",img)
#暂停查看结果
cv.waitKey(0)

