hog函数的用法 python,使用Python + OpenCV的HOG描述符

本文介绍如何使用OpenCV的HOGDescriptor进行视频中的人行道检测。作者使用了预训练的hogcascade_pedestrians.xml文件,并分享了实现过程中遇到的问题及解决方法。

I am trying to implement HOG Descriptor with OpenCV to detect Pedestrians in a video. I am currently using the pre-made dataset by OpenCV hogcascade_pedestrians.xml. Unfortuntley the documentation on this part is very poor on the internet although the HOG Descriptor is very effective for human detection. I have been writing a code for pedestrians detection with Python, and I have stopped at the following code:

import cv2

import numpy as np

import imutils

VidCap = cv2.VideoCapture('pedestrians.mp4')

HOGCascade = cv2.HOGDescriptor('hogcascade_pedestrians.xml')

HOGCascade.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

while True:

_ , image = VidCap.read()

image = imutils.resize(image, width=700)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

clahe = cv2.createCLAHE(clipLimit=15.0,tileGridSize=(8,8))

gray = clahe.apply(gray)

winStride = (8,8)

padding = (16,16)

scale = 1.05

meanshift = -1

(rects, weights) = HOGCascade.detectMultiScale(gray, winStride=winStride,

padding=padding,

scale=scale,

useMeanshiftGrouping=meanshift)

for (x, y, w, h) in rects:

cv2.rectangle(image, (x, y), (x+w, y+h), (0,200,255), 2)

cv2.imshow('Image', image)

if cv2.waitKey(5) == 27:

break

VidCap.release()

cv2.destroyAllWindows()

I presume that the code scripting would be something like codes written for Haar Cascades. But I have tried that and I got errors. Do anyone have any idea of how to implement the HOG Descriptor on OpenCV with Python.

I have read the following question, but I get nothing from the second answer.

My problem is that I can't find the way to write the code, as the documentation about this part is very poor.

Note: I am using OpenCV 3.1.0-dev with Python 2.7.11

解决方案HOGCascade = cv2.HOGDescriptor()

If you want to use this .xml, You have lots of preparation work to do.

When u finally get the available descriptor, you should replace the cv2.HOGDescriptor_getDefaultPeopleDetector() in

setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值