codes of houghTransform(standard) [closed]

asked 2013-09-21 00:53:14 -0600

stereomatching gravatar image

updated 2020-11-13 03:44:19 -0600

I am studying the codes of hough transform(HoughLinesStandard) on this link hough transform.

Have some problems about the codes

int const numrho = cvRound(((width + height) * 2 + 1) / rho); //#1    
for(int i = 0; i < height; ++i){
    uchar const *img_ptr = img.ptr<uchar>(i);
    for(int j = 0; j < width; ++j){
        if( img_ptr[j] != 0 ){
            for(int n = 0; n < numangle; ++n){
                int r = cvRound( j * tabCos[n] + i * tabSin[n] );
                r += (numrho - 1) / 2; //#2
                ++accum[(n+1) * (numrho+2) + r + 1];
            }
        }
    }
}

Q1 : The first question is(#1), why is the size of numrho = cvRound(((width + height) * 2 + 1) / rho)?

let x = width, y = height

x * x + y * y = r * r --(1)
sqrt((x + y) * (x + y) - 2*x*y) = r --(2)
from(2) => x + y >= r
since openCV consider only points such that r > 0
=> r == 2 * (x + y) 
+1 because we need to include the 0 point

Is this correct?Anything need to fix?

Q2 : why r += (numrho - 1) / 2; ? make sure it is always positive?

Thanks a lot

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-13 03:43:38.489333