enfin
一般會員
發表:5 回覆:4 積分:1 註冊:2005-07-11
發送簡訊給我
|
請問做影像處理用一般的視訊與無線針孔攝影機有什麼差別ㄋ?我目前遇到的問題是用之前學長給的程式做影像處理,如果是用一般視訊都很正常,但是用無線針孔攝影機時,一開始按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
發送簡訊給我
|
我想問的是為什麼會有這種情形發生ㄋ?程式碼哪裡需要改ㄉㄋ?還是系統ㄉ問題ㄋ?想請教各位高手,感謝ㄌ!
|
taishyang
站務副站長
發表:377 回覆:5490 積分:4563 註冊:2002-10-08
發送簡訊給我
|
您好: 您的問題可能是有new但沒有delete所造成的 <> >
>
|
enfin
一般會員
發表:5 回覆:4 積分:1 註冊:2005-07-11
發送簡訊給我
|
delete pBitmap1; } 有加這行啊!再用一般視訊是可以ㄉ沒問題,但是換成針孔就會出現錯誤!
|
taishyang
站務副站長
發表:377 回覆:5490 積分:4563 註冊:2002-10-08
發送簡訊給我
|
引言:
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
發送簡訊給我
|
我已經將程式碼改回,結果還是一樣說,下面是改過ㄉ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
發送簡訊給我
|
引言:我已經將程式碼改回,結果還是一樣說,下面是改過ㄉcode,可否在幫我看看到底是哪理出錯,感謝! 您沒有改完壓 >
|
taishyang
站務副站長
發表:377 回覆:5490 積分:4563 註冊:2002-10-08
發送簡訊給我
|
引言:
我已經將程式碼改回,結果還是一樣說,下面是改過ㄉ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
發送簡訊給我
|
我將程式碼改成:
//--------------------------------------------------------------------------- #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
發送簡訊給我
|
您可以先把程式縮小範圍,看是什麼哪段程式碼所引起的
|