python - 行人检测与 HOG 描述符和 SVM 理解 Python 代码

标签 python opencv detection

我正在尝试使用 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 特征,但是第一个代码上的这个函数在哪里?它在其中一个功能内吗?

最佳答案

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

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

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

关于python - 行人检测与 HOG 描述符和 SVM 理解 Python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57191874/

相关文章:

c# - OpenCV是否有紧凑的C#端口?

neural-network - 试图在图像中找到对象坐标 (x,y),我的神经网络似乎在没有学习的情况下优化了错误

button - Godot:检测按下的鼠标是否在按钮上方

python - 查找多幅图像之间的差异图像

python - Sage/Python 中 fork 后出现 SIGILL

python - 基维,导入错误 : cannot import name App

opencv - 单个图像中的背景检测

python - 如何在 Python 中执行包含 Python 代码的字符串?

python - 将24x24图像复制到28x28的零数组

tensorflow - 使用经过训练的对象检测 API 模型和 TF 2 进行批量预测