title: How to detect a white paper on a white background with opencv
body: <p>I use the OpenCV library for detecting a white page from a book. Finding 4 corners on dark surfaces, but the white background finds only 3 corners. How can I find a way to find 4 corners or read a page on a white background?</p>
  
  <p>Or could you suggest another library that I can use outside of Opencv?</p>
  
  <p>I use the following code to find the contours.</p>
  
  <pre><code>    Mat grayImage = new Mat(imageMat.size(), CvType.CV_8UC4);
      Mat cannedImage = new Mat(imageMat.size(), CvType.CV_8UC4);
      Mat dilate = new Mat(imageMat.size(), CvType.CV_8UC4);
  
      Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_RGBA2GRAY);
      Imgproc.GaussianBlur(imageMat, imageMat, new Size(3, 3), 0);
      Imgproc.cvtColor(imageMat, grayImage, Imgproc.COLOR_BGR2GRAY);
      Imgproc.GaussianBlur(grayImage, grayImage, new Size(5.0, 5.0), 0.0);
      Imgproc.threshold(grayImage, grayImage, 20.0, 255.0, Imgproc.THRESH_TRIANGLE);
      Imgproc.Canny(grayImage, cannedImage, 75.0, 200.0);
      Imgproc.dilate(cannedImage, dilate, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10.0, 10.0)));
  </code></pre>
  
  <p>How can I change this code?</p>
  
  <p>I test my code with these photos.</p>
  
  <p><a href="https://i.stack.imgur.com/iwG9x.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iwG9x.jpg" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/JMnYT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JMnYT.jpg" alt="enter image description here"></a></p>
  
  <p>Thanks,
  Have a nice day.</p>