Ask Your Question

nebgnahz's profile - activity

2017-09-29 11:42:34 -0500 received badge  Teacher (source)
2017-09-29 11:42:30 -0500 received badge  Student (source)
2017-05-31 08:02:57 -0500 received badge  Necromancer (source)
2017-05-31 08:02:57 -0500 received badge  Self-Learner (source)
2017-05-25 10:59:21 -0500 received badge  Enthusiast
2017-05-24 14:29:36 -0500 answered a question Unable to get HOG confidence using GPU implementation (OpenCV 3)

Answering my own question here: setting group_threshold as 0 would work. Example as below:

// g++ mwp.cpp -o hog --std=c++11 `pkg-config --cflags --libs opencv`
#include "opencv2/core/core.hpp"
#include "opencv2/cudaobjdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect.hpp"
#include <iostream>

using namespace cv;

static void printUsage() { std::cout << "Usage: hog <image>\n"; }

int main(int argc, char **argv) {
  if (argc < 2) {
    printUsage();
    return 0;
  }

  //
  // Load Image
  //
  Mat frame = imread(argv[1], CV_LOAD_IMAGE_COLOR);
  Mat img;
  cvtColor(frame, img, COLOR_BGR2BGRA);
  cuda::GpuMat gpu_img;
  gpu_img.upload(img);

  //
  // Create Hog
  //
  Size win_size(64, 128);
  Size block_size(16, 16);
  Size block_stride(8, 8);
  Size cell_size(8, 8);
  int nbins = 9;
  cv::Ptr<cv::cuda::HOG> hog = cv::cuda::HOG::create(
      win_size, block_size, block_stride, cell_size, nbins);
  Mat detector = hog->getDefaultPeopleDetector();
  hog->setSVMDetector(detector);

  //
  // Do detection
  //
  hog->setGroupThreshold(0); // Important
  std::vector<Rect> found;
  std::vector<double> confidences;
  hog->detectMultiScale(gpu_img, found, &confidences);

  //
  // Show result
  //
  assert(found.size() == confidences.size());
  for (int i = 0; i < found.size(); i++) {
    Rect r = found[i];
    printf("(%d, %d, %d, %d), %3.2f\n", r.x, r.y, r.width, r.height,
           confidences[i]);
  }

  return 0;
}
2017-05-24 14:28:25 -0500 answered a question Retrieve GPU HOG detector scores

For GPU version of the HOG, pass in the third parameter confidence as &vector<double> would work.

Note: you need to configure group_threshold 0 to retrieve the detector scores. See the example code below.

Documentation link: http://docs.opencv.org/3.2.0/de/da6/c...


Below is a minimal working example in case you are interested:

// g++ mwp.cpp -o hog --std=c++11 `pkg-config --cflags --libs opencv`
#include "opencv2/core/core.hpp"
#include "opencv2/cudaobjdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/objdetect.hpp"
#include <iostream>

using namespace cv;

static void printUsage() { std::cout << "Usage: hog <image>\n"; }

int main(int argc, char **argv) {
  if (argc < 2) {
    printUsage();
    return 0;
  }

  //
  // Load Image
  //
  Mat frame = imread(argv[1], CV_LOAD_IMAGE_COLOR);
  Mat img;
  cvtColor(frame, img, COLOR_BGR2BGRA);
  cuda::GpuMat gpu_img;
  gpu_img.upload(img);

  //
  // Create Hog
  //
  Size win_size(64, 128);
  Size block_size(16, 16);
  Size block_stride(8, 8);
  Size cell_size(8, 8);
  int nbins = 9;
  cv::Ptr<cv::cuda::HOG> hog = cv::cuda::HOG::create(
      win_size, block_size, block_stride, cell_size, nbins);
  Mat detector = hog->getDefaultPeopleDetector();
  hog->setSVMDetector(detector);

  //
  // Do detection
  //
  hog->setGroupThreshold(0); // Important
  std::vector<Rect> found;
  std::vector<double> confidences;
  hog->detectMultiScale(gpu_img, found, &confidences);

  //
  // Show result
  //
  assert(found.size() == confidences.size());
  for (int i = 0; i < found.size(); i++) {
    Rect r = found[i];
    printf("(%d, %d, %d, %d), %3.2f\n", r.x, r.y, r.width, r.height,
           confidences[i]);
  }

  return 0;
}
2017-05-23 19:43:50 -0500 commented question Retrieve GPU HOG detector scores

I've asked a similar question before: http://answers.opencv.org/question/11...

AFAIK, this is still not resolved.

Edit: Looking at my own question again, actually you can retrieve the confidence (detector scores) by setting group_threshold 0. It's embarrassing that I missed it.

2016-11-09 15:12:55 -0500 asked a question Unable to get HOG confidence using GPU implementation (OpenCV 3)

I am confused at how to get the confidence level when using HOG GPU implementation in OpenCV 3.

According to OpenCV 3.1 cv::cuda::HOG::detectMultiScale Documentation, code replicated below:

virtual void
cv::cuda::HOG::detectMultiScale(InputArray img,
                            std::vector<Rect>& found_locations,
                            std::vector<double>* confidences = NULL)

You can pass a pointer to the third argument confidences. I've tried it but got OpenCV Error: Assertion failed (confidence == NULL || group_threshold_ == 0).

Looking at the actual implementation (hog.cpp:385), it is checking the confidences and only allowing a NULL parameter (code replicated below):

CV_Assert( confidences == NULL || group_threshold_ == 0 );

The same question has also been asked on StackOverflow and hasn't been addressed. Please advice.