如何在輪廓上任意,點3個點,算出這一個的圓周多少 |
尚未結案
|
ttccdd
一般會員 發表:11 回覆:1 積分:2 註冊:2009-11-30 發送簡訊給我 |
這是我的程式 如何將我左邊水梨輪廓的3個任意點,3個座標值,計算出這一顆水梨的圓周多少
//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "Unit4.h" #include #include <math.h><br />//--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) TForm4 *Form4; //--------------------------------------------------------------------------- __fastcall TForm4::TForm4(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm4::Button2Click(TObject *Sender) { Graphics::TBitmap *Bmp = new Graphics::TBitmap(); Byte *ptr; int gray; int i,j; int ii; int threshold; //threshold = ScrollBar1->Position; ii = ScrollBar1->Position; threshold = ii*2.55; Edit1->Text = threshold; Bmp->Assign(Image1->Picture->Bitmap); Bmp->PixelFormat=pf24bit; for(j=0; j ptr = (Byte *)Bmp->ScanLine[j]; for(i=0; i gray = (ptr[i]*0.114 ptr[i 1]*0.587 ptr[i 2]*0.299); if(gray > threshold ) gray = 255; else gray = 0; ptr[i] = ptr[i 1] = ptr[i 2] = (Byte)gray; } } Image2->Picture->Assign(Bmp); delete Bmp; } //--------------------------------------------------------------------------- void __fastcall TForm4::N4Click(TObject *Sender) { if (OpenPictureDialog1->Execute()) Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName); float ScaleFactor; } //--------------------------------------------------------------------------- void __fastcall TForm4::ScrollBar1Change(TObject *Sender) { Graphics::TBitmap *Bmp = new Graphics::TBitmap(); Byte *ptr; int gray; int i,j; int ii; int threshold; //threshold = ScrollBar1->Position; ii = ScrollBar1->Position; threshold = ii*2.55; Edit1->Text = threshold; Bmp->Assign(Image1->Picture->Bitmap); Bmp->PixelFormat=pf24bit; for(j=0; j ptr = (Byte *)Bmp->ScanLine[j]; for(i=0; i gray = (ptr[i]*0.114 ptr[i 1]*0.587 ptr[i 2]*0.299); if(gray > threshold ) gray = 255; else gray = 0; ptr[i] = ptr[i 1] = ptr[i 2] = (Byte)gray; } } Image2->Picture->Assign(Bmp); delete Bmp; } //--------------------------------------------------------------------------- void __fastcall TForm4::Button3Click(TObject *Sender) { int a,b,c,d; a=StrToInt(Label1->Caption); b=StrToInt(Label2->Caption); double g; g = sqrt((a*a) (b*b)/2); Label3->Caption="半徑為"; Label4->Caption=g*3.14159; Label5->Caption="mm"; int x1, y1, x2, y2; unsigned char value; for (int i=1; i<=361; i ) { x1 = b g*cos(M_PI*i/180); // 這一次滑鼠停留的位置x座標 y1 = d g*sin(M_PI*i/180); // 這一次滑鼠停留的位置y座標 if (i!=1){ Image2->Canvas->MoveTo(x2, x1); // 上一次滑鼠停留的位置 Image2->Canvas->LineTo(y2, y1); // 這一次滑鼠停留的位置 } x2 = x1; y2 = y1; } } //--------------------------------------------------------------------------- void __fastcall TForm4::Button1Click(TObject *Sender) { Graphics::TBitmap *Bmp = new Graphics::TBitmap(); Byte *ptr; int gray; int i,j,ii; int sx = 0; int sy = 0; int **pic = 0; int threshold; threshold = ScrollBar1->Position; ii = ScrollBar1->Position; threshold = ii*2.55; Edit1->Text = threshold; Bmp->Assign(Image1->Picture->Bitmap); Bmp->PixelFormat=pf24bit; pic = new int*[Bmp->Height]; for(i = 0; i< Bmp->Height; i ) pic[i] = new int[Bmp->Width]; Bmp->Assign(Image2->Picture->Bitmap); for(j=0; j ptr = (Byte *)Bmp->ScanLine[j]; for(i=0; i gray = (ptr[i*3]*0.114 ptr[i*3 1]*0.587 ptr[i*3 2]*0.299); pic[j][i] = ptr[i*3] = ptr[i*3 1] = ptr[i*3 2] = (Byte)gray; } } for(j=1; j ptr = (Byte *)Bmp->ScanLine[j]; for(i=1; i sx = -1*pic[j-1][i-1] pic[j 1][i-1] -2*pic[j-1][i] 2*pic[j 1][i] - pic[j-1][i 1] pic[j 1][i 1]; sy = pic[j-1][i-1] 2*pic[j][i-1] pic[j 1][i-1] - 1*pic[j-1][i 1] - 2*pic[j][i 1] - pic[j 1][i 1]; if(sqrt(sx*sx sy*sy)>threshold) { ptr[i*3] = ptr[i*3 1] = ptr[i*3 2] = 0; } else ptr[i*3] = ptr[i*3 1] = ptr[i*3 2] = 255; } } Image2->Picture->Assign(Bmp); for (i=0; i< Bmp->Height; i ) delete [] pic[i]; delete [] pic; delete Bmp; } void __fastcall TForm4::ScrollBar2Change(TObject *Sender) { Graphics::TBitmap *BMP = new Graphics::TBitmap(); BMP->Assign(Image1->Picture->Bitmap ); Byte* ptr=NULL; int posi=ScrollBar2->Position; Edit5->Text=posi; for (int y=0;y { ptr=(Byte*)BMP->ScanLine[y]; for (int x=0;x { int R=ptr[x*3 2]; int G=ptr[x*3 1]; int B=ptr[x*3]; int RValue=R ScrollBar2->Position; int GValue=G ScrollBar2->Position; int BValue=B ScrollBar2->Position; if (RValue>255) ptr[x*3 2]=255; else if (RValue<0) ptr[x*3 2]=0; else ptr[x*3 2]=RValue; if (GValue>255) ptr[x*3 1]=255; else if (GValue<0) ptr[x*3 1]=0; else ptr[x*3 1]=GValue; if (BValue>255) ptr[x*3]=255; else if (BValue<0) ptr[x*3]=0; else ptr[x*3]=BValue; } } Image2->Picture->Assign(BMP); delete BMP; } //--------------------------------------------------------------------------- void __fastcall TForm4::Button5Click(TObject *Sender) { Graphics::TBitmap *BMP = new Graphics::TBitmap(); BMP->Assign(Image1->Picture->Bitmap ); Byte* ptr=NULL; int posi=ScrollBar2->Position; Edit5->Text=posi; for (int y=0;y { ptr=(Byte*)BMP->ScanLine[y]; for (int x=0;x { int R=ptr[x*3 2]; int G=ptr[x*3 1]; int B=ptr[x*3]; int RValue=R ScrollBar2->Position; int GValue=G ScrollBar2->Position; int BValue=B ScrollBar2->Position; if (RValue>255) ptr[x*3 2]=255; else if (RValue<0) ptr[x*3 2]=0; else ptr[x*3 2]=RValue; if (GValue>255) ptr[x*3 1]=255; else if (GValue<0) ptr[x*3 1]=0; else ptr[x*3 1]=GValue; if (BValue>255) ptr[x*3]=255; else if (BValue<0) ptr[x*3]=0; else ptr[x*3]=BValue; } } Image2->Picture->Assign(BMP); delete BMP; } //--------------------------------------------------------------------------- void __fastcall TForm4::Image2MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Image2->Canvas->Pen->Width=5; Image2->Canvas->Pen->Style=psSolid; Image2->Canvas->Pen->Color=clRed; Image2->Canvas->MoveTo(X,Y); Image2->Canvas->LineTo(X,Y); Label1->Caption=X; Label2->Caption=Y; ListBox1->Items->Add(Label1->Caption); ListBox2->Items->Add(Label2->Caption); }
------
50 mp6fm06 |
g9412747
初階會員 發表:3 回覆:28 積分:36 註冊:2009-02-25 發送簡訊給我 |
|
daver046
一般會員 發表:3 回覆:5 積分:1 註冊:2004-04-28 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |