5

I am playing around with the SVM-HOG pipeline for pedestrian detection using OpenCV in python.

I have a lot of images of different sizes, some are small(e.g. 21×32), and some are larger(e.g. 127×264).

I first defined my HOG descriptor as hog = cv2.HOGDescriptor() When I compute the HOG features by calling h = hog.compute(image) I found that when the image is smaller than 64*128, the descriptor won't be able to compute the features, instead, it just terminates the program.

The original paper used 64*128 sized images, but I think it also stated it is ok to use images with the same aspect ratio which is 1:2 (correct me if I'm wrong).

My question is that is 64*128 the smallest size that a HOG descriptor can compute the feature on? because I tried to compute HOG features on images resized to 32*64, and it won't work.

Thanks. enter image description here

for entries in os.listdir(dir_path):
    if entries.endswith(".jpg"):
        img = cv2.imread(os.path.join(test_path, entries))
        rects, scores = hog.detectMultiScale(img, winStride=(4,4), padding=(8,8), scale=1.05)
        sc = [score[0] for score in scores]
        for i in range(len(rects)):
            r = rects[i]
            rects[i][2] = r[0]+r[2]
            rects[i][3] = r[1]+r[3]
        pick =[]
        pick = non_max_suppression(rects, probs = sc, overlapThresh = 0.3)
        for (x,y,w,h) in pick:
            cv2.rectangle(img, (x, y), (w, h), (0, 255, 0), 1)    
        cv2.imshow("A",img)

enter image description here

sensationti
  • 195
  • 1
  • 9
  • 1
    you can define the hog parameters, but it's quite complicated and I didnt take the time to identify the meaning of all the different parameters yet (which have to fit together in the end). But I believe, that 64x128 isn't the minimum. But once you chooe the parameters, the hog window size is fixed. To evaluate bigger or smaller windows, you can always resize the image, which is done during the detection step (which is a sliding windows detector approach). – Micka Aug 25 '20 at 10:07
  • 1
    If you are just interested in the detection step and want to detect objects smaller than 64x128, you can increase image size. Afair, I successfully detected persons of size about 32 pixels, but you will have to resize the input image. Otherwise, during detection stage, the minimum evaluated windows size is the one you've chosen during training, so for 64x128 person detection, persons must have a size of about 112 pixels height (because the window includes some background, as welll). – Micka Aug 25 '20 at 10:09
  • with the default parameters, the minimum size is `60 * 128`. – Ahmet Aug 25 '20 at 10:36
  • @Ahmet is it 60\*128 or 64\*128? – sensationti Aug 25 '20 at 13:49
  • @Micka In the detection process, how big do you usually resize the original input image to? I tried to upscale the original image to double and triple the original size, but it turns out it didn't do anything. – sensationti Aug 25 '20 at 13:51
  • Why do you hesitate? You can create the same result, `from skimage import data; image = cv2.resize(data.astronaut(), (60, 128)); hog.compute(image)` – Ahmet Aug 25 '20 at 13:52
  • @jay: how small are the persons in the original image expected to be? Can you share your detection code? – Micka Aug 25 '20 at 14:25
  • @Micka I've included an image in my question. There are two humans. I can detect the person on the right with no problem but have difficulties to detect the smaller one on the left. The image is of size 876\*701 and I believe that smaller pedestrian has a size less than 40\*70. The code I used for detection is also included in the question – sensationti Aug 25 '20 at 15:08
  • I'm not sure how well HoG person detection works with persons visible from the side. If you resize the image by a factor of sonewhere between 130/70 and 105/70 you should get the best possible result. – Micka Aug 25 '20 at 17:51
  • do you observe the same problem with small persons which are front-faced? – Micka Aug 25 '20 at 17:51
  • 1
    @Micka I am having issues with front-faced persons too when they are small. Do you think if I add more training data(front-faced and sided) this problem will be alleviated? I tried to rescale the image by 115/70, and it can pick up some objects which it previously missed, thank you for this. – sensationti Aug 25 '20 at 19:15

0 Answers0