Changeset 7790 for trunk/MagicSoft/Cosy/videodev/FilterLed.cc
- Timestamp:
- 07/14/06 13:19:54 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Cosy/videodev/FilterLed.cc
r7788 r7790 45 45 } 46 46 47 void FilterLed::DrawHexagon(float cx, float cy, float r, byte col) const 48 { 49 MGMap::DrawHexagon(fImg, 768, 576, cx, cy, r, col); 50 } 51 47 52 void FilterLed::DrawCircle(const Ring &l, byte col) const 48 53 { … … 53 58 { 54 59 DrawCircle(l.GetX(), l.GetY(), r, col); 60 } 61 62 void FilterLed::DrawHexagon(const Ring &l, double r, byte col) const 63 { 64 DrawHexagon(l.GetX(), l.GetY(), r, col); 55 65 } 56 66 … … 121 131 } 122 132 123 int FilterLed::GetMeanPosition Circle(const int x, const int y,124 const int box, float &mx, 125 133 int FilterLed::GetMeanPositionBox(const int x, const int y, 134 const int box, float &mx, 135 float &my, unsigned int &sum) const 126 136 { 127 137 //------------------------------- … … 188 198 } 189 199 190 int FilterLed::GetMeanPosition Circle(const int x, const int y,191 200 int FilterLed::GetMeanPositionBox(const int x, const int y, 201 const int box) const 192 202 { 193 203 float mx, my; 194 204 unsigned int sum; 195 return GetMeanPosition Circle(x, y, box, mx, my, sum);205 return GetMeanPositionBox(x, y, box, mx, my, sum); 196 206 } 197 207 … … 334 344 } 335 345 346 class ClusterFinder 347 { 348 private: 349 byte *fImg; 350 351 UInt_t fW; 352 UInt_t fH; 353 354 Int_t fX0; 355 Int_t fX1; 356 357 Int_t fY0; 358 Int_t fY1; 359 360 UInt_t fCount; 361 Float_t fSumX; 362 Float_t fSumY; 363 364 Float_t FindCluster(Int_t x, Int_t y) 365 { 366 // if edge is touched stop finding cluster 367 if (x<fX0 || x>=fX1 || y<fY0 || y>=fY1) 368 return -1; 369 370 if (fCount>999) 371 return -1; 372 373 // get the value 374 Float_t val = fImg[y*fW+x]; 375 376 // if its empty we have found the border of the cluster 377 if (val==0) 378 return 0; 379 380 // mark the point as processed 381 fImg[y*fW+x] = 0; 382 383 fSumX += x*val; // sumx 384 fSumY += y*val; // sumy 385 fCount++; 386 387 Float_t rc[4]; 388 rc[0] = FindCluster(x+1, y ); 389 rc[1] = FindCluster(x, y+1); 390 rc[2] = FindCluster(x-1, y ); 391 rc[3] = FindCluster(x, y-1); 392 393 for (int i=0; i<4; i++) 394 { 395 if (rc[i]<0) // check if edge is touched 396 return -1; 397 398 val += rc[i]; 399 } 400 401 return val; 402 } 403 public: 404 ClusterFinder(byte *img, UInt_t w, UInt_t h) 405 { 406 fW = w; 407 fH = h; 408 409 fImg = new byte[fW*fH]; 410 411 memcpy(fImg, img, fW*fH); 412 } 413 414 ~ClusterFinder() 415 { 416 delete fImg; 417 } 418 void FindCluster(Leds &leds, Int_t x0=0, Int_t y0=0, Int_t x1=0, Int_t y1=0) 419 { 420 fX0 = x0; 421 fY0 = y0; 422 fX1 = x1==0?fW:x1; 423 fY1 = y1==0?fH:y1; 424 425 for (Int_t x=fX0; x<fX1; x++) 426 for (Int_t y=fY0; y<fY1; y++) 427 { 428 const byte &b = fImg[y*fW+x]; 429 if (b==0) 430 continue; 431 432 fCount = 0; 433 fSumX = 0; 434 fSumY = 0; 435 436 const Float_t mag = FindCluster(x, y); 437 if (fCount>999) 438 { 439 cout << "ERROR - Spot with Size>999 detected..." << endl; 440 return; 441 } 442 443 if (mag>0 && fCount>6) 444 { 445 Float_t M = mag/0xff; 446 if (M>0xf0) 447 M=0xf0; 448 449 leds.Add(fSumX/mag, fSumY/mag, 0, 0, 0xf0); 450 } 451 } 452 leds.Compress(); 453 } 454 }; 336 455 337 456 void FilterLed::Execute(Leds &leds, int xc, int yc, double &bright) const … … 353 472 byte &b = fImg[y*fW+x]; 354 473 474 // Skip saturating pixels 475 if (b>0xf0) 476 continue; 477 478 sum += b; 479 sq += b*b; 480 } 481 482 sum /= wx*hy; 483 sq /= wx*hy; 484 485 bright=sum; 486 487 488 // 254 because b<=max and not b<max 489 const double sdev = TMath::Sqrt(sq-sum*sum); 490 const byte max = sum+fCut*sdev>254 ? 254 : (byte)(sum+fCut*sdev); 491 492 // 493 // clean image from noise 494 // (FIXME: A lookup table could accelerate things... 495 // 496 for (int x=x0; x<x1; x++) 497 for (int y=y0; y<y1; y++) 498 { 499 byte &b = fImg[y*fW+x]; 500 if (b<=max) 501 b = 0; 502 } 503 504 ClusterFinder find(fImg, fW, fH); 505 find.FindCluster(leds, x0, y0, x1, y1); 506 } 507 508 /* 509 void FilterLed::Execute(Leds &leds, int xc, int yc, double &bright) const 510 { 511 const int x0 = TMath::Max(xc-fBox, 0); 512 const int y0 = TMath::Max(yc-fBox, 0); 513 const int x1 = TMath::Min(xc+fBox, fW); 514 const int y1 = TMath::Min(yc+fBox, fH); 515 516 const int wx = x1-x0; 517 const int hy = y1-y0; 518 519 double sum = 0; 520 double sq = 0; 521 522 for (int x=x0; x<x1; x++) 523 for (int y=y0; y<y1; y++) 524 { 525 byte &b = fImg[y*fW+x]; 526 355 527 sum += b; 356 528 sq += b*b; … … 387 559 byte mag[maxpnt]; // (Use 'new' instead for big numbers!) 388 560 561 const int r = 5; 562 389 563 int cnt = 0; 390 for (int x=x0 ; x<x1; x++)391 for (int y=y0 ; y<y1; y++)564 for (int x=x0+r; x<x1-r; x++) 565 for (int y=y0+r; y<y1-r; y++) 392 566 { 393 567 byte &b = fImg[y*fW+x]; … … 395 569 continue; 396 570 397 const int ipos = GetMeanPosition(x, y, 5);571 const int ipos = GetMeanPosition(x, y, r); 398 572 399 573 int j; … … 402 576 if (pos[j]==ipos) 403 577 { 404 if (mag[j] < 0xf0)405 mag[j] += 0x10;578 if (mag[j]<0xff) 579 mag[j]++; // how often found (area) 406 580 break; 407 581 } … … 411 585 412 586 pos[cnt] = ipos; 413 mag[cnt] = 0x10;587 mag[cnt] = 1; 414 588 415 589 cnt++; … … 428 602 for (int i=0; i<cnt; i++) 429 603 { 430 if (mag[i]<= 0x80) // 0xa0604 if (mag[i]<=7) 431 605 continue; 432 606 433 607 Float_t mx, my; 434 608 unsigned int sum; 435 GetMeanPosition(pos[i]%fW, pos[i]/fW, 5, mx, my, sum);436 437 leds.Add(mx, my, 0, 0, mag[i]);438 } 439 440 RemoveTwinsInterpol(leds, first, 5);441 } 442 443 void FilterLed::FindStar(Leds &leds, int xc, int yc, bool circle) const609 GetMeanPosition(pos[i]%fW, pos[i]/fW, r, mx, my, sum); 610 611 leds.Add(mx, my, 0, 0, 0);//mag[i]*10); 612 } 613 614 RemoveTwinsInterpol(leds, first, r); 615 } 616 */ 617 void FilterLed::FindStar(Leds &leds, int xc, int yc, bool box) const 444 618 { 445 619 // fBox: radius of the inner (signal) box … … 535 709 float mx, my; 536 710 unsigned int mag; 537 int pos = circle ? GetMeanPositionCircle(xc, yc, fBox-1, mx, my, mag) : GetMeanPosition(xc, yc, fBox-1, mx, my, mag);711 int pos = box ? GetMeanPositionBox(xc, yc, fBox-1, mx, my, mag) : GetMeanPosition(xc, yc, fBox-1, mx, my, mag); 538 712 539 713 if (pos<0 || pos>=fW*fH || fImg[pos]<sum+fCut*sdev)
Note:
See TracChangeset
for help on using the changeset viewer.