1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| void Analyse::RemoveObjectEdges(){
CvScalar scalaire, scalaire2;
CvPoint point;
point.x=0; point.y=0;
IplImage *marqueur;
marqueur = cvCreateImage(cvGetSize(m_IplImage), m_IplImage->depth, m_IplImage->nChannels);
IplImage *taff;
//Création du masque
for (int y=0; y<m_IplImage->height; y++){
for (int x=0; x< m_IplImage->width; x++){
if ((x == 0) || (y == 0) || y==(m_IplImage->height-1) || x==(m_IplImage->width-1)) {
scalaire.val[0]=255;
cvSet2D(marqueur, y, x, scalaire );
}
else{
scalaire.val[0]=0;
cvSet2D(marqueur, y, x, scalaire);
}
}
}
//Ou logique entre marquer et m_IplImage et marqueur, le tout stocké dans m_EnTrait.
cvOr( m_IplImage, marqueur, m_EnTrait);
//On copie le résultat dans taff:
taff = cvCloneImage(m_EnTrait);
//Propagation du maximum:
bool modif = false;
do{
int m;
int tab[4];
CvScalar scal1, scal2, scal3, scal4;
modif = false;
for (int y=1; y<(m_IplImage->height-1); y++){
for (int x=1; x<(m_IplImage->width-2); x++){
scalaire2 = cvGet2D (taff, y, x);
scal1 = cvGet2D(taff, y, (x-1));
scal2 = cvGet2D(taff, (y-1), (x-1) );
scal3 = cvGet2D(taff, (y-1), x);
scal4 = cvGet2D(taff, (y-1), (x+1));
tab[0] = scal1.val[0]; tab[1] = scal2.val[0]; tab[2] = scal3.val[0]; tab[3] = scal4.val[0];
if (scalaire2.val[0] == 0){
m = ValMax(tab, 4);
if (scalaire2.val[0] < m){
scalaire2.val[0]=m;
cvSet2D(taff, y, x, scalaire2);
modif = true;
}
}
}
}
for (int y=((m_IplImage->height)-2); y>0; y--){
for (int x=((m_IplImage->width)-2); x>0; x--){
scalaire2 = cvGet2D(taff, y, x);
scal1 = cvGet2D(taff, y, (x+1));
scal2 = cvGet2D(taff, (y+1), (x-1) );
scal3 = cvGet2D(taff, (y+1), x);
scal4 = cvGet2D(taff, (y+1), (x+1));
tab[0] = scal1.val[0]; tab[1] = scal2.val[0]; tab[2] = scal3.val[0]; tab[3] = scal4.val[0];
if (scalaire2.val[0] == 0){
m = ValMax(tab, 4);
if (scalaire2.val[0] < m){
scalaire2.val[0]=m;
cvSet2D(taff, y, x, scalaire2);
modif = true;
}
}
}
}
}while (modif == true);
cvSub(m_IplImage, taff, m_EnTrait);
IplImage2Qimage();
} |
Partager