大家好, 想向大家請教
我之前在做連續影像相減可是讓前後兩張的影像丟到不同buffer的問題一直無法解決, 所以我想先拍下一張影像存檔, 然後再將連續影像都對拍下來的那一張做相減再show出來, 我想先試試這個再回去做連續影像相減, 可是我要執行時出現了 "Debugger Exception Notification" 這個視窗, 上面寫著 "Project Project1.exe raised exception class EAccess Violation with message 'Access violation at address 00401F30 in module 'Project1.exe'. Write of address 00000000'. Process stopped Use Step or Run to continue." 我不知道是哪裡出了問題, 以下是我的程式
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h" #include
#include <math.h>
#include
#include
#include #define col 320
#define row 240 unsigned char *image;
unsigned char *gray1;
unsigned char *gray2;
unsigned char *subtraction; //---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "EzCapCamera"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender)
{
EzCapCamera1->CameraDisplay(); //開啟攝影機功能 if (!(image=new unsigned char [3*240*320 1])||
!(gray1=new unsigned char [240*320 1])||
!(gray2=new unsigned char [240*320 1])||
!(subtraction=new unsigned char [240*320 1])
)
{}
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender)
{
EzCapCamera1->CapBmpPic("1.bmp"); //儲存圖檔 FILE *fin;
int buff1=0;
int i; if((fin=fopen("1.bmp","rb"))== NULL)
{}
fread(image,240*320,3,fin);
fclose(fin); buff1=0;
for(i=0;i<3*240*320;i=i 3)
{
gray1[buff1]=0.299*image[i 2] 0.587*image[i 1] 0.114*image[i];
buff1 ;
} }
//--------------------------------------------------------------------------- void __fastcall TForm1::Button3Click(TObject *Sender)
{
delete [] image;
delete [] gray1;
delete [] gray2;
delete [] subtraction; EzCapCamera1->CameraClose(); //關閉攝影機功能
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
EzCapCamera1->CapBmpPic("2.bmp"); //儲存圖檔
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
Image1->Picture->LoadFromFile("2.bmp"); //載入圖檔
if (Image1->Picture->Bitmap->Empty==true)
{
ShowMessage("請載入圖檔!!");
}
Graphics::TBitmap *Bmp = new Graphics::TBitmap();
Byte *ptr;
int Width,Height,r,g,b;
int i,j;
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];
gray2[j*col i]=0.299*r 0.587*g 0.114*b;
}
}
for(i=0;i=70)
subtraction[i]=0;
else
subtraction[i]=255;
} for(j=0;jHeight;j )
{
ptr = (Byte *)Bmp->ScanLine[j];
for(i=0;iWidth;i )
{
ptr[i*3]=subtraction[j*col i];
ptr[i*3 1]=subtraction[j*col i];
ptr[i*3 2]=subtraction[j*col i];
}
} Image2->Picture->Assign(Bmp); }
//---------------------------------------------------------------------------
麻煩請大家幫我看看, 謝謝大家