【问题标题】:Pedestrian detection with HOG descriptor and SVM understanding the python code行人检测与 HOG 描述符和 SVM 理解 Python 代码
【发布时间】:2019-12-03 03:16:05
【问题描述】:

我正在尝试使用 HOG 和 SVM 了解 Python 中的行人检测代码,以使用 FPGA 对其进行加速。

以下从网站复制的代码工作正常

hog = cv2.HOGDescriptor()                              
hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())

def detector(image):
   rects, weights = hog.detectMultiScale(image, winStride=(4, 4), padding=(8, 8),scale=1.05)                                 
   for (x, y, w, h) in rects:
       cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)       
       cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)        
   rects = np.array([[x, y, x + w, y + h] for (x, y, w, h) in rects])      
   result = non_max_suppression(rects, probs=None, overlapThresh=0.7)
   return result

frame = cv2.imread("/.../pedestrian2.jpg")
result = detector(frame.copy())
for (xA, yA, xB, yB) in result:     # draw the final bounding boxes after non-maxima supression
    cv2.rectangle(frame, (xA, yA), (xB, yB), (0, 255, 0), 2)
img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)      
img_out = PIL.Image.fromarray(img)
img_out

按照教程 https://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial/ 我知道主要功能是 hog.compute(im,descriptor) 计算图像的 HOG 特征,但是第一个代码中的这个函数在哪里?它是否在其中一个函数内?

【问题讨论】:

    标签: python opencv detection


    【解决方案1】:

    虽然“解释这段代码”对于本网站来说有点过于宽泛,但“第一个代码上的这个函数在哪里”这个狭隘的问题:不是。但是,它已在您链接的教程中进行了讨论。

    在发布代码的开头,您将cv2.HOGDescriptor() 对象实例化为hog。一旦创建,该对象将具有 cv2.HOGDescriptor() 类的所有绑定属性和方法,包括 .compute() 方法,一旦您调用它。

    this question 有一些关于基本用法的讨论,here is a link 有一些关于 HOGDescriptor` 类的基本文档的讨论

    【讨论】:

    • 据我了解,查看您发送的线程,.compute() 需要在某个时候调用并且需要处理图像。从我的第一个代码中,读取图像后,唯一调用的函数是 hog.detectMultiScale(image, winStride=(4, 4), padding=(8, 8),scale=1.05)。我会说在detectMultiScale函数中使用了compute(),对吗?
    • 从另一个角度看,如果我使用其他线程的代码,它以 hist = hog.compute(image,winStride,padding,locations) 结尾。在此之后我需要什么代码来获取带有检测的图像,就像我的第一个代码一样?非常感谢
    猜你喜欢
    • 2016-09-29
    • 2016-05-03
    • 2014-07-05
    • 2013-03-10
    • 2016-05-01
    • 2012-08-01
    • 2014-01-29
    • 2014-05-15
    • 2017-01-14
    相关资源
    最近更新 更多