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

test coding

 
monkey0710
一般會員


發表:2
回覆:1
積分:0
註冊:2008-04-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-07-02 14:28:13 IP:140.125.xxx.xxx 訂閱

[code cpp]
請在此區域輸入程式碼
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "EzCapCamera"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
EzCapCamera1->CameraDisplay(); //開啟攝影機攝影機畫面
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
EzCapCamera1->CameraClose();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------


void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
{
Graphics::TBitmap *Bitmap1= new Graphics::TBitmap();
Bitmap1->PixelFormat=pf24bit;
Bitmap1->Assign(Image1->Picture);
int Threshold;
Threshold = (int)ScrollBar1->Position;
Byte *ptr;
Byte gray;
for (int y=0; yHeight;y )
{
ptr=(Byte *)Bitmap1->ScanLine[y];
for(int x=0;xWidth*3;x =3)
{
gray=( ptr[x] ptr[x 1] ptr[x 2])/3;
if(gray>Threshold)
{
ptr[x]=255;
ptr[x 1]=255;
ptr[x 2]=255;
}
else
{
ptr[x]=0;
ptr[x 1]=0;
ptr[x 2]=0;
}
}
}
Repaint();
Form1->Image1->Picture->Assign(Bitmap1);
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button7Click(TObject *Sender)
{
Timer1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
//----抓取bmp檔並存為1.bmp-----------
Graphics::TBitmap *Bitmap1 = new Graphics::TBitmap();
EzCapCamera1->CapBitmapFrame(Bitmap1);
EzCapCamera1->CapBmpPic("1.bmp");
Image1->Picture->LoadFromFile("1.bmp");
//---- 抓取ScrollBar的position設為Threshold,並以此值做二值化
Bitmap1->PixelFormat=pf24bit;
Bitmap1->Assign(Image1->Picture);
int Threshold;
Threshold = (int)ScrollBar1->Position;
Edit1->Text=ScrollBar1->Position;
Byte *ptr;
Byte gray;
for (int y=0; yHeight;y )
{
ptr=(Byte *)Bitmap1->ScanLine[y];
for(int x=0;xWidth*3;x =3)
{
gray=( ptr[x] ptr[x 1] ptr[x 2])/3;
if(gray>Threshold)
{
ptr[x]=255;
ptr[x 1]=255;
ptr[x 2]=255;
}
else
{
ptr[x]=0;
ptr[x 1]=0;
ptr[x 2]=0;
}
}
}
Form1->Image1->Picture->Assign(Bitmap1);
//------計算面積以及重心---------
Byte *tptr;
int r,g,b;
int i,j,XX,YY;
int sum=0, X=0, Y=0;
Bitmap1->Assign(Image1->Picture->Bitmap);
Bitmap1->PixelFormat=pf24bit;
for (int i=0;iHeight;i )
{
tptr=(Byte*)Bitmap1->ScanLine[i];
for (int j=0;jWidth;j )
{
b=tptr[i*3];
g=tptr[i*3 1];
r=tptr[j*3 2];
if(r==255&&g==255&&b==255&&iHeight&&jHeight)
{
sum=sum 1;
X=X i;
Y=Y i;
XX=X/sum;
YY=Y/sum;
Form1->Edit2->Text=sum;
Form1->Edit3->Text=XX;
Form1->Edit4->Text=YY;
}
}
}

}
[/code]
系統時間:2024-11-21 23:46:39
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!