title: Detecting rectangle in image gives unwanted result (opencv, java)
body: <p>I have this picture that I have done thresholding on to convert it to binary image and black and white. See the picture below:</p>
  
  <p><img src="https://i.imgur.com/BiaFDrd.jpg" alt="Example 1"></p>
  
  <p>I want to extract each box with a letter, this was done by the following code:</p>
  
  <pre><code> List&lt;MatOfPoint&gt; contours = new ArrayList&lt;MatOfPoint&gt;();  
    Imgproc.findContours(destination3, contours, new Mat(), Imgproc.RETR_LIST,Imgproc.CHAIN_APPROX_SIMPLE);
  
           MatOfPoint2f approxCurve = new MatOfPoint2f();
           int x = 1;
           //For each contour found
           for (int i=0; i&lt;contours.size(); i++)
           {
               //Convert contours(i) from MatOfPoint to MatOfPoint2f
               MatOfPoint2f contour2f = new MatOfPoint2f( contours.get(i).toArray() );
               //Processing on mMOP2f1 which is in type MatOfPoint2f
               double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
               Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);
  
               //Convert back to MatOfPoint
               MatOfPoint points = new MatOfPoint( approxCurve.toArray() );
  
               // Get bounding rect of contour
               Rect rect = Imgproc.boundingRect(points);
               if(rect.height &gt; 50 &amp;&amp; rect.height &lt; 100) {
                // draw enclosing rectangle (all same color, but you could use variable i to make them unique)
               //Core.rectangle(destination, new Point(rect.x,rect.y), new Point(rect.x+rect.width,rect.y+rect.height), new Scalar(255, 0, 255), 3); 
               Rect roi = new Rect(rect.x, rect.y, rect.width, rect.height);
               Mat cropped = new Mat(destination3, roi);
               Highgui.imwrite("letter"+x+".jpg", cropped);
               x++;
               }
           }
  </code></pre>
  
  <p>But a letter extracted is totally black, it seems like it fills in the white letters as well as seen in the picture below. How do I fix this? What is wrong with my code?</p>
  
  <p><img src="https://i.imgur.com/UGCgKBK.jpg" alt="current output"></p>