Note that there are some explanatory texts on larger screens.

plurals
  1. POHough transform returns the collinear and semi collinear points
    primarykey
    data
    text
    <p>I have points in an image. I need to detect the most collinear points. The fastest method is to use Hough transform, but I have to modify the opencv method. Actually I need that the semi collinear points to be returned with detected line, for this reason I modified the polar line struct. A tolerance threshold is also needed to detect nearly detected points as shown in the image. Can someone help in how to tune this threshold? I need at least four semi collinear points to detect the line to which they belong. <img src="https://i.stack.imgur.com/Xatig.png" alt="ex 1"> <img src="https://i.stack.imgur.com/eWSto.png" alt="ex 2"> <img src="https://i.stack.imgur.com/cb9wq.png" alt="ex 3"></p> <ol> <li><p>The points of first image were detected by 6 overlapped lines</p></li> <li><p>the point of middle images were detected by nothing</p></li> <li>the third's points were detected by three lines</li> </ol> <p><img src="https://i.stack.imgur.com/YWMTM.jpg" alt="`![enter image description here"> <img src="https://i.stack.imgur.com/b9vJD.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/0KTbm.jpg" alt="enter image description here"></p> <p>Which is the best way to get rid from the overlapped liens?? Or how to tune the tolerance threshold to detect the semi collinear points by only one line?</p> <p>the is my own function call:</p> <pre><code>vector&lt;CvLinePolar2&gt; lines; CvMat c_image = source1; // loaded image HoughLinesStandard(&amp;c_image,1,CV_PI/180,4,&amp;lines,INT_MAX); </code></pre> <hr> <pre><code> typedef struct CvLinePolar2 { float rho; float angle; vector&lt;CvPoint&gt; points; }; void HoughLinesStandard( const CvMat* img, float rho, float theta, int threshold, vector&lt;CvLinePolar2&gt; *lines, int linesMax= INT_MAX ) { cv::AutoBuffer&lt;int&gt; _accum, _sort_buf; cv::AutoBuffer&lt;float&gt; _tabSin, _tabCos; const uchar* image; int step, width, height; int numangle, numrho; int total = 0; int i, j; float irho = 1 / rho; double scale; vector&lt;vector&lt;CvPoint&gt;&gt; lpoints; CV_Assert( CV_IS_MAT(img) &amp;&amp; CV_MAT_TYPE(img-&gt;type) == CV_8UC1 ); image = img-&gt;data.ptr; step = img-&gt;step; width = img-&gt;cols; height = img-&gt;rows; numangle = cvRound(CV_PI / theta); numrho = cvRound(((width + height) * 2 + 1) / rho); _accum.allocate((numangle+2) * (numrho+2)); _sort_buf.allocate(numangle * numrho); _tabSin.allocate(numangle); _tabCos.allocate(numangle); int *accum = _accum, *sort_buf = _sort_buf; float *tabSin = _tabSin, *tabCos = _tabCos; memset( accum, 0, sizeof(accum[0]) * (numangle+2) * (numrho+2) ); //memset( lpoints, 0, sizeof(lpoints) ); lpoints.resize(sizeof(accum[0]) * (numangle+2) * (numrho+2)); float ang = 0; for(int n = 0; n &lt; numangle; ang += theta, n++ ) { tabSin[n] = (float)(sin(ang) * irho); tabCos[n] = (float)(cos(ang) * irho); } // stage 1. fill accumulator for( i = 0; i &lt; height; i++ ) for( j = 0; j &lt; width; j++ ) { if( image[i * step + j] != 0 ) { CvPoint pt; pt.x = j; pt.y = i; for(int n = 0; n &lt; numangle; n++ ) { int r = cvRound( j * tabCos[n] + i * tabSin[n] ); r += (numrho - 1) / 2; int ind = (n+1) * (numrho+2) + r+1; int s = accum[ind]; accum[ind]++; lpoints[ind].push_back(pt); } } } // stage 2. find local maximums for(int r = 0; r &lt; numrho; r++ ) for(int n = 0; n &lt; numangle; n++ ) { int base = (n+1) * (numrho+2) + r+1; if( accum[base] &gt; threshold &amp;&amp; accum[base] &gt; accum[base - 1] &amp;&amp; accum[base] &gt;= accum[base + 1] &amp;&amp; accum[base] &gt; accum[base - numrho - 2] &amp;&amp; accum[base] &gt;= accum[base + numrho + 2] ) sort_buf[total++] = base; } // stage 3. sort the detected lines by accumulator value icvHoughSortDescent32s( sort_buf, total, accum ); // stage 4. store the first min(total,linesMax) lines to the output buffer linesMax = MIN(linesMax, total); scale = 1./(numrho+2); for( i = 0; i &lt; linesMax; i++ ) { CvLinePolar2 line; int idx = sort_buf[i]; int n = cvFloor(idx*scale) - 1; int r = idx - (n+1)*(numrho+2) - 1; line.rho = (r - (numrho - 1)*0.5f) * rho; line.angle = n * theta; line.points = lpoints[idx]; lines-&gt;push_back(line); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload