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

ccd能擷取到畫面但如何在畫面進行處理

答題得分者是:taishyang
student38
一般會員


發表:22
回覆:13
積分:7
註冊:2010-04-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-06-24 22:57:39 IP:120.114.xxx.xxx 訂閱
我是剛開始接觸這一類webcam擷取照片並處理影像 處理類似2值灰階那種的 單讀取讀片可以處理,但是使用webcam擷取後的圖片使用灰階卻只處理三分之一 請問是我少打了什麼指令,或是哪裡不夠完善@@? 

[code cpp]
void __fastcall TForm1::N11Click(TObject *Sender)
{
// 啟動並設定外部 CCD camera 的參數
int px=5, py=5;

Screen->Cursor = crHourGlass;

cap.setParentHandle(Handle);
cap.createWindow();
cap.connect();
cap.getSource();
cap.getFormat();
cap.getDisplay();

cap.setPreviewRate(30);
cap.setPreview(true);

cap.setLocation(px, py);

if ( GroupBox1->Left < cap.left cap.imgWidth )
GroupBox1->Left = cap.left cap.imgWidth 1;

Form1->Refresh();

Screen->Cursor = crDefault;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::bitnTakePictureClick(TObject *Sender)
{
// 拍照
TImage *image = Image3;
int gap=3;

image->Left = cap.left;
image->Top = gap cap.imgHeight;
image->Picture->Bitmap->Width = cap.imgWidth;
image->Picture->Bitmap->Height= cap.imgHeight;
image->Canvas->CopyRect(Rect(0,0,cap.imgWidth,cap.imgHeight),
Form1->Canvas,
Rect(cap.left, cap.top,
cap.left cap.imgWidth, cap.top cap.imgHeight)
);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N5Click(TObject *Sender)
{
if (Image3->Picture->Bitmap->Empty==true) //===灰階
ShowMessage("請載入圖檔!!");
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
Byte *ptr;
int r,g,b;
int gray;
int i,j;
int threshold;
Bmp->PixelFormat=pf24bit;
Bmp->Assign(Image3->Picture->Bitmap);
for(j=0;jHeight;j )
{
ptr = (Byte *)Bmp->ScanLine[j];
for(i=0;iWidth;i )
{
b=ptr[i*3];
g=ptr[i*3 1];
r=ptr[i*3 2];
gray=0.299*r 0.587*g 0.114*b;
ptr[i*3]=(Byte)gray;
ptr[i*3 1]=(Byte)gray;
ptr[i*3 2]=(Byte)gray;
}
}
Image3->Picture->Assign(Bmp);
delete Bmp;

}
//---------------------------------------------------------------------------請在此區域輸入程式碼

[/code]
感謝taishyang大大的教導!
編輯記錄
student38 重新編輯於 2010-06-24 22:59:01, 註解 無‧
student38 重新編輯於 2010-06-24 23:00:44, 註解 無‧
student38 重新編輯於 2010-06-24 23:02:41, 註解 無‧
student38 重新編輯於 2010-06-24 23:04:46, 註解 無‧
student38 重新編輯於 2010-06-25 16:35:09, 註解 無‧
student38 重新編輯於 2010-06-25 16:35:28, 註解 無‧
taishyang
站務副站長


發表:377
回覆:5490
積分:4563
註冊:2002-10-08

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-06-25 16:25:01 IP:122.116.xxx.xxx 訂閱
Bmp->PixelFormat=pf24bit;
Bmp->Assign(Image3->Picture->Bitmap);
要顛倒
Bmp->Assign(Image3->Picture->Bitmap);
Bmp->PixelFormat=pf24bit;

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