//--------------------------------------------------------------------------- #include #pragma hdrstop //--------------------------------------------------------------------------- #pragma argsused void FullCapture(unsigned char Tabx[4][20],unsigned char Taby[4][15]) { Tabx[0][8]=0xFE; Taby[0][10]=0xFF; } void WndCapture(unsigned char Tab[2],unsigned char Tabx[4][20],unsigned char Taby[4][15]) { } //fonction de recadrage des coordonnées //x et y sont les coordonnée du centre de la zone, *D détermine la taille //de cette zone et Px et Py la position du marqueur dans cette zone void Recadrage(short int *Px,short int *Py,short int x,short int y, unsigned char wnd_Decal) { if (x<((320>>wnd_Decal)>>1)) { *Px=*Px-((320>>wnd_Decal)>>1)-x; } else *Px=x-((320>>wnd_Decal)>>1)+*Px; if (y<(240>>wnd_Decal)>>1) { *Py=*Py-((240>>wnd_Decal)>>1)-y; } else *Py=y-((240>>wnd_Decal)>>1)+*Py; } //Fonction de traitement de reconnaissance du marqueur sur une zone de 320>>*D par //240>>*D, Px et Py détermine les valeurs du centre de la zone ou de la balle //que l'on veut retrouver. //*D détermine les dimensions de la zone. //Tabx et Taby donne les profils des zones étudiers de centre (*Px,*Py) //n permet de déterminer la ligne de lecture (0 pour tout les cas sauf le full) //A,b,c,d représente les limitesdu tableau. void ProcProto(unsigned char Tabx[4][20],unsigned char Taby[4][15],unsigned char *wnd_Decal,short int *xAbs,short int *yAbs,short int n) { //variable pour les boucles unsigned char i;//TabX unsigned char j;//parcours octet TabX unsigned char k;//TabY unsigned char l;//parcours octet TabY //variable de validation: unsigned char Valid=0; //variable de comptage unsigned char NbPixX=0; unsigned char NbPixY=0; unsigned char ValX=0; unsigned char ValY=0; //variable zone: unsigned char NbPixZoneX=0; unsigned char NbPixZoneY=0; //Structure Champ de bite: compacte et rapide d'accès struct Test { unsigned char bit0:1; unsigned char bit1:1; unsigned char bit2:1; unsigned char bit3:1; unsigned char bit4:1; unsigned char bit5:1; unsigned char bit6:1; unsigned char bit7:1; }c; //Nouvelle version traitement image: Tableau de char (1 octet=8 pixels) unsigned short ConcatCharX,ConcatCharY; //Etude sur TabX donc sur la zone X du prototype Image for (i=0; i <((320>>*wnd_Decal)>>3); i++) { //concaténation dans une variable d'étude des 2 char nécéssaire au traitement ConcatCharX=0x0000000000000000; ConcatCharX=((Tabx[n][i-1])<<7) | Tabx[n][i]; //parcours de l'octet: for (j=0; j < 8; j++) { //remplissage conditions structure: c.bit0=ConcatCharX>>(7-j) & 0x0000000000000001;//bit 1 du pixel c.bit1=ConcatCharX>>(8-j) & 0x0000000000000001;//bit pixel-1 c.bit2=ConcatCharX>>(11-j) & 0x0000000000000001;//bit pixel-4 //Parcours Tabx if (c.bit0) { if (c.bit1) { NbPixX+=1; } //mise en place des regroupements de pixels else if (!c.bit1 && c.bit2) { NbPixX+=4; } else { NbPixX=1; } } if ((!c.bit0 && c.bit1) || (i==((320>>*wnd_Decal)>>3)-1) && c.bit0) { //condition de validation pour parcourir tabY if (NbPixX>=6 && NbPixX<=15) { ValX=(i*8+j)-(NbPixX>>1); //parcours de TabY for (k=0; k <((240>>*wnd_Decal)>>3); k++) { ConcatCharY=0x0000000000000000; ConcatCharY=Taby[n][k-1]<<8 | Taby[n][k]; //parcours de TabY octet for (l=0; l < 8; l++) { c.bit3=ConcatCharY>>(7-l) & 0x0000000000000001;//bit 1 du pixel c.bit4=ConcatCharY>>(8-l) & 0x0000000000000001;//bit pixel-1 c.bit5=ConcatCharY>>(11-l) & 0x0000000000000001;//bit pixel-4 if (c.bit3) { if (c.bit4) { NbPixY+=1; } //mise en place des regroupements de pixels else if (!c.bit3 && c.bit5) { NbPixY+=4; } else { NbPixY=1; } } if((!c.bit3 && c.bit4) || (k==((240>>*wnd_Decal)>>3)-1) && c.bit3) { if (NbPixY>=6 && NbPixY<=15) { ValY=(k*8+l)-(NbPixY>>1); Valid=1; i=20; j=8; k=15; l=8; } else if(NbPixY>15 && NbPixY>NbPixZoneY) { //traitement zone en Y NbPixZoneY=NbPixY; ValY=(k*8+l)-(NbPixZoneY>>1); } } } } } //zone en X if (NbPixX>15 && NbPixX>NbPixZoneX) { for (k=1; k < ((240>>*wnd_Decal)>>3); k++) { ConcatCharY=Taby[n][k-1]<<8 | Taby[n][k]; //parcours de TabY octet for (l=0; l < 8; l++) { c.bit3=ConcatCharY>>(7-l) & 0x0000000000000001;//bit 1 du pixel c.bit4=ConcatCharY>>(8-l) & 0x0000000000000001;//bit pixel-1 c.bit5=ConcatCharY>>(11-l) & 0x0000000000000001;//bit pixel-4 if (c.bit3) { if (c.bit4) { NbPixY+=1; } //mise en place des regroupements de pixels else if (!c.bit4 && c.bit5) { NbPixY+=4; } else { NbPixY=1; } } if((!c.bit3 && c.bit4) || (k==((240>>*wnd_Decal)>>3)-1)&& c.bit3) { if (NbPixY>=6 && NbPixY<=15) { ValY=(k*8+l)-(NbPixY>>1); ValX=(i*8+j)-(NbPixX>>1); } } } } } } } } *xAbs=ValX; *yAbs=ValY; *wnd_Decal=Valid; //REMARQUE : Le test de validité de présence ou non se fait sur Y non sur X //en effet si Y possède une valeur alors X en possède une aussi et donc il y a présence //si Y est une zone X ne peu etre qu'un point et non nul //si Y est un point alors X est automatiquement non nul et soit une zone soit un point //si Y est nul alors X est une zone et un point Y n'a pu etre trouver } //Fonction principale de démarage de l'application ou en cas de perte de marqueur //on passe en paramêtre les 2 tableaux et les 2 coordonnées précédente du marqueur void Absolut(unsigned char Tabx[4][20],unsigned char Taby[4][15],short int *px,short int *py,unsigned char *wnd_Decal) { unsigned char i=0; //APPEL A LA FONCTION DE CAPTURE DE LA ZONE IMAGE FullCapture(&Tabx,&Taby); //coordonnée du centre de la zone while (*py==0 || i<4) { *wnd_Decal=1; ProcProto(&Tabx,&Taby,px,py,&wnd_Decal,i); i++; } if (!*py) { switch (i) { case 1: Recadrage(px,&py,200,60,1); break; case 2: Recadrage(px,py,80,180,1); break; case 3: Recadrage(px,py,200,180,1); break; } } } //Fonction principale de suivit du marqueur, 3 fonctions : fine,midel1 et midel2 void Relatif(unsigned char Tabx[4][20],unsigned char Taby[4][15],short int *xAbs,short int *yAbs,unsigned char *wnd_Decal) { //save du centre de la zone short int OldMarkX=*xAbs; short int OldMarkY=*yAbs; unsigned char DecalageOld=*wnd_Decal; //détermination des bords du tableau: istart et istop,jstart et jstop unsigned char iStart=0,jStart=0; unsigned char wnd_height; unsigned char TabWnd[2]; wnd_height=320>>*wnd_Decal; iStart=OldMarkX-(wnd_height)>>1; if (iStart<0) iStart=0; if (iStart>(320-((wnd_height)>>1))) iStart=320-((wnd_height)>>1); wnd_height=240>>*wnd_Decal; jStart=OldMarkY-(wnd_height)>>1; if (jStart<0) jStart=0; if (jStart>(240-((wnd_height)>>1))) jStart=(240-((wnd_height)>>1)); TabWnd[1]=jStart; TabWnd[2]=*wnd_Decal; //APPEL A LA FONCTION DE CAPTURE DE LA ZONE IMAGE if ((iStart-((iStart>>3)<<3))<5) { TabWnd[0]=(iStart)>>3; WndCapture(&TabWnd,&Tabx,&Taby); } else { TabWnd[0]=((iStart)>>3)+1; WndCapture(&TabWnd,&Tabx,&Taby); } ProcProto(&Tabx,&Taby,&wnd_Decal,&xAbs,&yAbs,0); Recadrage(&xAbs,&yAbs,OldMarkX,OldMarkY,DecalageOld); } void Traitement(unsigned char Tabx[4][20],unsigned char Taby[4][15], short int *px,short int *py,unsigned char *wnd_Decal) { unsigned char Num_Fonct=0; int i=0; while (i==0) { switch (Num_Fonct) { case 0: *wnd_Decal=1; Absolut(&Tabx,&Taby,px,py,&wnd_Decal); if (*py>0 && !wnd_Decal) Num_Fonct=2; else if (*py>0 && wnd_Decal) Num_Fonct=3; else Num_Fonct=0; break; case 1: *wnd_Decal=1; Relatif(&Tabx,&Taby,px,py,&wnd_Decal); if (!*py && !wnd_Decal) Num_Fonct=0; else Num_Fonct=3; break; case 2: *wnd_Decal=2; Relatif(&Tabx,&Taby,px,py,&wnd_Decal); if (!*py && !wnd_Decal) Num_Fonct=0; else Num_Fonct=3; break; case 3: *wnd_Decal=3; Relatif(&Tabx,&Taby,px,py,&wnd_Decal); if (!*py ) Num_Fonct=1; else Num_Fonct=3; break; default: Num_Fonct=0; } //On récupère les valeur de X et Y qui sont xAbs et yAbs:test printf(%i,*px); printf(%i,*py); //de toute facon sa arrive pas jusque la^^ i++; } } int main(int argc, char* argv[]) { unsigned char wnd_Decal; short int xAbs,yAbs; short int *px,*py; unsigned char TabX[4][20],TabY[4][15]; px=&xAbs; py=&yAbs; Traitement(&TabX,&TabY,px,py,&wnd_Decal); return 0; } //---------------------------------------------------------------------------