0
$\begingroup$

I would like to implement a HOG descriptor in C++. I found an implementation of this code here.

An extract of the code follows:

//extract HOG features from a group of key points
void HOGExtractor::extract(ublas::matrix<float> &dscr_list, const 
ublas::matrix<int> &bbox_list, const IntegralHistogram &inthist)
{
    unsigned int length = _param.xgrid * _param.ygrid * inthist.dirnum();
        if (dscr_list.size1() != bbox_list.size1() || dscr_list.size2() != 
length)
    throw std::runtime_error( boost::str(
                boost::format("Allocate proper memory for dscr_list [%1% %2%] != [%3% %4%]") % dscr_list.size1() % dscr_list.size2() % dscr_list.size2() % length) );

ublas::matrix<float>::iterator1 idscr_list;
ublas::matrix<int>::const_iterator1 ibbox_list;
ublas::matrix<int>::const_iterator1 ibbox_list_end(bbox_list.end1());
ublas::vector<int> bbox_grids( _param.xgrid * _param.ygrid * 4 );
for ( ibbox_list = bbox_list.begin1(), idscr_list = dscr_list.begin1(); ibbox_list != ibbox_list_end; ++ibbox_list, ++idscr_list)
{
    ublas::matrix<int>::const_iterator2 ibbox = ibbox_list.begin();
    float x0 = std::max( *ibbox++, 0 );
    float y0 = std::max( *ibbox++, 0 );
    float x1 = std::min( *ibbox++, inthist.width() - 1 );
    float y1 = std::min( *ibbox++, inthist.height() - 1 );
    if ( x1 - x0 < _param.xgrid || y1 - y0 < _param.ygrid )
        throw std::runtime_error( boost::str(boost::format("Grid number should be less than bbox width/height [%1% %2% %3% %4%]/[%5% %6%]") % x0 % y0 % x1 % y1 % _param.xgrid % _param.ygrid) );

    float xstep = (x1 - x0 + 1) / _param.xgrid;
    float ystep = (y1 - y0 + 1) / _param.ygrid;
    for (int i = 0; i < _param.xgrid; ++i)
        for (int j = 0; j < _param.ygrid; ++j)
        {
            bbox_grids( (i * _param.ygrid + j)*4 + 0) = static_cast<int>(x0 + xstep*i);    //x0 
            bbox_grids( (i * _param.ygrid + j)*4 + 1) = static_cast<int>(y0 + ystep*j);    //y0 
            bbox_grids( (i * _param.ygrid + j)*4 + 2) = static_cast<int>(x0 + xstep*(i + 1) - 1);    //x1 
            bbox_grids( (i * _param.ygrid + j)*4 + 3) = static_cast<int>(y0 + ystep*(j + 1) - 1);    //y1 
        }
    inthist.get_hist< ublas::matrix<float>::iterator2, ublas::vector<int>::const_iterator>( idscr_list.begin(), bbox_grids.begin(), bbox_grids.end(), _param.normalize);
}

}

The "key points" it is referred to here are (if I'm not mistaken) the coordinates of the box containing an object we want to extract the features.

However, I am wondering how I can get these coordinates in a image? (Given an image and an object I want to extract the features, how can I know the values of x0, x1, y0, y1?)

$\endgroup$
  • $\begingroup$ So your question is, how to automatically find the position of an object in an image? You can use an object detector for this. Like Viola-Jones or Felzenszwalbs Deformable Part Models. $\endgroup$ – sietschie Sep 13 '13 at 22:45
  • $\begingroup$ @sietschie Basically yes. Thank you for your answer! $\endgroup$ – bigTree Sep 15 '13 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.