title: Get a single line representation for multiple close by lines clustered together in opencv
body: <p>I detected lines in an image and drew them in a separate image file in OpenCv C++ using HoughLinesP method. Following is a part of that resulting image. There are actually hundreds of small and thin lines which form a big single line. </p>
  
  <p><img src="https://i.stack.imgur.com/7m5C0.jpg" alt="enter image description here"> </p>
  
  <p>But I want single few lines that represent all those number of lines. Closer lines should be merged together to form a single line. For example above set of lines should be represented by just 3 separate lines as below.</p>
  
  <p><img src="https://i.stack.imgur.com/6taMY.png" alt="enter image description here"></p>
  
  <p>The expected output is as above. How to accomplish this task.</p>
  
  <hr>
  
  <hr>
  
  <p>Up to now progress result from akarsakov's answer.</p>
  
  <hr>
  
  <p>(separate classes of lines resulted are drawn in different colors). Note that this result is the original complete image I am working on, but not the sample section I had used in the question</p>
  
  <p><img src="https://i.stack.imgur.com/eYuAS.jpg" alt="enter image description here"></p>