OpenCV Hough strongest lines

独自空忆成欢 提交于 2019-11-29 12:06:09

问题


Do the HoughLines or HoughLinesP functions in OpenCV return the list of lines in accumulator order like the HoughCircles function does? I would like to know the ordering of lines. It would also be very handy to get a the accumulator value for the lines so an intelligent and adaptive threshold could be used instead of a fixed one. Are either the ordering or the accumulator value available without rewriting OpenCV myself?


回答1:


HoughTransform orders lines descending by number of votes. You can see the code here

However, the vote count is lost as the function returns - the only way to have it is to modify OpenCV.

The good news is that is not very complicated - I did it myself once. It's a metter of minutes to change the output from vector< Vec2f > to vector< Vec3f > and populate the last param with vote count.

Also, you have to modify CvLinePolar to add the third parameter - hough is implemented in C, and there is a wrapper over it in C++, so you have to modify both the implementation and the wrapper.

The main code to modify is here

 for( i = 0; i < linesMax; i++ )
 {
        CvLinePolar 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;

        // add this line, and a field voteCount to CvLinePolar
        // DO NOT FORGET TO MODIFY THE C++ WRAPPER
        line.voteCount = accum[idx];          

        cvSeqPush( lines, &line );
 }


来源:https://stackoverflow.com/questions/11352528/opencv-hough-strongest-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!