OpenCV: How to use the HOGDescriptor :: detect method?

I was able to track moving objects in the video. http://ww1.sinaimg.cn/mw690/63a9e398jw1ecn39e3togj20jv0g1gnv.jpg

However, I want to decide whether the object is human or not. I tried HOGDescriptor in OpenCV. HOGDescriptor has two methods for detecting people: HOGDescriptor::detect and HOGDescriptor::detectMultiScale . OpenCV "sources \ samples \ cpp \ peopledetect.cpp" demonstrates how to use HOGDescriptor::detectMultiScale , which search the image at different scales and very slowly.

In my case, I was tracking objects in a rectangle. I think using HOGDescriptor::detect to detect inside a rectangle will be much faster. But the OpenCV document only has gpu::HOGDescriptor::detect (I still can’t figure out how to use it) and skipped HOGDescriptor::detect . I want to use HOGDescriptor::detect .

Can someone provide me some C ++ code snippet demonstrating the use of HOGDescriptor::detect ?

thanks.

+10
c ++ image-processing opencv
source share
2 answers

Since you already have a list of objects, you can call the HOGDescriptor::detect method for all objects and check the output array foundLocations . If it is not empty, the object is classified as a person. The only thing HOG works with is 64x128 windows by default, so you need to resize your objects:

 std::vector<cv::Rect> movingObjects = ...; cv::HOGDescriptor hog; hog.setSVMDetector(cv::HOGDescriptor::getDefaultPeopleDetector()); std::vector<cv::Point> foundLocations; for (size_t i = 0; i < movingObjects.size(); ++i) { cv::Mat roi = image(movingObjects[i]); cv::Mat window; cv::resize(roi, window, cv::Size(64, 128)); hog.detect(window, foundLocations); if (!foundLocations.empty()) { // movingObjects[i] is a person } } 
+11
source share
  • If you are not using OpenCV with CUDA , the call to gpu::HOGDescriptor::detect will be equal to the call to HOGDescriptor::detect . GPU is not called.

  • Also for code you can use

     GpuMat img; vector<Point> found_locations; gpu::HOGDescriptor::detect(img, found_locations); if(!found_locations.empty()) { // img contains/is a real person } 

Edit:

However, I want to decide whether the object is human or not.

I do not think you need this step. HOGDescriptor::detect itself is used to detect people, so you do not need to check them, because they must be people according to your setting. On the other hand, you can adjust your threshold to control its detected quality.

+1
source share

All Articles