OpenCV筆記(十八) 使用霍夫變換檢測圓圈

2022-08-26 01:12:09 字數 1404 閱讀 9630

這些筆記的最初,我是以接近於原始碼分析的形式來梳理自己學習opencv的過程。

然而寫下來,一是執行力,二是時間的問題,確實越寫越馬虎了。用我老師的話:觀其大略了。

但是,暫時就這麼寫著吧。

在筆記《十七》中,我們簡單地談到了霍夫變換檢測直線的原理,就是判斷相鄰畫素點的值(x, y)對應的r-theta曲線是否能夠相交,如果有足夠多的相鄰的畫素點的曲線相交,我們就認為這些相鄰的畫素點構成一條直線。

圓圈亦然,只是把直線的方程替換成了圓的方程。除了極座標的r,多了兩個變數:xcenter和ycenter。

r就是畫素所在的圓圈的半徑,x-center和y-center就是這個圓圈的圓心。

如果若干相鄰的畫素,他們對應的r、x-center、y-center能夠相交,就說明它們位於同乙個圓圈的曲線上。

在opencv中,我們在使用霍夫變換檢測之前,一般先對影象進行高斯平滑,去除雜訊。

opencv中是這樣定義houghcircles函式的:

void houghcircles

(inputarrayimage, outputarraycircles, intmethod, doubledp, doublemindist, doubleparam1=100, doubleparam2=100, intminradius=0, intmaxradius=0 )

image需要8位單通道的灰度影象

circles一般為vector

method一般為cv_hough_gradient

dp是輸入影象和處理影象的比值,如果為1,則兩者相同;如果為2,則處理的影象是輸入影象的一半大小。

mindist是檢測到的圓圈之間,它們的圓心的最小距離。

param1是傳入canny()函式的higher threshold。預設lower threshold為higher threshold的一半。

param2暫時不了解。看示例**吧。

opencv中關於houghcircles的例子:

1

void houghdetection(const mat& src_gray, const mat& src_display, int cannythreshold, int

accumulatorthreshold)219

20//

shows the results

21imshow( windowname, display);22}

23 }

opencv筆記 霍夫變換

霍夫變化 opencv霍夫變化 opencv中的霍夫直線檢測的函式為houghlines 改進版本的houghlinesp函式 統計概論霍夫直線檢測 void houghlines inputarray image,輸入8 位元 單通道 二值 影象 outputarray lines,輸出的角度和r...

OpenCV 霍夫線變換 霍夫圓變換

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

opencv學習筆記十五 霍夫變換

一 霍夫直線變換 houghlinesp inputarray image,outputarray lines,double rho,double theta,int threshold,double minlinelength 0,double maxlinegap 0 引數解釋 image 邊緣...