Ask Your Question
1

Three questions about HOG detector

asked 2018-02-01 10:01:56 -0600

yamciayamcia gravatar image

updated 2018-02-04 02:37:18 -0600

have following code and I have some questions about it: 1. What is detection window size for HOG detector and how does it change within program run? 2. What classificators are being used in OpenCV HOG detector? 3. Confusion matrix for HOG in OpenCV?

# detect people in the image and start counting time
start = datetime.datetime.now()
(rects, weights) = hog.detectMultiScale(image, winStride=winStride,
    padding=padding, scale=scale, useMeanshiftGrouping=meanShift)
#end time counting
print("[INFO] detection took: {}s".format(
    (datetime.datetime.now() - start).total_seconds()))

# draw the original bounding boxes
for (x, y, w, h) in rects:
    cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)

# show the output image
cv2.imshow("Detections", image)
cv2.waitKey(0)
print ("dws: ", dws)
edit retag flag offensive close merge delete

Comments

instead of HOGDescriptor i suggest you to use mobilenet_ssd_python.py

sturkmen gravatar imagesturkmen ( 2018-02-01 13:48:21 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-02-01 11:46:56 -0600

updated 2018-02-02 20:42:36 -0600

I would recommend you read this, this and this to truly understand how the HOG descriptor works.

EDIT I:

Sorry I did a poor job at clearly explaining a few things to you so let us take a step back.

  1. HOG: The main idea of the algorithm is to simply create a feature descriptor of any given image regardless of it belonging to a class or not. How? It uses image gradients and direction. Given an image, it tries to find the dominant direction of an edge.

  2. The algorithm itself is tied to no particular machine learning technique i.e. you can create your own classifier or object detector from these computed HOGs.

In both methods, you need training data regardless.

Classifier Your dataset consists of different classes, compute the HOGs of each of them then use your choice of classifiers to categorize them. So given a new image, the model will try finding its HOG then tell you which label it closely associates with. This is were the confusion matrix comes into play because you have multiple classes.

Object Detector Generally folks train the HOGs using SVM (a classifier) - which I believe is the same case for OpenCV as well. Then by using detectMultiScale, it will apply the sliding window technique to grab a portion of the image, pass it on to the trained model. The model then spits out a probability. If this value passes a set threshold then it keeps the bounding box associated with this area. At the end it'd apply a non-max suppression.

For the case of OpenCV, HOGs are used as object detectors. Their classification model was trained to recognize just a single class (I stand to be corrected) which is why there is no confusion matrix.

Now, you can go ahead and train your own multi-class classifier of HOGs should you choose because of 2.

I highly recommend you read this paper. Along with it, a tutorial and forum will do you good too!

Again, I am really sorry for not being extremely precise in my prior responses earlier. Hope this clarifies things.

Cheers :)

edit flag offensive delete link more

Comments

Thanks. I managed to find out for the first question, but two still remaining and I couldn't find any info about it...

yamciayamcia gravatar imageyamciayamcia ( 2018-02-01 14:01:13 -0600 )edit

You clearly have not understood it then. HOG is not a classifier. It is an object/feature detector. Classification:Given an image, tell me what class it belongs to e.g. Apple, bus, forest etc.Detection:For a given image, find out if there exist a patch(or coordinates) where an object exists. To add on to this, you train HOG on a single object then save the features into an xml file (for the case of OpenCV). Plus, confusion matrices are made for classifiers.

eshirima gravatar imageeshirima ( 2018-02-01 14:12:35 -0600 )edit

I got you, but to use detector, we also need classificator, right? So I'm asking, when I run hog.detectmultiscale, which classifiers does it use? And for those classifiers, how are confusion matrices?

yamciayamcia gravatar imageyamciayamcia ( 2018-02-02 05:10:56 -0600 )edit

No. To run a detector, you do not need a classifier! HOG just counts the occurrences of gradient orientation in localized portions of an image. The detectMultiScale method is the one that tells HOG how to find these occurrences. Feature detection algorithms normally do not run classification. Why classify something on an image first then detect its location? Feature detectors learn/memorize features/attributes about an object then straight up start finding their locations in a given image/frame.

eshirima gravatar imageeshirima ( 2018-02-02 12:22:15 -0600 )edit

Thanks. It's almost clear now, but how counting occurrences of gradients leads to telling program that it's a person?

yamciayamcia gravatar imageyamciayamcia ( 2018-02-02 13:06:54 -0600 )edit

Check my edit. Please don't forget to upvote and accept as answer if it helped u!

eshirima gravatar imageeshirima ( 2018-02-02 20:43:04 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-01 10:01:56 -0600

Seen: 848 times

Last updated: Feb 02 '18