霍夫變換原始碼

2021-07-23 12:18:18 字數 3920 閱讀 7313

void cv::houghlines( inputarray _image, outputarray _lines,

double rho, double theta, int threshold,

double srn, double stn )

static

void seqtomat(const cvseq* seq, outputarray _arr)

else

_arr.release();

}cv_impl cvseq*

cvhoughlines2( cvarr* src_image, void* linestorage, int method,

double rho, double theta, int threshold,

double param1, double param2 )

else

if( cv_is_storage( linestorage ))

else

if( cv_is_mat( linestorage ))

else

cv_error( cv_stsbadarg, "destination is not cvmemstorage* nor cvmat*" );

iparam1 = cvround(param1);

iparam2 = cvround(param2);

switch( method )

if( mat )

else

result = lines;

return result;

}//標準霍夫變換

static

void

icvhoughlinesstandard( const cvmat* img, float rho, float theta,

int threshold, cvseq *lines, int linesmax )

// stage 1. fill accumulator

for( i = 0; i < height; i++ )

for( j = 0; j < width; j++ )

}// stage 2. 查詢區域性最大值

for(int r = 0; r < numrho; r++ )

for(int n = 0; n < numangle; n++ )

// stage 3. 按累加器的值對檢測的線進行排序

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 < linesmax; i++ )

}//概率霍夫變換

static

void

icvhoughlinesprobabilistic( cvmat* image,

float rho, float theta, int threshold,

int linelength, int linegap,

cvseq *lines, int linesmax )

ttab = &trigtab[0];

mdata0 = mask.data;

cvstartwriteseq( cv_32sc2, sizeof(cvseq), sizeof(cvpoint), storage, &writer );//建立新序列並初始化寫入部分

// stage 1. collect non-zero image points

for( pt.y = 0, count = 0; pt.y < height; pt.y++ )

else

mdata[pt.x] = 0;}}

seq = cvendwriteseq( &writer ); //完成寫入操作

count = seq->total;

// stage 2. 隨機順序處理所有點

for( ; count > 0; count-- )

, };

float a, b;

int* adata = (int*)accum.data; //定義指向累加器指標

int i, j, k, x0, y0, dx0, dy0, xflag;

int good_line;

const

int shift = 16;

i = point->y;

j = point->x;

// "remove" it by overriding it with the last element

*point = *(cvpoint*)cvgetseqelem( seq, count-1 );

//檢查是否已被排除 (i.e. belongs to some other line)

if( !mdata0[i*width + j] )

continue;

// 更新累加器,找到最可能的線

for( n = 0; n < numangle; n++, adata += numrho )

}// if it is too "weak" candidate, continue with another point

if( max_val < threshold )

continue;

// from the current point walk in each direction

// 沿著找到的線並提取線段

a = -ttab[max_n*2+1];

b = ttab[max_n*2];

x0 = j;

y0 = i;

if( fabs(a) > fabs(b) )

else

for( k = 0; k < 2; k++ )

else

if( j1 < 0 || j1 >= width || i1 < 0 || i1 >= height )

break;

mdata = mdata0 + i1*width + j1;

// for each non-zero point:

// update line end,

// clear the mask element

// reset the gap

if( *mdata )

else

if( ++gap > linegap )

break;}}

good_line = abs(line_end[1].x - line_end[0].x) >= linelength ||

abs(line_end[1].y - line_end[0].y) >= linelength;

for( k = 0; k < 2; k++ )

else

mdata = mdata0 + i1*width + j1;

// for each non-zero point:

// update line end,

// clear the mask element

// reset the gap

if( *mdata )

}*mdata = 0;

}if( i1 == line_end[k].y && j1 == line_end[k].x )

break;}}

if( good_line )

;cvseqpush( lines, &lr );

if( lines->total >= linesmax )

return;}}

}

OpenCV 霍夫線變換 霍夫圓變換

關於霍夫變換在官方文件opencv249裡的描述如下 api如下 void houghlines inputarray image,outputarray lines,double rho,double theta,int threshold,double srn 0,double stn 0 vo...

缺點 霍夫圓 霍夫變換

霍夫變換是一種特徵提取,被廣泛應用在影象分析 電腦視覺以及數字影像處理。霍夫變換是用來辨別找出物件中的特徵,例如 線條。他的演算法流程大致如下,給定乙個物件 要辨別的形狀的種類,演算法會在引數空間中執行投票來決定物體的形狀,而這是由累加空間 accumulator space 裡的區域性最大值來決定...

霍夫變換 Hough Transform

霍夫變換的主要作用是從影象中檢測出具有某種相同特徵的幾何形狀,如直線 圓等。霍夫變換的基本原理 例如檢測情景為直線檢測。我們知道,在直角座標系下,直線方程表示為y k x b 其中k,b 為引數,表示直線的斜率和截距。那麼,對於直角座標系下的某個特定點 x 0,y0 過該點的任意直線方程為y0 k ...