線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:4210
推到 Plurk!
推到 Facebook!

請問我如何找到一個圓的中心點

 
n8652070
一般會員


發表:4
回覆:3
積分:1
註冊:2006-10-26

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-11-19 14:54:04 IP:163.23.xxx.xxx 訂閱
請問,我目前CCD擷取到影像後,我做處理判斷後找到圓,我要如何找到圓的中心點並標示出來??
判斷圓程式如下:
void __fastcall TForm1::makeEllipticalOutline(OUTLINE *outline, int xrad, int yrad)
{
short *ptr;
int xradsq = xrad * xrad;
int yradsq = yrad * yrad;
int xradbkpt = (int) (xradsq / sqrt(xradsq yradsq));
int yradbkpt = (int) (yradsq / sqrt(xradsq yradsq));
int x, y;
int curx, cury;
// count # of iterations in loops below
outline->perim_length = 4 * xradbkpt 4 * yradbkpt 4;
outline->perim = (short *)
malloc(2 * (outline->perim_length) * sizeof(short));
ptr = outline->perim;
*(ptr) = curx = 0; // perimeter starts at top and proceeds clockwise
*(ptr) = cury = - yrad;
// from 0 to 45 degrees, measured cw from top
for (x = 1; x <= xradbkpt ; x ) {
y = (int) (-yrad * sqrt(1 - ((float) x / xrad)*((float) x / xrad)));
*(ptr) = x - curx;
*(ptr) = y - cury;
curx = x;
cury = y;
}

// from 45 to 135 degrees (including right axis)
for (y = - yradbkpt ; y <= yradbkpt ; y ) {
x = (int) (xrad * sqrt(1 - ((float) y / yrad)*((float) y / yrad)));
*(ptr) = x - curx;
*(ptr) = y - cury;
curx = x;
cury = y;
}
// from 135 to 225 degrees (including down axis)
for (x = xradbkpt ; x >= - xradbkpt ; x--) {
y = (int) (yrad * sqrt(1 - ((float) x / xrad)*((float) x / xrad)));
*(ptr) = x - curx;
*(ptr) = y - cury;
curx = x;
cury = y;
}
// from 225 to 315 degrees (including left axis)
for (y = yradbkpt ; y >= - yradbkpt ; y--) {
x = (int) (-xrad * sqrt(1 - ((float) y / yrad)*((float) y / yrad)));
*(ptr) = x - curx;
*(ptr) = y - cury;
curx = x;
cury = y;
}
// from 315 to 360 degrees
for (x = - xradbkpt ; x < 0 ; x ) {
y = (int) (-yrad * sqrt(1 - ((float) x / xrad)*((float) x / xrad)));
*(ptr) = x - curx;
*(ptr) = y - cury;
curx = x;
cury = y;
}
outline->halfsize_x = xrad;
outline->halfsize_y = yrad;
}

psl
一般會員


發表:6
回覆:30
積分:7
註冊:2003-06-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2006-11-19 17:09:18 IP:218.172.xxx.xxx 未訂閱

目前我想到的有兩個做法
給你參考一下

如果你有圓上的所有點的座標值
分別找 x 和 y 的最大最小值
加起來除以二就是了
以 x 來說 (Xmax Xmin)/2 就是圓心的 x 座標值
y也是一樣 很簡單吧 ^___^
另外一個做法是用向量找交點
找圓上的任意三點 a b c
線段ab 的中垂線有個向量 bc 的中垂線有個向量
兩個向量的延長線的交點就是圓心了
n890377
一般會員


發表:17
回覆:16
積分:21
註冊:2006-07-13

發送簡訊給我
#3 引用回覆 回覆 發表時間:2006-11-20 13:02:04 IP:163.22.xxx.xxx 未訂閱
你的圓是已經二值化以後的圓嗎????
------
.
n8652070
一般會員


發表:4
回覆:3
積分:1
註冊:2006-10-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2006-11-21 16:22:01 IP:163.23.xxx.xxx 訂閱

===================引 用 文 章===================

目前我想到的有兩個做法
給你參考一下

如果你有圓上的所有點的座標值
分別找 x 和 y 的最大最小值
加起來除以二就是了
以 x 來說 (Xmax Xmin)/2? 就是圓心的 x 座標值
y也是一樣? 很簡單吧? ^___^
另外一個做法是用向量找交點
找圓上的任意三點 a b c
線段ab 的中垂線有個向量?? bc 的中垂線有個向量
兩個向量的延長線的交點就是圓心了???



感謝大大的指導,小弟我在試看看,有進一步的結果在跟大家分享
n8652070
一般會員


發表:4
回覆:3
積分:1
註冊:2006-10-26

發送簡訊給我
#5 引用回覆 回覆 發表時間:2006-11-21 16:24:50 IP:163.23.xxx.xxx 訂閱

===================引 用 文 章===================
你的圓是已經二值化以後的圓嗎????


是的,我所找到的原已作過處理(包含二值化),我是用圓找輪廓來判斷圓的。
johnpage
初階會員


發表:0
回覆:79
積分:40
註冊:2004-08-07

發送簡訊給我
#6 引用回覆 回覆 發表時間:2006-11-22 07:24:52 IP:218.175.xxx.xxx 未訂閱
小心  
1.CCD 對於測試平面的角度會造成形狀變異
2.距離或解析度所造成取樣點不足
此時必須藉由類神經輔助
可參考台科大電子工程系 黃忠偉教授指導的專題
n890377
一般會員


發表:17
回覆:16
積分:21
註冊:2006-07-13

發送簡訊給我
#7 引用回覆 回覆 發表時間:2006-11-25 15:08:54 IP:163.22.xxx.xxx 未訂閱
若你的背景是單純的....只剩圓的部份...

Graphics::TBitmap *TheBitmap, *TempBitmap;
TempBitmap = new Graphics::TBitmap();
TempBitmap =Image1->Picture->Bitmap;
Byte *ptr_s;
int g_s,j,i,line,g_s1,g_s2;
int cxy=0,sx=0,sy=0,sum=0;
AnsiString ss;
TempBitmap->PixelFormat = pf24bit;
for (j=0; jHeight; j )
{
ptr_s = (Byte *)Image1->Picture->Bitmap->ScanLine[j];
for (i=0; iWidth; i )
{
g_s = ptr_s[i*3 2];
g_s1= ptr_s[i*3 1];
g_s2= ptr_s[i*3];
if(g_s2==255&& g_s1==255&& g_s==255)
{
sx=sx i;
sy=sy j;
sum=sum 1;
cxy ;
i Image1->Picture->Bitmap->Width; //紀錄座標之後讓i大於判斷式跳出迴圈
j Image1->Picture->Bitmap->Height;//紀錄座標之後讓j大於判斷式跳出迴圈
}

}
}
if(sum>0)
{
sx= sx/cxy;
sy= sy/cxy;
}

------
.
n8652070
一般會員


發表:4
回覆:3
積分:1
註冊:2006-10-26

發送簡訊給我
#8 引用回覆 回覆 發表時間:2006-12-11 10:34:09 IP:163.23.xxx.xxx 訂閱
^^    感謝各位大大的指教,我運用其所教導的向量方法,已可找到圓的中心點。
感謝各位大大的指導 ~~
系統時間:2024-05-08 14:21:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!