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

關於Access Violation 的問題解決方法

答題得分者是:jow
timspc
一般會員


發表:3
回覆:3
積分:6
註冊:2007-08-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-10-08 00:29:10 IP:140.113.xxx.xxx 訂閱
我的問題是有關於Access Violation 的問題。
有爬過文我有將每一個變數名稱都更改,但是我不知道遇到的問題是哪裡。

問題的視窗: Project E:\iris localization\Project1.exe faulted with message: 'access violation at 0x7c957a50: write of address 0x00030fb0'. Process Stopped . Use Step or Run to continue.
可以請各位大大提供方法檢測嗎?
因為對於bcb是初學,之前有爬文說用在" IDE 內設 Debug 模式 rebuild 後, 再執行",不懂何謂IDE。
可以請一些有經驗的人幫我看看嗎。
程式我有用註解,應該是不難了解再做甚麼事情。

程式是做虹膜處理,puil是指瞳孔,註解中有寫circle是指瞳孔。
[code cpp]
void __fastcall TForm1::FindCenterOfThePupilClick(TObject *Sender)
{if(!image_old->Picture->Bitmap->Empty)
{
Graphics::TBitmap *TheOldBitmap;
TheOldBitmap=image_old->Picture->Bitmap;
TheOldBitmap->PixelFormat=pf8bit;

int height_old,width_old,Xp,Yp,Threshold_pupil,Threshold_Edge;
height_old=TheOldBitmap->Height;
width_old=TheOldBitmap->Width;

int count;
//binary image------------------------------------------------------------------
Graphics::TBitmap *TheNewBitmap;
Byte *binary_image,*binary_image_2;
TheNewBitmap=new Graphics::TBitmap();
TheNewBitmap->PixelFormat=pf8bit;
TheNewBitmap->Width=TheOldBitmap->Width;
TheNewBitmap->Height=TheOldBitmap->Height;

Threshold_pupil=ThresholdSB1->Position;
Label4->Caption=Threshold_pupil;
for(int y=0;y {
binary_image=(Byte*) TheOldBitmap->ScanLine[y];
binary_image_2=(Byte*) TheNewBitmap->ScanLine[y];
for(int x=0;x {
if(binary_image[x]<=Threshold_pupil)binary_image_2[x]=0;
else if(binary_image[x]>Threshold_pupil)binary_image_2[x]=255;
}
}
//------------------------------------------------------------------------------

//project image_old in the vertical detection----------------------------------
Byte *project;
int refX,refY;
for(int y=0;y {project=(Byte*) TheNewBitmap->ScanLine[y];
count=0;
for(int x=0;x
switch(y)
{case 0:
refY=count;Yp=y; break;
default:
if(refY>count)
{refY=count;Yp=y;} break;}
}

//project image_old in the horizontal detection
for(int x=0;x { count=0;
for(int y=0;y {project=(Byte*) TheNewBitmap->ScanLine[y];
count =project[x];}

switch(x)
{case 0:
refX=count;Xp=x; break;
default:
if(refX>count)
{refX=count;Xp=x;} break; }
}
//------------------------------------------------------------------------------

//binarize a 121*121 region centered at the point (Xp,Yp)-----------------------
TRect OldimageRect,NewimageRect;
Graphics::TBitmap *TheNewPartBitmap;
TheNewPartBitmap=new Graphics::TBitmap();
TheNewPartBitmap->PixelFormat=pf8bit;
TheNewPartBitmap->Width=201;
TheNewPartBitmap->Height=201;

TheNewPartBitmap->Canvas->CopyMode=cmSrcCopy;
OldimageRect=Rect(Xp-100,Yp-100,Xp 100,Yp 100);
NewimageRect=Rect(0,0,201,201);
TheNewPartBitmap->Canvas->CopyRect(NewimageRect,TheNewBitmap->Canvas,OldimageRect);

image_new->Picture->Bitmap->Assign(TheNewPartBitmap);
delete TheNewBitmap;
//------------------------------------------------------------------------------


//find circle edge--------------------------------------------------------------
Byte *Old,*Up,*Down,*New;
int up,left,right,down;
Graphics::TBitmap *The_NewBitmap;
The_NewBitmap=new Graphics::TBitmap();
The_NewBitmap->Assign(TheNewPartBitmap);
Threshold_Edge=ThresholdEdge->Position;
Label6->Caption=Threshold_Edge;
for(int y=0;yHeight;y )
{Old=(Byte *)TheNewPartBitmap->ScanLine[y];
New=(Byte *)The_NewBitmap->ScanLine[y];
for(int x=0;xWidth;x )
{count=0;
if(y==0)up=0;
else {Up=(Byte *) TheNewPartBitmap->ScanLine[y-1];up=Up[x]-Old[x];}
up=(up>0)?0:abs(up);count =up;
if(y==TheNewPartBitmap->Height-1)down=0;
else {Down=(Byte *) TheNewPartBitmap->ScanLine[y 1];down=Down[x]-Old[x];}
down=(down>0)?0:abs(down);count =down;
if(x==0)left=0;
else {left=Old[x-1]-Old[x];}
left=(left>0)?0:abs(left);count =left;
if(x==TheNewPartBitmap->Width-1)right=0;
else {right=Old[x 1]-Old[x];}
right=(right>0)?0:abs(right);count =right;
count/=10;
if(count>Threshold_Edge)New[x]=0;
else New[x]=255;
}
}
Edgeimage->Picture->Bitmap->Assign(The_NewBitmap);
delete TheNewPartBitmap;
//------------------------------------------------------------------------------

//find the R center of the puil-------------------------------------------------
int R_distance;
int ***CircleParameter;
CircleParameter=new int**[21];
for(int x=0;x<21;x )CircleParameter[x]=new int*[21];
for(int x=0;x<21;x )for(int y=0;y<21;y )CircleParameter[x][y]=new int[300];
for(int x=0;x<21;x )
for(int y=0;y<21;y )
for(int z=0;z<300;z )CircleParameter[x][y][z]=0;
Byte *temp_image;
for(int y=0;y<201;y )
{temp_image=(Byte*) The_NewBitmap->ScanLine[y];
for(int x=0;x<201;x )
{ if(temp_image[x]>0)
{ for(int w=Xp-10;w for(int h=Yp-10;h {R_distance=(int) sqrt(abs(x-w)*abs(x-w) abs(y-h)*abs(y-h));
CircleParameter[w-Xp 10][h-Yp 10][R_distance] =1;}
}
}
}
count=0;
for(int x=0;x<21;x )
for(int y=0;y<21;y )
for(int z=0;z<300;z )
if(CircleParameter[x][y][z]>count)
{
count=CircleParameter[x][y][z];
R_distance=z 1;
Xp=x-10 101;
Yp=y-10 101;
}
for(int x=0;x<21;x )for(int y=0;y<21;y )delete[] CircleParameter[x][y];
for(int x=0;x<21;x )delete[] CircleParameter[x];
delete[] CircleParameter;

StatusBar1->Panels->Items[0]->Text="first Xp=" IntToStr(Xp);
StatusBar1->Panels->Items[1]->Text="first Yp=" IntToStr(Yp);
StatusBar1->Panels->Items[2]->Text="Radius R=" IntToStr(R_distance);
}
else
{WaringDlg->ShowModal();}
}

[/code]
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-10-08 09:31:51 IP:210.66.xxx.xxx 訂閱
已知固定大小的Buffer, 直接宣告成靜態陣列就好了,甚或如果
使用率很高就應該宣告在Class內,以免每次進入函式還要重新
配置.


NOTE: IDE 是指目前使用的整合開發環境.

以下建議僅供參考.

[code cpp]
//find the R center of the puil-------------------------------------------------
int R_distance;

////// int ***CircleParameter;
int CircleParameter[21][21][300];
memset(CircleParameter,0,sizeof(CircleParameter));

/*以下刪除////////////////////////////////////////////////
CircleParameter=new int**[21];
for(int x=0;x<21;x )CircleParameter[x]=new int*[21];
for(int x=0;x<21;x )for(int y=0;y<21;y )CircleParameter[x][y]=new int[300];
for(int x=0;x<21;x )
for(int y=0;y<21;y )
for(int z=0;z<300;z )CircleParameter[x][y][z]=0;
以上刪除//////////////////////////////////////////////////////////////////////////////
/
*/

Byte *temp_image;
for(int y=0;y<201;y )
{temp_image=(Byte*) The_NewBitmap->ScanLine[y];
for(int x=0;x<201;x )
{ if(temp_image[x]>0)
{ for(int w=Xp-10;w for(int h=Yp-10;h {R_distance=(int) sqrt(abs(x-w)*abs(x-w) abs(y-h)*abs(y-h));
CircleParameter[w-Xp 10][h-Yp 10][R_distance] =1;}
}
}
}

count=0;
for(int x=0;x<21;x )
for(int y=0;y<21;y )
for(int z=0;z<300;z )
if(CircleParameter[x][y][z]>count)
{
count=CircleParameter[x][y][z];
R_distance=z 1;
Xp=x-10 101;
Yp=y-10 101;
}

/*以下刪除////////////////////////////////////////////////////////////
//你可以就原來程式自行Debug.
for(int x=0;x<21;x )for(int y=0;y<21;y )delete[] CircleParameter[x][y];<--原本狀況發生在這裡,
for(int x=0;x<21;x )delete[] CircleParameter[x];
delete[] CircleParameter;
以上刪除////////////////////////////////////////////////////////////
*/

StatusBar1->Panels->Items[0]->Text="first Xp=" IntToStr(Xp);
StatusBar1->Panels->Items[1]->Text="first Yp=" IntToStr(Yp);
StatusBar1->Panels->Items[2]->Text="Radius R=" IntToStr(R_distance);
}
else {WaringDlg->ShowModal();}

}
[/code]
編輯記錄
jow 重新編輯於 2007-10-08 09:33:06, 註解 無‧
系統時間:2024-04-18 18:31:38
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!