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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
|
//---------------------------------------------------------------------------
#include <stdio.h>
//---------------------------------------------------------------------------
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])
{
(void) Tab;
(void) Tabx;
(void) Taby;
}
//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;
}
}
/* -ed- ambigu, non corrige */
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;
}
}
/* -ed- ambigu, non corrige */
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;
}
}
/* -ed- ambigu, non corrige */
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, wnd_Decal, px, py, 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;
/* -ed- ambigu */
iStart = OldMarkX - (wnd_height) >> 1;
/* -ed- inutile */
if (iStart < 0)
iStart = 0;
if (iStart > (320 - ((wnd_height) >> 1)))
iStart = 320 - ((wnd_height) >> 1);
wnd_height = 240 >> *wnd_Decal;
/* -ed- ambigu */
jStart = OldMarkY - (wnd_height) >> 1;
/* -ed- inutile */
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 (void)
{
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;
}
//--------------------------------------------------------------------------- |
Partager