Ask Your Question

Revision history [back]

cv::countNonZero is your medicine, you can change your code like below

    approxPolyDP( Mat(contours[i]), contours_poly[i], 3,true );
    boundRect[i] = boundingRect( Mat(contours_poly[i]) );

    Rect upperRect = boundRect[i];
    upperRect.y -= 5;  // you can change this value if needed on other images
    int zeropixels = countNonZero( bw( upperRect ) );
    if( zeropixels < 10) // // you can change this value if needed on other images
    rectangle( rsz, boundRect[i].tl(), boundRect[i].br(),Scalar(0, 255, 0), 1, 8, 0 );

    rois.push_back(rsz(boundRect[i]).clone());

cv::countNonZero is your medicine, you can change your code like below

    approxPolyDP( Mat(contours[i]), contours_poly[i], 3,true );
    boundRect[i] = boundingRect( Mat(contours_poly[i]) );

    Rect upperRect = boundRect[i];
    upperRect.y -= 5;  // you can change this value if needed on other images
    int zeropixels nonzeropixels = countNonZero( bw( upperRect ) );
    if( zeropixels nonzeropixels < 10) // // you can change this value if needed on other images
    rectangle( rsz, boundRect[i].tl(), boundRect[i].br(),Scalar(0, 255, 0), 1, 8, 0 );

    rois.push_back(rsz(boundRect[i]).clone());