HOG Descriptor using Python + OpenCV

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

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

回答1:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!