Bounding box For characters

asked 2015-11-11 19:34:27 -0500

fredreload gravatar image

Hi, I am currently using this program provided by OpenCV to get the bounding box for my characters. The problem is the largest bounding box rectangle surrounds the entire image so when I do CV_RETR_EXTERNAL only the largest rectangle shows. I want to know how to remove the largest bounding box so I can get a bounding box for each character. I also want the bounding box to be in order in x axis from left to right so I can analyze them. I know

for( int i = 0; i< contours.size(); i++ )
Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
rectangle( drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0 );

Is supposed to loop through all the boundRect but most of them is showing -1 in my case so I am not sure how to group them by x axis. Below is an image of my output and I want to remove the largest blue bounding box rectangle.

image description

edit retag flag offensive close merge delete


use THRESH_BINARY_INV instead of THRESH_BINARY as shown below

  /// Detect edges using Threshold
  threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY_INV );
sturkmen gravatar imagesturkmen ( 2015-11-12 03:00:55 -0500 )edit