14

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?

Community
  • 1
  • 1
zzzz
  • 682
  • 10
  • 16
  • 2
    Good one. I always assumed the lines were given in order. And this assumption has so far been consistent with my results... However, it would be nice to be sure. – Quentin Geissmann Jul 05 '12 at 22:57

1 Answers1

15

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 );
 }
Ghilas BELHADJ
  • 13,412
  • 10
  • 59
  • 99
Sam
  • 19,708
  • 4
  • 59
  • 82
  • Thank you for making that clear and pointing me to the code. I'm using the probabilistic version and going through the code, it would be nice to bring linesMax out too to speed things up. – zzzz Jul 06 '12 at 13:17
  • 1
    The Probabilistic is in the same file, i think you already found it. The different approach in line search means that the vote count is not as relevant as in classical H. As long as a line has the min required votes, it is pushed in the result queue. No sorting is performed. – Sam Jul 06 '12 at 13:38
  • Hello, Sorry for revamping this thread, but do you have an idea hwo to get the accumulator value in probalistic hough transform? I am not quite sure where in the accumulator matrix the line's votes are. – Aeefire Mar 26 '15 at 12:42