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

有關Buffer存入Image問題...

尚未結案
RK
一般會員


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

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-11-10 00:44:55 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;

/*
  Bitmap1 =   new Graphics::TBitmap();
  Image1->Width = width;
  Image1->Height = height;
  Bitmap1->Width =  width;
  Bitmap1->Height = height;
  Bitmap1->PixelFormat = pf24bit;
  */
  綠色字Mark起來的就是我不知道怎麼改的地方…。    藍色字應該是定義BMP的標頭吧?
  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 於 2005/11/10 00:53:52
CoffeeX
中階會員


發表:18
回覆:121
積分:72
註冊:2005-02-18

發送簡訊給我
#2 引用回覆 回覆 發表時間:2006-08-28 22:22:51 IP:140.125.xxx.xxx 未訂閱

這張卡我有實作過,

你是希望存到Image?

那就把comment 那段 uncomment 試試看吧,

他有callback 跟 thread 兩種方法取像,

我實作的部份是 callback 的,

有興趣可以交流一下...

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