std::length_error at HOGDetector::compute() [closed]

asked 2017-11-30 01:02:28 -0600

slu gravatar image

updated 2017-11-30 19:21:53 -0600

Hi, I am trying to create my own HOG detector (using a svm). The tutorial with INRIA-dataset worked fine. Now I want to use pictures of size 80x80 as training set (one picture is included at the end of this post as reference).

However, when calling this line with the 80x80-grayscale image:

hog.compute(image, detections, Size(8,8), Size(0,0));

I get the following error:

terminate called after throwing an instance of 'std::length_error' what(): vector::_M_fill_insert

I am using OpenCV 3.1. Does anybody know how I can solve this problem?

Edit: The colour image is read, then transformed to grayscale and then the compute() fails:

cv::Mat img = cv::imread("path/to/picture.png");
cv::HOGDescriptor hog;
cv::Rect r = cv::Rect( 0, 0, 80, 80 );
cv::Mat gray;
std::vector< float > descriptors;
r.x += ( img.cols - r.width ) / 2;
r.y += ( img.rows - r.height ) / 2;
cv::cvtColor(img(r), gray, cv::COLOR_BGR2GRAY);
std::clog << "[DEB] img-size: " << gray.size().width << "x" << gray.size().height << std::endl; // outputs 80x80, as expected
hog.compute(gray, descriptors, cv::Size(8, 8), cv::Size(0, 0)); // this fails and gives me the mentioned error

C:\fakepath\36.png

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2017-11-30 21:52:18.523195

Comments

could you share some of your positive images

sturkmen gravatar imagesturkmen ( 2017-11-30 10:24:59 -0600 )edit

I edited my post

slu gravatar imageslu ( 2017-11-30 19:37:23 -0600 )edit

hog.winSize = Size(80,80);

(default is128x64, for the person descriptor)

berak gravatar imageberak ( 2017-11-30 21:23:16 -0600 )edit

Thanks, I missed that parameter. It works now.

slu gravatar imageslu ( 2017-11-30 21:38:45 -0600 )edit