title: Remove duplicate lines after HoughLinesP on Android + OpenCV
body: <p>I'm trying to detect a white rectangle in a black image. I've used HoughLinesP after Canny, and the detection is accurate.
  The probleme is that, some lines are very similar and define the same edge almost. So in the matrix that HgouhLinesP returns, instead of having 4 lines I have more than that. Is it possible to change a parameter in HoughLinesP to make it generate only 4 lines ?</p>
  
  <p>I tried to implement a method where I compare the equations of all the generated lines but similar lines seem to have very different equations and the result is wrong. So basically I create a 4x4 matrix and put the first line in it. Then I compare the following lines, when one of them is different I put it in the 4x4 matrix etc. I compare the rest of the lines with the ones already in the 4x4 matrix. Could anyone please help ? </p>
  
  <pre><code> Imgproc.Canny(diff, diff2, 100, 100, 3);
  
          Mat lines = new Mat();
          int threshold = 80;
          int minLineSize = 150;
          int lineGap = 80;
          Imgproc.HoughLinesP(diff2, lines, 1, Math.PI / 180, threshold, minLineSize, lineGap);
          double[][] linesFinal = new double[4][4];
          linesFinal[0] = lines.get(0, 0);
  
          double x01 = linesFinal[0][0],
                  y01 = linesFinal[0][1],
                  x02 = linesFinal[0][2],
                  y02 = linesFinal[0][3];
          double a = y02 - y01 / x02 - x01;
          double b = y01 - a * x01;
          Log.i(TAG, "aaaaaaaaaaaaaaaaaaaaa:    " + String.valueOf(a) + "bbbbbbbbbb     " + String.valueOf(b));
          Point start0 = new Point(x01, y01);
          Point end0 = new Point(x02, y02);
  
          Core.circle(finaleuh, end0, 10, new Scalar(255, 0, 0, 255), 10);
          Core.circle(finaleuh, start0, 10, new Scalar(255, 0, 0, 255), 10);
  
          int index = 1;
          int x = 1;
  
  
          while (index &lt; 4 &amp;&amp; x &lt; lines.cols()) {
  
              // Log.i(TAG,"xxxxxxxxxxxxxxxx:    "+ String.valueOf(x)+"   indeeeeeex      "+ String.valueOf(index));
              double[] vec = lines.get(0, x);
              double Xi1 = vec[0],
                      Yi1 = vec[1],
                      Xi2 = vec[2],
                      Yi2 = vec[3];
              double Ai = (Yi2 - Yi1) / (Xi2 - Xi1);
              double Bi = Yi1 - Ai * Xi1;
              //  Log.i(TAG,"aaaaaaaaaaaaaaaaaaaaa:    "+ String.valueOf(Ai)+ "bbbbbbbbbb     " + String.valueOf(Bi));
  
              int counter = 0;
              for (int i = 0; i &lt; index; i++)
  
              {
  
                  double xF = linesFinal[i][0],
                          yF = linesFinal[i][1],
                          xFF = linesFinal[i][2],
                          yFF = linesFinal[i][3];
  
  
                  double aF = yFF - yF / xFF - xF;
                  double bF = yF - aF * xF;
                  Log.i(TAG, "aaaaaaaaaaaaaaaaaaaaa:    " + String.valueOf(aF) + "bbbbbbbbbb     " + String.valueOf(bF));
  
                  double diffFA = Math.abs(aF - Ai);
                  double diffFB = Math.abs(bF - Bi);
  
                  if (diffFA &gt; 250 &amp;&amp; diffFB &gt; 300) {
                      counter = counter + 1;
  
  
                  }
  
              }
  
  
              if (counter == index)
  
  
              {
                  linesFinal[index] = vec;
                  double xF = linesFinal[index][0],
                          yF = linesFinal[index][1],
                          xFF = linesFinal[index][2],
                          yFF = linesFinal[index][3];
  
                  Point startF = new Point(xF, yF);
                  Point endF = new Point(xFF, yFF);
                  Core.circle(finaleuh, endF, 10, new Scalar(255, 0, 0, 255), 10);
                  Core.circle(finaleuh, startF, 10, new Scalar(255, 0, 0, 255), 10);
                  index++;
                  x++;
              } else {
                  x++;
              }
  
  
          }
  </code></pre>