Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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?

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;
    }
}

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;
    }
}