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

ㄧ般的視訊與無線針孔攝影機的差別?

尚未結案
enfin
一般會員


發表:5
回覆:4
積分:1
註冊:2005-07-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-07-12 19:57:51 IP:140.121.xxx.xxx 未訂閱
請問做影像處理用一般的視訊與無線針孔攝影機有什麼差別ㄋ?我目前遇到的問題是用之前學長給的程式做影像處理,如果是用一般視訊都很正常,但是用無線針孔攝影機時,一開始按contact是可以連的,但是一按capture時,卻發生錯誤,如下圖所示: 感謝各位高手提供寶貴的意見! 附程式如下:
 
//---------------------------------------------------------------------------
#include 
#include 
#include 
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
bool entry;
Graphics::TBitmap *pBitmap;
Graphics::TBitmap *pBitmap1;
int ImWidth=320,ImHeight=240,B[240][320],G[240][320],R[240][320];
LRESULT CALLBACK capVideoStreamCallbackProc(HWND hWnd,LPVIDEOHDR lpVHdr)
{ BYTE *ptr;
int Address;
if(!entry)
{ entry=true;
for(int i=0;i<240;i++)
{
ptr=(BYTE*)pBitmap->ScanLine[239-i];
for(int j=0;j<320;j++)
{
Address=j*3;
B[i][j]=(int)(lpVHdr->lpData)[3*(i*320+j)];
G[i][j]=(int)(lpVHdr->lpData)[3*(i*320+j)+1];
R[i][j]=(int)(lpVHdr->lpData)[3*(i*320+j)+2];
ptr[Address]=B[i][j];
ptr[Address+1]=G[i][j];
ptr[Address+2]=R[i][j];
} }
entry=false; }
return 0;}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{  }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
pBitmap= new Graphics::TBitmap();
pBitmap->Assign(Form1->Image1->Picture);
ImHeight=pBitmap->Height;
ImWidth=pBitmap->Width; }
//---------------------------------------------------------------------------
void __fastcall TForm1::ContactClick(TObject *Sender)
{
hWndC=capCreateCaptureWindow("Capture Window",WS_CHILD | WS_VISIBLE,40,40,320,240,Handle,0);
CAPDRIVERCAPS aCAPDRIVERCAPS;
aCAPDRIVERCAPS.wDeviceIndex=0;
capDriverConnect(hWndC,aCAPDRIVERCAPS.wDeviceIndex);
capPreviewRate(hWndC,66);
capPreview(hWndC,true); }
//---------------------------------------------------------------------------
void __fastcall TForm1::StartClick(TObject *Sender)
{  Timer1->Enabled=true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SaveImageClick(TObject *Sender)
{
pBitmap1= new Graphics::TBitmap();
pBitmap1->Assign(Form1->Image1->Picture);
pBitmap1->SaveToFile("Image.bmp"); }
//---------------------------------------------------------------------------
void __fastcall TForm1::SourceClick(TObject *Sender)
{ capDlgVideoSource(hWndC); }
//---------------------------------------------------------------------------
void __fastcall TForm1::DisconnectClick(TObject *Sender)
{
capDriverDisconnect(hWndC);
capPreview(hWndC,false);
capCaptureStop(hWndC);
capSetCallbackOnFrame(hWndC,NULL);
DestroyWindow(hWndC); }
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
pBitmap1= new Graphics::TBitmap();
pBitmap1->Assign(Form1->Image1->Picture);
BYTE *ptr1;
int Address;
for(int y=0;y<240;y++)
{
ptr1=(BYTE*)pBitmap1->ScanLine[239-y];
for(int x=0;x<320;x++)
{
Address=x*3;
ptr1[Address]=B[y][x];
ptr1[Address+1]=G[y][x];
ptr1[Address+2]=R[y][x];
} }
Form1->Image1->Canvas->Draw(0,0,pBitmap1);
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
Byte *ptr;
int r,g,b;
int gray;
int i,j;
int threshold;
Bmp->Assign(Image1->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;
} }
Image1->Picture->Assign(Bmp);
delete pBitmap1; }
//---------------------------------------------------------------------------
void __fastcall TForm1::StopClick(TObject *Sender)
{ Timer1->Enabled=false; }
//---------------------------------------------------------------------------
void __fastcall TForm1::CaptureClick(TObject *Sender)
{
CAPTUREPARMS aCAPTUREPARMS;
aCAPTUREPARMS.fYield=true;
aCAPTUREPARMS.fMakeUserHitOKToCapture=true;
capCaptureSetSetup( hWndC, &aCAPTUREPARMS, sizeof(aCAPTUREPARMS));
entry=false;
capSetCallbackOnFrame(hWndC,capVideoStreamCallbackProc);
}
//---------------------------------------------------------------------------
發表人 - enfin 於 2005/07/12 23:56:41
enfin
一般會員


發表:5
回覆:4
積分:1
註冊:2005-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-07-12 22:45:45 IP:140.121.xxx.xxx 未訂閱
我想問的是為什麼會有這種情形發生ㄋ?程式碼哪裡需要改ㄉㄋ?還是系統ㄉ問題ㄋ?想請教各位高手,感謝ㄌ!
taishyang
站務副站長


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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-07-12 23:44:17 IP:218.168.xxx.xxx 未訂閱
您好:    您的問題可能是有new但沒有delete所造成的 <> > >
enfin
一般會員


發表:5
回覆:4
積分:1
註冊:2005-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-07-13 00:10:04 IP:140.121.xxx.xxx 未訂閱
delete pBitmap1; } 有加這行啊!再用一般視訊是可以ㄉ沒問題,但是換成針孔就會出現錯誤!
taishyang
站務副站長


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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-07-13 00:24:52 IP:218.168.xxx.xxx 未訂閱
引言: delete pBitmap1; } 有加這行啊!再用一般視訊是可以ㄉ沒問題,但是換成針孔就會出現錯誤!
只加上那一行是不夠的有一個new就要一個delete,下面是你有new的 但沒有delete
     pBitmap= new Graphics::TBitmap();
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
pBitmap1= new Graphics::TBitmap();
enfin
一般會員


發表:5
回覆:4
積分:1
註冊:2005-07-11

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-07-13 00:49:53 IP:211.22.xxx.xxx 未訂閱
我已經將程式碼改回,結果還是一樣說,下面是改過ㄉcode,可否在幫我看看到底是哪理出錯,感謝!
 
//---------------------------------------------------------------------------    #include 
#include 
#include <math.h>
#pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;    bool entry;
Graphics::TBitmap *pBitmap;
Graphics::TBitmap *pBitmap1;
int ImWidth=320,ImHeight=240,B[240][320],G[240][320],R[240][320];    LRESULT CALLBACK capVideoStreamCallbackProc(HWND hWnd,LPVIDEOHDR lpVHdr)
{       BYTE *ptr;
   int Address;
   if(!entry)
  {
    entry=true;
   for(int i=0;i<240;i  )
    {
      ptr=(BYTE*)pBitmap->ScanLine[239-i];
      for(int j=0;j<320;j  )
      {
       Address=j*3;
       B[i][j]=(int)(lpVHdr->lpData)[3*(i*320 j)];
       G[i][j]=(int)(lpVHdr->lpData)[3*(i*320 j) 1];
       R[i][j]=(int)(lpVHdr->lpData)[3*(i*320 j) 2];
       ptr[Address]=B[i][j];
       ptr[Address 1]=G[i][j];
       ptr[Address 2]=R[i][j];
   }
  }
   entry=false;
  }
   return 0;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   pBitmap= new Graphics::TBitmap();
   pBitmap->Assign(Form1->Image1->Picture);
   ImHeight=pBitmap->Height;
   ImWidth=pBitmap->Width;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::ContactClick(TObject *Sender)
{
   hWndC=capCreateCaptureWindow("Capture Window",WS_CHILD | WS_VISIBLE,40,40,320,240,Handle,0);
   CAPDRIVERCAPS aCAPDRIVERCAPS;
   aCAPDRIVERCAPS.wDeviceIndex=0;
   capDriverConnect(hWndC,aCAPDRIVERCAPS.wDeviceIndex);
   capPreviewRate(hWndC,66);
   capPreview(hWndC,true);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::StartClick(TObject *Sender)
{
 Timer1->Enabled=true;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::SaveImageClick(TObject *Sender)
{
    pBitmap1= new Graphics::TBitmap();
    pBitmap1->Assign(Form1->Image1->Picture);
    pBitmap1->SaveToFile("Image.bmp");
}
//---------------------------------------------------------------------------    void __fastcall TForm1::SourceClick(TObject *Sender)
{
  capDlgVideoSource(hWndC);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::DisconnectClick(TObject *Sender)
{
   capDriverDisconnect(hWndC);
   capPreview(hWndC,false);
   capCaptureStop(hWndC);
   capSetCallbackOnFrame(hWndC,NULL);
   DestroyWindow(hWndC);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
 pBitmap1= new Graphics::TBitmap();
 pBitmap1->Assign(Form1->Image1->Picture);
 BYTE *ptr1;
 int Address;
   for(int y=0;y<240;y  )
    {
      ptr1=(BYTE*)pBitmap1->ScanLine[239-y];
      for(int x=0;x<320;x  )
      {
       Address=x*3;
       ptr1[Address]=B[y][x];
       ptr1[Address 1]=G[y][x];
       ptr1[Address 2]=R[y][x];
      }
    }
  Form1->Image1->Canvas->Draw(0,0,pBitmap1);
  delete pBitmap1;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::StopClick(TObject *Sender)
{
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::CaptureClick(TObject *Sender)
{
   CAPTUREPARMS aCAPTUREPARMS;
   aCAPTUREPARMS.fYield=true;
   aCAPTUREPARMS.fMakeUserHitOKToCapture=true;
   capCaptureSetSetup( hWndC, &aCAPTUREPARMS, sizeof(aCAPTUREPARMS));
   entry=false;
   capSetCallbackOnFrame(hWndC,capVideoStreamCallbackProc);
}
//---------------------------------------------------------------------------    
發表人 - enfin 於 2005/07/13 00:51:22 發表人 - enfin 於 2005/07/13 00:53:10
taishyang
站務副站長


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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-07-13 01:09:37 IP:218.168.xxx.xxx 未訂閱
引言:我已經將程式碼改回,結果還是一樣說,下面是改過ㄉcode,可否在幫我看看到底是哪理出錯,感謝!
您沒有改完壓 >
taishyang
站務副站長


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

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-07-13 01:12:57 IP:218.168.xxx.xxx 未訂閱
引言: 我已經將程式碼改回,結果還是一樣說,下面是改過ㄉcode,可否在幫我看看到底是哪理出錯,感謝!
 
//---------------------------------------------------------------------------    #include 
#include 
#include <math.h>
#pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;    bool entry;
Graphics::TBitmap *pBitmap;
Graphics::TBitmap *pBitmap1;
int ImWidth=320,ImHeight=240,B[240][320],G[240][320],R[240][320];    LRESULT CALLBACK capVideoStreamCallbackProc(HWND hWnd,LPVIDEOHDR lpVHdr)
{       BYTE *ptr;
   int Address;
   if(!entry)
  {
    entry=true;
   for(int i=0;i<240;i  )
    {
      ptr=(BYTE*)pBitmap->ScanLine[239-i];
      for(int j=0;j<320;j  )
      {
       Address=j*3;
       B[i][j]=(int)(lpVHdr->lpData)[3*(i*320 j)];
       G[i][j]=(int)(lpVHdr->lpData)[3*(i*320 j) 1];
       R[i][j]=(int)(lpVHdr->lpData)[3*(i*320 j) 2];
       ptr[Address]=B[i][j];
       ptr[Address 1]=G[i][j];
       ptr[Address 2]=R[i][j];
   }
  }
   entry=false;
  }
   return 0;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   pBitmap= new Graphics::TBitmap(); 這裡有new但沒有delete 
   pBitmap->Assign(Form1->Image1->Picture);
   ImHeight=pBitmap->Height;
   ImWidth=pBitmap->Width;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::ContactClick(TObject *Sender)
{
   hWndC=capCreateCaptureWindow("Capture Window",WS_CHILD | WS_VISIBLE,40,40,320,240,Handle,0);
   CAPDRIVERCAPS aCAPDRIVERCAPS;
   aCAPDRIVERCAPS.wDeviceIndex=0;
   capDriverConnect(hWndC,aCAPDRIVERCAPS.wDeviceIndex);
   capPreviewRate(hWndC,66);
   capPreview(hWndC,true);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::StartClick(TObject *Sender)
{
 Timer1->Enabled=true;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::SaveImageClick(TObject *Sender)
{
    pBitmap1= new Graphics::TBitmap();這裡有new但沒有delete         pBitmap1->Assign(Form1->Image1->Picture);
    pBitmap1->SaveToFile("Image.bmp");
}
//---------------------------------------------------------------------------    void __fastcall TForm1::SourceClick(TObject *Sender)
{
  capDlgVideoSource(hWndC);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::DisconnectClick(TObject *Sender)
{
   capDriverDisconnect(hWndC);
   capPreview(hWndC,false);
   capCaptureStop(hWndC);
   capSetCallbackOnFrame(hWndC,NULL);
   DestroyWindow(hWndC);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
 pBitmap1= new Graphics::TBitmap();
 pBitmap1->Assign(Form1->Image1->Picture);
 BYTE *ptr1;
 int Address;
   for(int y=0;y<240;y  )
    {
      ptr1=(BYTE*)pBitmap1->ScanLine[239-y];
      for(int x=0;x<320;x  )
      {
       Address=x*3;
       ptr1[Address]=B[y][x];
       ptr1[Address 1]=G[y][x];
       ptr1[Address 2]=R[y][x];
      }
    }
  Form1->Image1->Canvas->Draw(0,0,pBitmap1);
  delete pBitmap1;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::StopClick(TObject *Sender)
{
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::CaptureClick(TObject *Sender)
{
   CAPTUREPARMS aCAPTUREPARMS;
   aCAPTUREPARMS.fYield=true;
   aCAPTUREPARMS.fMakeUserHitOKToCapture=true;
   capCaptureSetSetup( hWndC, &aCAPTUREPARMS, sizeof(aCAPTUREPARMS));
   entry=false;
   capSetCallbackOnFrame(hWndC,capVideoStreamCallbackProc);
}
//---------------------------------------------------------------------------    
enfin
一般會員


發表:5
回覆:4
積分:1
註冊:2005-07-11

發送簡訊給我
#9 引用回覆 回覆 發表時間:2005-07-13 15:09:37 IP:140.121.xxx.xxx 未訂閱
我將程式碼改成:  
 
//---------------------------------------------------------------------------    #include 
#include 
#include <math.h>
#pragma hdrstop    #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;    bool entry;
Graphics::TBitmap *pBitmap;
Graphics::TBitmap *pBitmap1;
int ImWidth=320,ImHeight=240,B[240][320],G[240][320],R[240][320];    LRESULT CALLBACK capVideoStreamCallbackProc(HWND hWnd,LPVIDEOHDR lpVHdr)
{       BYTE *ptr;
   int Address;
   if(!entry)
  {
    entry=true;
   for(int i=0;i<240;i++)
    {
      ptr=(BYTE*)pBitmap->ScanLine[239-i];
      for(int j=0;j<320;j++)
      {
       Address=j*3;
       B[i][j]=(int)(lpVHdr->lpData)[3*(i*320+j)];
       G[i][j]=(int)(lpVHdr->lpData)[3*(i*320+j)+1];
       R[i][j]=(int)(lpVHdr->lpData)[3*(i*320+j)+2];
       ptr[Address]=B[i][j];
       ptr[Address+1]=G[i][j];
       ptr[Address+2]=R[i][j];
   }
  }
   entry=false;
  }
   return 0;
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
   pBitmap= new Graphics::TBitmap();
   pBitmap->Assign(Form1->Image1->Picture);
   ImHeight=pBitmap->Height;
   ImWidth=pBitmap->Width;
   delete pBitmap;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::ContactClick(TObject *Sender)
{
   hWndC=capCreateCaptureWindow("Capture Window",WS_CHILD | WS_VISIBLE,40,40,320,240,Handle,0);
   CAPDRIVERCAPS aCAPDRIVERCAPS;
   aCAPDRIVERCAPS.wDeviceIndex=0;
   capDriverConnect(hWndC,aCAPDRIVERCAPS.wDeviceIndex);
   capPreviewRate(hWndC,66);
   capPreview(hWndC,true);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::StartClick(TObject *Sender)
{
 Timer1->Enabled=true;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::SaveImageClick(TObject *Sender)
{
    pBitmap1= new Graphics::TBitmap();
    pBitmap1->Assign(Form1->Image1->Picture);
    pBitmap1->SaveToFile("Image.bmp");
    delete pBitmap1;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::SourceClick(TObject *Sender)
{
  capDlgVideoSource(hWndC);
}
//---------------------------------------------------------------------------    void __fastcall TForm1::DisconnectClick(TObject *Sender)
{
   capDriverDisconnect(hWndC);
   capPreview(hWndC,false);
   capCaptureStop(hWndC);
   capSetCallbackOnFrame(hWndC,NULL);
   DestroyWindow(hWndC);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
 pBitmap1= new Graphics::TBitmap();
 pBitmap1->Assign(Form1->Image1->Picture);
 BYTE *ptr1;
 int Address;
   for(int y=0;y<240;y++)
    {
      ptr1=(BYTE*)pBitmap1->ScanLine[239-y];
      for(int x=0;x<320;x++)
      {
       Address=x*3;
       ptr1[Address]=B[y][x];
       ptr1[Address+1]=G[y][x];
       ptr1[Address+2]=R[y][x];
      }
    }
  Form1->Image1->Canvas->Draw(0,0,pBitmap1);
  delete pBitmap1;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::StopClick(TObject *Sender)
{
Timer1->Enabled=false;
}
//---------------------------------------------------------------------------    void __fastcall TForm1::CaptureClick(TObject *Sender)
{
   CAPTUREPARMS aCAPTUREPARMS;
   aCAPTUREPARMS.fYield=true;
   aCAPTUREPARMS.fMakeUserHitOKToCapture=true;
   capCaptureSetSetup( hWndC, &aCAPTUREPARMS, sizeof(aCAPTUREPARMS));
   entry=false;
   capSetCallbackOnFrame(hWndC,capVideoStreamCallbackProc);
}
//---------------------------------------------------------------------------    
結果當按下capture時,出現另外一種錯誤,如圖下 為什麼會有這種情形發生ㄋ? 感謝! 發表人 - enfin 於 2005/07/13 15:13:02
taishyang
站務副站長


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

發送簡訊給我
#10 引用回覆 回覆 發表時間:2005-07-13 15:48:00 IP:210.68.xxx.xxx 未訂閱
您可以先把程式縮小範圍,看是什麼哪段程式碼所引起的
系統時間:2024-05-08 8:12:34
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!