使用Python + OpenCV的HOG描述符 [英] HOG Descriptor using Python + OpenCV

查看:2343
本文介绍了使用Python + OpenCV的HOG描述符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV实现HOG描述符,以便在视频中检测行人。我目前正在使用OpenCV hogcascade_pedestrians.xml 的预制数据集。尽管HOG描述符对人类检测非常有效,但是这部分的文档在互联网上非常差。我一直用Python编写行人检测代码,我已停止使用以下代码:

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()

我认为代码脚本就像是为Haar Cascades编写的代码。但我已经尝试过,但我得到了错误。有没有人知道如何用Python在OpenCV上实现HOG描述符。

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.

注意:我正在使用OpenCV 3.1.0-dev和Python 2.7.11

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

推荐答案

HOGCascade = cv2.HOGDescriptor()

如果你想使用这个 .xml ,你有很多准备工作要做。

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

当你最终得到可用的描述符时,你应该在
中替换 cv2.HOGDescriptor_getDefaultPeopleDetector() setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

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

这篇关于使用Python + OpenCV的HOG描述符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆