How to resize boundingRect to fix size?
Hi guys, I wanna resize boundingRect to fix size and have the object inside the center of rect but I don't get some help after googling it. And try some several ways but didn't work, like:
cv::Rect r0 = cv::boundingRect(contours[cnum]);
r0.x = r0.x - 5;
r0.y = r0.y - 5;
r0.height = 60
r0.width = 100;
cv::rectangle(blob, r0, cv::Scalar(255, 0, 0));
human.detectMultiScale(frame(r0),rects);
Here we go my full code, look at the last line:
cv::namedWindow("Frame");
cv::namedWindow("Background Model");
cv::namedWindow("Blob");
cv::VideoCapture cap("skenario c/3.avi");
cv::BackgroundSubtractorMOG2 bgs;
bgs.nmixtures = 3;
bgs.history = 1000;
bgs.bShadowDetection = true;
bgs.nShadowDetection = 0;
bgs.fTau = 0.25;
std::vector<std::vector<cv::Point>> contours;
cv::CascadeClassifier human;
assert(human.load("hogcascade_pedestrians.xml"));
for(;;){
cap >> frame;
cv::GaussianBlur(frame,blurred,cv::Size(3,3),0,0,cv::BORDER_DEFAULT);
bgs.operator()(blurred,fg,0);
bgs.getBackgroundImage(bgmodel);
cv::erode(fg,fg,cv::Mat(),cv::Point(-1,-1),1);
cv::dilate(fg,fg,cv::Mat(),cv::Point(-1,-1),3);
cv::threshold(fg,threshfg,70.0f,255,CV_THRESH_BINARY);
cv::findContours(threshfg,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE);
cv::cvtColor(threshfg,blob,CV_GRAY2RGB);
cv::drawContours(blob,contours,-1,cv::Scalar(255,255,255),CV_FILLED,8);
blob.copyTo(blobarray[(int)cap.get(CV_CAP_PROP_POS_FRAMES)]);
int cmin = 20;
int cmax = 1000;
bool FOD1 = true;
bool FOD2 = true;
std::vector<cv::Rect> rects;
for(int cnum = 0; cnum < contours.size(); cnum++){
if(contours[cnum].size() > cmin && contours[cnum].size() < cmax){
//I WANNA RESIZE HERE:
human.detectMultiScale(frame(cv::boundingRect(contours[cnum])),rects);
I'll appreciate any help here, thanks. :)