1

I am trying to understand the code in python of pedestrian detection with HOG and SVM to accelerate it with an FPGA.

Below the code working fine copied from a website

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

Following the tutorial https://www.learnopencv.com/handwritten-digits-classification-an-opencv-c-python-tutorial/ I understand that the main function is hog.compute(im,descriptor) which compute the HOG features of an image, but where is this function on the first code? Is it inside of one of the functions?

Bonifacio2
  • 3,405
  • 6
  • 34
  • 54
josem
  • 11
  • 1

1 Answers1

0

While "explain this code" is a bit too broad for this site, the narrow question of "where is this function on the first code": it's not. It is, however, discussed in the tutorial you've linked.

At the beginning of the posted code, you instantiate the cv2.HOGDescriptor() object as hog. Once created, the object has all of the bound attributes and methods of the cv2.HOGDescriptor() class, including the .compute() method, once you invoke it.

There's some discussion in this question about the basic usage and here is a link to some of the basic documentation for the HOGDescriptor` class

G. Anderson
  • 5,815
  • 2
  • 14
  • 21
  • What I understand, and looking into the thread you sent, .compute() needs to be called at some point and need to works with an image. From my first code, after the image is read, the only function called is hog.detectMultiScale(image, winStride=(4, 4), padding=(8, 8),scale=1.05). I would say that compute() is used inside detectMultiScale function, is it right? – josem Jul 27 '19 at 09:09
  • From another point of view, if I use the code of the other thread, it ends with hist = hog.compute(image,winStride,padding,locations). What would be the code that I need after this to get the image with detections as in my first code? Many thanks – josem Jul 27 '19 at 09:17