全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2301
推到 Plurk!
推到 Facebook!

Buffer存入Image問題

尚未結案
RK
一般會員


發表:4
回覆:5
積分:1
註冊:2004-11-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-11-10 00:51:41 IP:218.166.xxx.xxx 未訂閱
爬了一天的文章(真的是爬了一天),有找到一些不錯的資訊..但就是試不出來..><    以下是我用ADlink AngeloRTV-24 (有前輩用過嗎?)影像擷取程式(修改自sample)          程式主要的用途,是要連續擷取影像,存入10 Buffer裡頭,再透過IO去決定要使用那張影像,因為之前是用廠商存檔,再開到Image裡,現在要改成直接在記憶體裡處理… 我是想要能夠傳入Image就好了,因為之前寫的處理程式都是在Image上做處理… 廠商的sample有類似將Buffer的資料丟入Image裡的程式,但是改了一天就是改不出來… 爬過文章知道還有TMemoryStream這招,順便請教一下用TMemoryStream更快嗎?麻煩各位前輩幫幫忙了~感謝!!
#define Port_Per_Card 2
int     inter;
int     width=640;
int     height=480;
U8      Byte_Pixel= 1;        //8bit gray
U8      Video_Format=0;        //640*480
U16     Port = 0;
void*   Temp= NULL;    U32 Status;    HDC     formdc = NULL;
HDC     ghdc = NULL;    U8*     BufferAddress;
U8*     BufferAddress0;
U8*     BufferAddress1;    Graphics::TBitmap *Bitmap1;
Byte*   ptr;
Byte*   Source;
BITMAP  bmp;
BITMAPINFO*     BitmapInfo;
HBITMAP Hbmp;
Graphics::TBitmap* Tbmp = new Graphics::TBitmap( );
HBITMAP hbitbap = NULL;
//---------------------------------------------------------------------------    /* Port 0 中斷服務函式 */
void __stdcall MediaStreamProc0( U32 VideoBufferAddress ,U16 PortNo )
{
        BufferAddress0 =  (U8*)VideoBufferAddress;
        AngeloRTV_Get_Int_Status(PortNo,&Status);
        if((Status>>1&0x01)==1)//Channel 0 for each port 
        {
                memcpy(Temp,(PVOID)BufferAddress0,width*height*Byte_Pixel);
                BitBlt(formdc,0,0,width,height,ghdc,0,0,SRCCOPY);        //顯示影像
 
 /*
        for (int y = 0; y < Bitmap1->Height; y  )
        {
                ptr = (Byte *)Bitmap1->ScanLine[y];
                Source = (Byte *)VideoBufferAddress;
                for (int x = 0; x < Bitmap1->Width; x  )
                {
                        //memset(&ptr[3*x],&Source[(y*gWidth x)*Byte_Pixel],3);
                        ptr[3*x] = Source[(y*gWidth x)*Byte_Pixel];
                        ptr[3*x 1] = ptr[3*x] ;
                        ptr[3*x 2] = ptr[3*x] ;
                }
                //memcpy(ptr,&Source[y*gWidth*Byte_Pixel],gWidth*Byte_Pixel);
        }
        Form1->Image1->Canvas->Draw(0,0,Bitmap1);
*/                綠色字Mark起來的就是我不知道怎麼改的地方…。
                
                inter  ;
                Form1->Edit5->Text=inter;
        }
        else
        {
                return;
        }
 }
 
 //---------------------------------------------------------------------------
 
 /* 連續擷取影像 */
 void __fastcall TForm1::Capture1Click(TObject *Sender)
{            for(Port = 0; Port < Port_Per_Card ; Port  )
        {
                AngeloRTV_Capture_Stop(Port);
                AngeloRTV_Set_Callback(Port,NULL);
        }
  
  for(Port = 0; Port < Port_Per_Card;Port  )//卡片Channel 啟動
        {
    AngeloRTV_Set_Image_Geometric(Port,0,0,width,height, 1, 1);//設定影像大小、比例
           AngeloRTV_Set_Color_Format(Port,Byte_Pixel); // 設定影像格式 灰階 or 彩色
                AngeloRTV_Set_Video_Format(Port,Video_Format);
                AngeloRTV_Set_Image_Config(Port,5,0);// 0 for color camera, 1 for monochrome
                AngeloRTV_Set_Int_Factor(Port,0x03);
                AngeloRTV_Select_Channel(Port,0x01);//only channel 0 in each port
  }
  
  if(Byte_Pixel==1)
        {
    BitmapInfo  = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)   sizeof(RGBQUAD) * 255);
                BitmapInfo->bmiHeader.biSizeImage = width*height;
                BitmapInfo->bmiHeader.biClrUsed = 256;
                BitmapInfo->bmiHeader.biClrImportant = 256;
                for(int j=0;j<256;j  )
                {
                        BitmapInfo->bmiColors[j].rgbBlue = j;
                        BitmapInfo->bmiColors[j].rgbGreen  = j;
                        BitmapInfo->bmiColors[j].rgbRed  = j;
                }
  }
        
        else
        {
                BitmapInfo  = (BITMAPINFO *)malloc(sizeof(BITMAPINFO));
                BitmapInfo->bmiHeader.biSizeImage = 0;
                BitmapInfo->bmiHeader.biClrUsed = 0; 
                BitmapInfo->bmiHeader.biClrImportant = 0;        
        }
        
  BitmapInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  BitmapInfo->bmiHeader.biWidth = width;
        BitmapInfo->bmiHeader.biHeight = -height;
        BitmapInfo->bmiHeader.biPlanes = 1;
        BitmapInfo->bmiHeader.biBitCount = Byte_Pixel*8;
        BitmapInfo->bmiHeader.biCompression = 0;
        藍色字應該是定義BMP的標頭吧?    /*
  Bitmap1 =   new Graphics::TBitmap();
  Image1->Width = width;
  Image1->Height = height;
  Bitmap1->Width =  width;
  Bitmap1->Height = height;
  Bitmap1->PixelFormat = pf24bit;
  */
  綠色字Mark起來的就是我不知道怎麼改的地方…。      if(hbitbap)
  {
          DeleteObject(hbitbap);
          hbitbap =NULL;
  }
  if(ghdc)
  {
          DeleteObject(ghdc);
          hbitbap =NULL;
  }      ghdc =CreateCompatibleDC(GetDC(Panel1->Handle )); //GetActiveWindow
  hbitbap = CreateDIBSection(ghdc,BitmapInfo,DIB_RGB_COLORS,&Temp,NULL,0);
  SelectObject(ghdc,hbitbap);
  formdc =  GetDC(Panel1->Handle) ;紅字這4行程式大概知道在做什麼,但不是很了解。      AngeloRTV_Set_Callback(0,MediaStreamProc0); //PORT 0 指定影像中斷服務函式位置
  AngeloRTV_Set_Callback(1,MediaStreamProc1); //PORT 1 指定影像中斷服務函式位置            for(Port = 0; Port < Port_Per_Card;Port  )//卡片Channel 啟動
        {
                AngeloRTV_Capture_Start(Port,0xFFFFFFFF);//LIVE 取像  意思是擷取 0xFFFFFFFF 張影像才停止
                //AngeloRTV_Capture_Start(Port,0x00000010);//擷取10影像後停止
        }
}
RK
一般會員


發表:4
回覆:5
積分:1
註冊:2004-11-02

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-11-10 21:33:16 IP:218.166.xxx.xxx 未訂閱
剛又發現一個新問題…存檔下來的影像居然是32bit Truecolor的影像… 是因為調色盤的關係嗎??
harisan3
一般會員


發表:6
回覆:11
積分:3
註冊:2004-12-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-11-10 22:43:11 IP:220.139.xxx.xxx 未訂閱
                SysPal.lPal.palPalEntry[i].peRed   = (unsigned char)i;
                SysPal.lPal.palPalEntry[i].peGreen = (unsigned char)i;
                SysPal.lPal.palPalEntry[i].peBlue  = (unsigned char)i;
                SysPal.lPal.palPalEntry[i].peFlags = 0;  // peFlags must set to 0    
32 bit是因為宣告的問題,你宣告了(Byte*4)分別是peRed,peGreen,peBlue,peFlags. 如果只有R,G,B的話你就要設定成24 bit 而不是32 bit.
RK
一般會員


發表:4
回覆:5
積分:1
註冊:2004-11-02

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-11-10 22:57:58 IP:220.136.xxx.xxx 未訂閱
那請問如果我要存成8bit的灰階要怎麼設呢??謝謝!!
系統時間:2024-05-11 15:56:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!