summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/skittle.cc
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/ovision/see/skittle.cc')
-rw-r--r--2005/i/robert/src/ovision/see/skittle.cc67
1 files changed, 46 insertions, 21 deletions
diff --git a/2005/i/robert/src/ovision/see/skittle.cc b/2005/i/robert/src/ovision/see/skittle.cc
index a1b4bfd..3fb5f64 100644
--- a/2005/i/robert/src/ovision/see/skittle.cc
+++ b/2005/i/robert/src/ovision/see/skittle.cc
@@ -11,7 +11,7 @@
/// Constructeur
Skittle::Skittle (Img *img, Segm *segm)
- : segm_ (segm), img_ (img)
+ : segm_ (segm), img_ (img), pcX_ (0), pcY_ (0)
{
oconfig_ = OConfig::getInstance ();
}
@@ -26,13 +26,13 @@ void
Skittle::pca (Zone &zone)
{
// Agrandissement de la zone de recherche
- const int grow = 30;
+ const int grow = oconfig_->skittleGrow;
int ymin = minWithBorder (zone.ymin - grow, 0);
int ymax = maxWithBorder (zone.ymax + grow, img_->height_);
int xmin = minWithBorder (zone.xmin - grow, 0);
int xmax = maxWithBorder (zone.xmax + grow, img_->width_);
/// Initialisation du saut de point
- int jump = oconfig_->jumpPointDist/5;
+ int jump = oconfig_->jumpPointDist/oconfig_->skittleDivJump;
if (!jump) jump = 1;
// Parcours d'une partie des pixels de l'image
int tmpY;
@@ -48,14 +48,9 @@ Skittle::pca (Zone &zone)
}
}
// Calcul de la composante principale
- for (std::vector<Hpoint>::iterator iter = l.begin (); iter != l.end (); ++iter)
- std::cout << (*iter)[0] << " " << (*iter)[1] << std::endl;
Hotelling hote (l);
hote.eigenVectors ();
- double i, j;
- hote.getPC (i, j);
- hote.show ();
- std::cout << "PC : " << i << " " << j << std::endl;
+ hote.getPC (pcX_, pcY_);
}
/// Utilisé pour la recherche de la courbure, cherche le point le plus haut
@@ -63,32 +58,53 @@ int
Skittle::climb (const int startX, int startY, const int color)
{
while (segm_->giveColor (img_->tabData_ + ((startY*img_->width_ + startX) * 3), true, true) == color)
- {
-// std::cout << startX << " " << startY << std::endl;
--startY;
- }
return startY;
}
+/// Vérifie qu'un catadiopre est à proximité
+int
+Skittle::isReflectBand (Zone &zone, std::vector<Zone> &listReflectBand)
+{
+ // Test les variables de composantes principales
+ if (!pcX_ && !pcY_ && listReflectBand.size ())
+ {
+ // Parcours la liste des catadiopres
+ for (std::vector<Zone>::iterator iter = listReflectBand.begin ();
+ iter != listReflectBand.end (); ++iter)
+ {
+ // Test la distance cartésienne
+ if (dist (iter->centerx, iter->centery, zone.centerx, zone.centery))
+ // Test la distance orthogonale
+ if (orthoDist (iter->centerx - zone.centerx, iter->centery - zone.centery,
+ pcX_, pcY_))
+ return 1;
+
+ }
+ }
+ return 0;
+}
+
/// Recherche de du côté de la courbure
Skittle::BendType
Skittle::bend (Zone &zone)
{
/// Border
- const int border = 20;
+ const int border = oconfig_->skittleBorder;
/// Initialisation du saut de point
- int jump = oconfig_->jumpPointDist/5;
+ int jump = oconfig_->jumpPointDist/oconfig_->skittleDivJump;
if (!jump) jump = 1;
/// Initialisation du point de départ
- const int startY = (int)(zone.ymin + (zone.ymax - zone.ymin) * 0.25);
+ const int startY = minWithBorder ((int)(zone.ymin + (zone.ymax - zone.ymin) * 0.25), 0);
/// Point supérieur de la quille
int upperPoint;
/// Recherche du premier et du dernier point
int firstPoint = climb (maxWithBorder (zone.xmin + border, img_->width_), startY, zone.color);
int lastPoint = climb (minWithBorder (zone.xmax - border, 0), startY, zone.color);
int limitPoint = firstPoint > lastPoint ? firstPoint : lastPoint;
- std::cout << firstPoint << " " << lastPoint << " " << limitPoint << std::endl;
+ std::cout << "<Skittle::bend> " << firstPoint << " " << lastPoint << " " << limitPoint << std::endl;
int above = 0; int below = 0;
+ std::cout << "<Skittle::bend> ";
/// Parcours des autres points
for (int i = zone.xmin + border + jump; i < zone.xmax - border - jump; i+=jump)
{
@@ -98,31 +114,40 @@ Skittle::bend (Zone &zone)
else ++above;
}
std::cout << std::endl;
- const int score = (int)((zone.xmax - zone.xmin - 2*border) / jump * 0.90) - 2;
+ const int score = (int)((zone.xmax - zone.xmin - 2*border) / jump * oconfig_->skittleScoreBendRatio) - 2;
BendType bending = error;
if (above > score) bending = up;
else if (below > score) bending = down;
- std::cout << "courb " << bending << std::endl;
return bending;
}
/// Analyse la zone
bool
-Skittle::analyse (Zone &zone)
+Skittle::analyse (Zone &zone, std::vector<Zone> &listReflectBand)
{
// group est partiel ?
// if (zone.partial)
// quille verticale sur l'image ?
- if ((zone.ymax - zone.ymin)/(double)(zone.xmax - zone.xmin) > 1.1)
+ if ((zone.ymax - zone.ymin)/(double)(zone.xmax - zone.xmin) > oconfig_->skittleVerticalRatio)
{
std::cout << "vertical !!!" << std::endl;
// debout ou couché ?
- bend (zone);
+ bend_ = bend (zone);
+ isReflectBand (zone, listReflectBand);
}
else
// calcul de l'orientation
pca (zone);
return true;
}
+
+/// Affiche les infos sur la quille
+void
+Skittle::show () const
+{
+ std::cout << "<Skittle::show> position : " << (bend_ == up ? "up"
+ : (bend_ == down ? "down" : "error")) << "\n";
+ std::cout << "<Skittle::show> orientation : " << pcX_ << ", " << pcY_ << std::endl;
+}