From 356a80697a3268aae77681b055e5e835aa2d1a71 Mon Sep 17 00:00:00 2001 From: schodet Date: Mon, 5 May 2003 18:34:25 +0000 Subject: Add: Support de la camera. Sub: size_thresholds. --- 2003/i/buzz/src/vision/GNUmakefile | 11 ++++--- 2003/i/buzz/src/vision/image.cc | 22 ++++++++++--- 2003/i/buzz/src/vision/image.h | 13 ++++---- 2003/i/buzz/src/vision/size_thresholds.cc | 53 ------------------------------- 2003/i/buzz/src/vision/size_thresholds.h | 40 ----------------------- 2003/i/buzz/src/vision/test_image.cc | 5 +-- 2003/i/buzz/src/vision/thresholds.h | 6 ++-- 7 files changed, 35 insertions(+), 115 deletions(-) delete mode 100644 2003/i/buzz/src/vision/size_thresholds.cc delete mode 100644 2003/i/buzz/src/vision/size_thresholds.h (limited to '2003') diff --git a/2003/i/buzz/src/vision/GNUmakefile b/2003/i/buzz/src/vision/GNUmakefile index b72985b..a4b5127 100644 --- a/2003/i/buzz/src/vision/GNUmakefile +++ b/2003/i/buzz/src/vision/GNUmakefile @@ -1,17 +1,20 @@ SRCDIR = .. CXXFLAGS = -Wall -g -CPPFLAGS = -I$(SRCDIR) +CPPFLAGS = -I$(SRCDIR) -I/usr/pkg/include +LDFLAGS = -L/usr/pkg/lib +LDADD = -lnetpbm -LDADD = -lppm +TARGETS = test_image vision.a test_image_SOURCES = test_image.cc image.cc thresholds.cc size_thresholds.cc - -TARGETS = test_image +vision_a_SOURCES = image.cc thresholds.cc size_thresholds.cc all: $(TARGETS) test_image: $(test_image_SOURCES:%.cc=%.o) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^ $(LDADD) +vision.a: ${vision_a_SOURCES:%.cc=vision.a(%.o)} + .dep/%.d: %.cc .dep @set -e; $(CC) -M $(CPPFLAGS) $< \ | sed 's/\($*\)\.o[ :]*/\1.o .dep\/$*.d : /g' > $@; \ diff --git a/2003/i/buzz/src/vision/image.cc b/2003/i/buzz/src/vision/image.cc index f868587..159d5ef 100644 --- a/2003/i/buzz/src/vision/image.cc +++ b/2003/i/buzz/src/vision/image.cc @@ -15,9 +15,8 @@ extern "C" { #define min(a,b) ((a) < (b) ? (a) : (b)) #define max(a,b) ((a) > (b) ? (a) : (b)) -// Constructeur. -Image::Image (const char *filename, Thresholds *thresholds, - SizeThresholds *sizeThresholds) +// Constructeurs. +Image::Image (const char *filename, const Thresholds *thresholds) { pixel **img; pixel *p; @@ -68,7 +67,20 @@ Image::Image (const char *filename, Thresholds *thresholds, // Initalisation m_groups = 0; m_thresholds = thresholds; - m_sizeThresholds = sizeThresholds; +} + +Image::Image (const Camera &camera, const Thresholds *thresholds) +{ + // Allocate memory... + camera.getSize (m_width, m_height); + m_image = new unsigned char [m_width * m_height * 3]; + // Lit l'image. + camera.read (m_image); + // Alloue de la memoire pour les zones. + m_zones = new unsigned char [m_width * m_height]; + // Initalisation + m_groups = 0; + m_thresholds = thresholds; } // Destructeur @@ -233,7 +245,7 @@ Image::groupFilter (void) { g2 = *g; // Trouve le type de palet. - g2->type = m_sizeThresholds->findType (g2->w, g2->h); + g2->type = 1; // TODO : trouver le type du palet. // Vire les groupes qu'on ne voix pas en entier ou d'une taille bizare. if (g2->type == 0 || g2->x <= 0 || g2->x + g2->w >= m_width diff --git a/2003/i/buzz/src/vision/image.h b/2003/i/buzz/src/vision/image.h index eae1d20..cbee54e 100644 --- a/2003/i/buzz/src/vision/image.h +++ b/2003/i/buzz/src/vision/image.h @@ -3,8 +3,9 @@ // image.h - Image class // buzz - Programme du robot Efrei Robotique I1-I2 2003 // Copyright (C) 2003 Nicolas Schodet + #include "thresholds.h" -#include "size_thresholds.h" +#include "camera/camera.h" struct ImageGroup { @@ -19,14 +20,14 @@ class Image unsigned char *m_image; unsigned char *m_zones; ImageGroup *m_groups; - Thresholds *m_thresholds; - SizeThresholds *m_sizeThresholds; + const Thresholds *m_thresholds; public: - // Constructeur. - Image (const char *filename, Thresholds *thresholds, - SizeThresholds *sizeThresholds); + // Constructeurs. + Image (const char *filename, const Thresholds *thresholds); + Image (const Camera &camera, const Thresholds *thresholds); // Destructeur. ~Image (void); + // Filtre l'image pour trouver les zones. void filter (void); // Fait des packets de pixels. void group (void); diff --git a/2003/i/buzz/src/vision/size_thresholds.cc b/2003/i/buzz/src/vision/size_thresholds.cc deleted file mode 100644 index 3a65d4c..0000000 --- a/2003/i/buzz/src/vision/size_thresholds.cc +++ /dev/null @@ -1,53 +0,0 @@ -// size_thresholds.cc - Chargement de seuils de taille de palets. -// buzz - Programme du robot Efrei Robotique I1-I2 2003 -// Copyright (C) 2003 Nicolas Schodet -#include "size_thresholds.h" - -#include - -// Constructeur. -SizeThresholds::SizeThresholds (const char *filename) -{ - FILE *fp; - SizeThreshold **pt; - int n; - int type, wm, wM, hm, hM; - // Ouvre le fichier. - fp = fopen (filename, "r"); - if (!fp) throw "SizeThresholds::SizeThresholds: fopen failled"; - // Charge chaque lignes. - pt = &m_thresholds; - while (!feof (fp)) - { - n = fscanf (fp, "%d %d %d %d %d\n", &type, &wm, &wM, - &hm, &hM); - if (n != 5) - { - fclose (fp); - throw "SizeThresholds::SizeThresholds: Bad format."; - } - // Ajoute un nouveaux seuil a la collection. - *pt = new SizeThreshold; - (*pt)->type = type; - (*pt)->wm = wm; - (*pt)->wM = wM; - (*pt)->hm = hm; - (*pt)->hM = hM; - pt = &(*pt)->next; - } - // Ferme la liste de seuils. - *pt = 0; - // Ferme le fichier. - fclose (fp); -} - -// Destructeur. -SizeThresholds::~SizeThresholds (void) -{ - SizeThreshold *p, *p2; - for (p = m_thresholds; p; p = p2) - { - p2 = p->next; - delete p; - } -} diff --git a/2003/i/buzz/src/vision/size_thresholds.h b/2003/i/buzz/src/vision/size_thresholds.h deleted file mode 100644 index f30ac4d..0000000 --- a/2003/i/buzz/src/vision/size_thresholds.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef __size_thresholds_h__ -#define __size_thresholds_h__ -// size_thresholds.h - Chargement de seuils pour les tailles de palets. -// buzz - Programme du robot Efrei Robotique I1-I2 2003 -// Copyright (C) 2003 Nicolas Schodet - -struct SizeThreshold -{ - SizeThreshold *next; - int wm, wM, hm, hM; - int type; -}; - -class SizeThresholds -{ - SizeThreshold *m_thresholds; - public: - SizeThresholds (const char *filename); - ~SizeThresholds (void); - // Trouve le type qui correspond a la taille. - int findType (int w, int h); -}; - -// Trouve la zone qui correspond aux composantes. -inline int -SizeThresholds::findType (int w, int h) -{ - SizeThreshold *t; - for (t = m_thresholds; t; t = t->next) - { - if (w >= t->wm && w <= t->wM - && h >= t->hm && h <= t->hM) - { - return t->type; - } - } - return 0; -} - -#endif // size_thresholds_h diff --git a/2003/i/buzz/src/vision/test_image.cc b/2003/i/buzz/src/vision/test_image.cc index cbdbd1e..bfdc232 100644 --- a/2003/i/buzz/src/vision/test_image.cc +++ b/2003/i/buzz/src/vision/test_image.cc @@ -12,13 +12,11 @@ main (int argc, char **argv) { Image *i; Thresholds *t; - SizeThresholds *st; ppm_init (&argc, argv); try { t = new Thresholds ("palets.rgb"); - st = new SizeThresholds ("palets.size"); - i = new Image (argc == 2 ? argv[1] : "test.ppm", t, 0); + i = new Image (argc == 2 ? argv[1] : "test.ppm", t); i->filter (); i->group (); i->groupFilter (); @@ -26,7 +24,6 @@ main (int argc, char **argv) i->dump ("dump.ppm"); delete i; delete t; - delete st; } catch (const char *s) { diff --git a/2003/i/buzz/src/vision/thresholds.h b/2003/i/buzz/src/vision/thresholds.h index b11c387..42d7313 100644 --- a/2003/i/buzz/src/vision/thresholds.h +++ b/2003/i/buzz/src/vision/thresholds.h @@ -18,13 +18,13 @@ class Thresholds Thresholds (const char *filename); ~Thresholds (void); // Trouve la zone qui correspond aux composantes. - unsigned char findZone (unsigned char y, unsigned char u, unsigned char - v); + unsigned char findZone (unsigned char y, unsigned char u, unsigned char v) + const; }; // Trouve la zone qui correspond aux composantes. inline unsigned char -Thresholds::findZone (unsigned char y, unsigned char u, unsigned char v) +Thresholds::findZone (unsigned char y, unsigned char u, unsigned char v) const { Threshold *t; for (t = m_thresholds; t; t = t->next) -- cgit v1.2.3