請問我如何找到一個圓的中心點 |
|
n8652070
一般會員 發表:4 回覆:3 積分:1 註冊:2006-10-26 發送簡訊給我 |
請問,我目前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 發送簡訊給我 |
|
n890377
一般會員 發表:17 回覆:16 積分:21 註冊:2006-07-13 發送簡訊給我 |
|
n8652070
一般會員 發表:4 回覆:3 積分:1 註冊:2006-10-26 發送簡訊給我 |
===================引 用 文 章=================== 目前我想到的有兩個做法 給你參考一下 如果你有圓上的所有點的座標值 分別找 x 和 y 的最大最小值 加起來除以二就是了 以 x 來說 (Xmax Xmin)/2? 就是圓心的 x 座標值 y也是一樣? 很簡單吧? ^___^ 另外一個做法是用向量找交點 找圓上的任意三點 a b c 線段ab 的中垂線有個向量?? bc 的中垂線有個向量 兩個向量的延長線的交點就是圓心了??? 感謝大大的指導,小弟我在試看看,有進一步的結果在跟大家分享 |
n8652070
一般會員 發表:4 回覆:3 積分:1 註冊:2006-10-26 發送簡訊給我 |
|
johnpage
初階會員 發表:0 回覆:79 積分:40 註冊:2004-08-07 發送簡訊給我 |
|
n890377
一般會員 發表:17 回覆:16 積分:21 註冊:2006-07-13 發送簡訊給我 |
若你的背景是單純的....只剩圓的部份...
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; j { ptr_s = (Byte *)Image1->Picture->Bitmap->ScanLine[j]; for (i=0; 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 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |