Algorithme de detection des contours_builder

Fermé
MEY20 Messages postés 6 Date d'inscription dimanche 22 février 2009 Statut Membre Dernière intervention 24 mai 2009 - 24 mai 2009 à 15:41
Bonjour,
j'ai un probleme avec cette fonction en builder C++ qui detecte les contours d'une image.j'ai toujour cette erreur "violation d'accés à l'adresse 00401D35 dans le mmodule 'projet1.exe' ",
je suit depuit hier je cherche pourquoi cette erreur mais sans succé.
je suis debutanta en builder et j'arrive pas à la corriger s'il vous plaiez aidez moi. plaise.
merci d'avance.

int h=Image1->Height;
int w=Image1->Width;
//declaration de la matrice
int **Mat=new int *[h];
for(int i=0;i<h;i++)
Mat[i]= new int [w];

//conversion de l'image ->matrice
for (int i=0;i<h;i++)
for(int y=0;y<w;y++ )
Mat[i][y]=Image1->Canvas->Pixels[y][i]&0xff;



// traitement

int pw, W, i1,j1,ibeg, jbeg, id ,jd,k1,k2,k,n,m,lm_entrer; int lx[10]; int ly[10];

for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
{
if(Mat[i][j]<128)
Mat[i][j]=1;
else
Mat[i][j]=0;
}

pw=1;
W=0; //nbre de contours exist dans l'image

for(int i=1;i<h-1;i++)
{
e6:
for(int j=1;j<w-1;j++)
{

if(Mat[i][j-1]==0 && Mat[i][j]==1)
{

pw=1;
i1=i;
j1=j;
ibeg=i1;
jbeg=j1;
id=i1;
jd=j1-1;
e4:
k1=jd-j1;
k2=id-i1;
lx[1]=id;
lx[2]=lx[1]+k1;
lx[3]=lx[2]-k2;
lx[4]=lx[3]-k2;
lx[5]=lx[4]-k1;
lx[6]=lx[5]-k1;
lx[7]=lx[6]+k2;
lx[8]=lx[7]+k2;
ly[1]=jd;
ly[2]=ly[1]-k2;
ly[3]=ly[2]-k1;
ly[4]=ly[3]-k1;
ly[5]=ly[4]+k2;
ly[6]=ly[5]+k2;
ly[7]=ly[6]+k1;
ly[8]=ly[7]+k1;
for(k=2;k<=8;k++)
{ n=lx[k];
m=ly[k];
if(Mat[n][m]==1)
{
Mat[n][m]=2;
pw=pw+1;

i1=lx[k];
j1=ly[k];
id=lx[k-1];
jd=ly[k-1];
if(i1==ibeg && j1==jbeg)
{
Mat[i1][j1]=2;
/*pw=pw+1;*/
// w=w+1;

goto e6;
}
else
goto e4;
}
}
}


}

}

//e5:

for(int i=0;i<h;i++)
for(int j=0;j<W;j++)
{
if(Mat[i][j]!=2)
Mat[i][j]=0;
else
Mat[i][j]=1;
}
Edit1->Text=IntToStr(w);


//conversion de la matrice en une image

for (int i=0;i<h;i++)
for (int j=0; j<w;j++)
Image1->Canvas->Pixels[j][i]=(TColor)RGB(Mat[i][j],
Mat[i][j],Mat[i][j]);

//Liberation de la matrice
for (int i=0;i<h;i++)
delete []Mat[i];
delete []Mat;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{ int i,j,y;
int h=Image1->Height;
int w=Image1->Width;
//declaration de la matrice
int **Mat=new int *[h];
for( i=0;i<h;i++)
Mat[i]= new int [w];


//conversion
for ( i=0;i<h;i++)
for( y=0;y<w;y++ )
Mat[i][y]=Image1->Canvas->Pixels[y][i]&0xff;



for(int i=0;i<h;i++)
for(int j=0;j<w;j++)
{
if(Mat[i][j]<128)
Mat[i][j]=1;
else
Mat[i][j]=0;
}

}