Resizing a bounding box opencv c++?
So, i am working on a character recognition program. This is what i have tried so far. 1. Loaded an image of character A written in various styles. 2. Pre processed the image (converting to grayscale,adaptivethreshold,morphology). 3. Find contours and draw them on the original image. 4. Draw bounding Rectangle on the detected contour.
Now, here is the thing. Since the characters are small, so the boundingrectangle is also small. What my objective is to resize the boundingrectangle to 60*60 and then draw it on each contours detected. Such that when i save the detected contours as images, it can be visible. How do i do that?
vector<vector<Point> > contours_poly( contours.size() );
vector<Rect> boundRect( contours.size() );
for( int i = 0; i < contours.size(); i++ )
{
approxPolyDP( Mat(contours[i]), contours_poly[i], 3, true );
boundRect[i] = boundingRect( Mat(contours_poly[i]) );
cout<<boundRect[i].height<<"\t"<<boundRect[i].width<<"\t"<<boundRect[i].area()<<endl;
Mat roi( result, boundRect[i]);
resize(roi,roi,Size(100,100),CV_INTER_CUBIC);
contour_rois.push_back(roi);
}
for (int i = 0; i < contours.size(); i = hierarchy[i][0]) {
// Rect r = boundingRect(contours[i]);
double area0 = contourArea(contours[i]);
if (area0 < 120) {
//cout<<area0<<endl;
drawContours(src, contours, i, Scalar(255,0,0), CV_FILLED, 8, hierarchy);
rectangle(src, boundRect[i].tl(), boundRect[i].br(), Scalar(0,0,255), 2, 8, 0 );
continue;
}
}
I'm not quite sure what it is you want to do. I thought you meant to take the area inside the box and resize it to 60x60, but you're already doing that with contour_rois.
Can you make a sample image manually, showing what you have now and what you want?