Ask Your Question

help with the hog detector

asked 2013-06-25 05:12:51 -0600

updated 2013-06-25 05:35:09 -0600

berak gravatar image


I am new to opencv and has recently been working on a small project where i need to deal with the HOG detector provided by the opencv. I have to extract the HOG detected window image out of the original image for which one possible approach i have tried is to create an image of Mat type and saving it with the exact width and height, x,y coordinates which are being calculated for the detected window. The approach works but the problem is it get crashes after while. Any help in this regards, some of the code chunk is given below. Thanks for any help in advance.

cv::Mat portionOfImage;
Rect r;
for (i=0; i<found_filtered.size(); i++) 
     r = found_filtered[i];
     r.x += cvRound(r.width*0.1);
     r.width = cvRound(r.width*0.8);
     r.y += cvRound(r.height*0.07);
     r.height = cvRound(r.height*0.8);
     rectangle(img,,, Scalar(0,255,0), 3);        
portionOfImage = img(r);
imshow("opencv", portionOfImage);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-06-25 06:54:05 -0600

Siegfried gravatar image


since you move and scale your rectangle, I guess that parts of your new rectangle are outside the image border. The reason could be the cvRound function. This function "Rounds floating-point number to the nearest integer". In some rare cases it could be that the scaling and moving values are rounded to the next higher int value and so result in an rectangle which lies (partly) outside the image border. You should check if the new rectangle lies within the image border before taking the ROI.

Why do you want to scale and move the detected rectangle and why do you want to do that for all detected rectangles with the same values?

edit flag offensive delete link more

Question Tools


Asked: 2013-06-25 05:12:51 -0600

Seen: 236 times

Last updated: Jun 25 '13