0

After reading some stack overflow posts on image processing, I made a program to detect and a paper in an image and remove the background. But currently the program only detects the contours. How can I crop out the biggest contour? Eventually, I will use this region and use tesseract for character recognition. I am stuck at the preprocessing part.

the image I used:

enter image description here

And this is what I got after running my script:

enter image description here

How can I approximate the big blue contour and crop it out for things like character detection?

Here is the code I used:

static void on_canny( int,void* ){
blur( dst, detected_edges, Size(3,3) );
Canny(detected_edges, detected_edges, cannyThreshold, cannyThreshold*r, kernel_size);
findContours(detected_edges, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
Mat drawing = Mat::zeros( detected_edges.size(), CV_8UC3 );
for(int i=0;i<contours.size();i++)
{
    Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
    drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
}
imshow("Contour",drawing);
imshow("Canny", detected_edges);
}
Titan97
  • 67
  • 1
  • 6
  • 1
    google contour size opencv, find http://docs.opencv.org/trunk/dd/d49/tutorial_py_contour_features.html as first hit. read, apply... – Piglet Jun 16 '17 at 08:39
  • @Piglet I made a for loop and compared all the contour areas. Its not giving me the correct result – Titan97 Jun 16 '17 at 08:56
  • [This answer](https://stackoverflow.com/a/44090417/5799975) and [that answer](https://stackoverflow.com/a/44131530/5799975) could help you get started in finding the largest contours. – Elouarn Laine Jun 16 '17 at 09:06
  • and why don't you provide this code as well so we can tell you what is wrong with it? – Piglet Jun 16 '17 at 09:48

0 Answers0