【问题标题】:remove bounding boxes inside bounding boxes for number recognition删除边界框内的边界框以进行数字识别
【发布时间】:2013-12-16 11:50:47
【问题描述】:

我正在尝试数字识别。但是在找到轮廓之后。我在主边界框内得到数字 0、6、8 的边界框......如图所示。请帮助我完成图像处理的初始步骤。 我曾尝试使用组矩形,但它们不起作用。请检查下面的代码。谢谢。

图片:http://tinypic.com/r/1twx05/5

int main()
{
    Mat inimage, gray;
    inimage = imread("sample.jpg");
    cvtColor(inimage, gray, COLOR_BGR2GRAY);
    GaussianBlur(gray, gray, Size(5,5), 0);
    adaptiveThreshold(gray, gray, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY_INV, 11, 0);
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    findContours( gray, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

    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]) );
    }
    //groupRectangles(boundRect, 1, 0.2);
    Scalar color = Scalar(0,0,255);
    for( int i = 0; i< contours.size(); i++ )
    {
        //drawContours( inimage, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
        rectangle( inimage, boundRect[i].tl(), boundRect[i].br(), color, 1, 8, 0 );
    }
    namedWindow( "Contours", CV_WINDOW_AUTOSIZE );
    imshow( "Contours", inimage );
    waitKey(0);
    return 0;
}

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    尝试使用标志:CV_RETR_EXTERNAL 而不是 CV_RETR_TREE

    正如docs 中所述,它告诉我们只采用外部轮廓。

    或按照树层次结构删除嵌套轮廓(阅读文档以了解操作方法)

    【讨论】:

      猜你喜欢
      • 2020-06-17
      • 2020-05-26
      • 2012-03-23
      • 2017-09-13
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多