title: Line detection using hough line Transform openCV android
body: <p>I'm trying to use hough transform to detect the four edges of a rectangle in my image. However, the result is not what I expected:</p>
  
  <p><img src="https://i.stack.imgur.com/qE79L.png" alt="Image"></p>
  
  <p>As you can see, it detected one line somewhere on the leaf instead of the four edges.</p>
  
  <pre><code>Mat binary_image = new Mat();
  
  Imgproc.threshold(gray_img, binary_image, 80, 255,   Imgproc.THRESH_BINARY_INV);
  
  //line detection
  Mat lines = new Mat();
  Imgproc.HoughLinesP( binary_image, lines, 1, Math.PI/180, 80, 5, 5 );
  
  for (int x = 0; x &lt; lines.cols(); x++)
      {
          double[] vec = lines.get(0, x);
          double x1 = vec[0],
                  y1 = vec[1],
                  x2 = vec[2],
                  y2 = vec[3];
          Point start = new Point(x1, y1);
          Point end = new Point(x2, y2);
  
          Core.line(mask, start, end, new Scalar(255,0,0), 1);
  
      }
  </code></pre>
  
  <p>Can anyone tell me what to do to make it right?</p>