From e954638ce3d5aca73959db2f75725e97398389de Mon Sep 17 00:00:00 2001 From: schodet Date: Mon, 26 May 2003 19:37:07 +0000 Subject: Modification pour le format de la camera direct. --- 2003/i/buzz/src/vision/Makefile.defs | 7 +++- 2003/i/buzz/src/vision/image.cc | 77 ++++++++--------------------------- 2003/i/buzz/src/vision/test_image.cc | 2 +- 2003/i/buzz/src/vision/test_vision.cc | 41 +++++++++++++++++++ 4 files changed, 63 insertions(+), 64 deletions(-) create mode 100644 2003/i/buzz/src/vision/test_vision.cc diff --git a/2003/i/buzz/src/vision/Makefile.defs b/2003/i/buzz/src/vision/Makefile.defs index fd6bae9..30147fd 100644 --- a/2003/i/buzz/src/vision/Makefile.defs +++ b/2003/i/buzz/src/vision/Makefile.defs @@ -1,8 +1,11 @@ -TARGETS += test_image +TARGETS += test_image test_vision LIBS += vision.a -test_image_SOURCES = test_image.cc image.cc thresholds.cc camera.a erreur.a config.a $(LIBPPM) +test_vision_SOURCES = test_vision.cc vision.a camera.a erreur.a config.a $(LIBPPM) +test_image_SOURCES = test_image.cc vision.a camera.a erreur.a config.a $(LIBPPM) vision_a_SOURCES = image.cc thresholds.cc test_image: $(test_image_SOURCES:%.cc=%.o) +test_vision: $(test_vision_SOURCES:%.cc=%.o) + vision.a: ${vision_a_SOURCES:%.cc=vision.a(%.o)} diff --git a/2003/i/buzz/src/vision/image.cc b/2003/i/buzz/src/vision/image.cc index 24c6140..27f13f8 100644 --- a/2003/i/buzz/src/vision/image.cc +++ b/2003/i/buzz/src/vision/image.cc @@ -2,10 +2,6 @@ // buzz - Programme du robot Efrei Robotique I1-I2 2003 // Copyright (C) 2003 Nicolas Schodet #include "image.h" -#include "rgbyuv.h" - -// A definir si on code en YUV. -//#define USE_YUV extern "C" { #include @@ -22,9 +18,6 @@ Image::Image (const char *filename, const Thresholds *thresholds) pixel *p; pixval maxval; int x, y, w, h; -#ifdef USE_YUV - int r, g, b, Y, U, V; -#endif // USE_YUV FILE *fp; unsigned char *pi; // Open the file. @@ -36,7 +29,7 @@ Image::Image (const char *filename, const Thresholds *thresholds) fclose (fp); if (!img) throw "Image::Image: ppm_readppm failled"; // Allocate memory... - m_image = new unsigned char [w*h*3]; + m_image = new unsigned char [w*h*4]; m_width = w; m_height = h; // Extrait les info RGB ou YUV. @@ -46,19 +39,10 @@ Image::Image (const char *filename, const Thresholds *thresholds) p = img[y]; for (x = 0; x < w; x++) { -#ifdef USE_YUV - r = PPM_GETR (*p) * 255 / maxval; - g = PPM_GETG (*p) * 255 / maxval; - b = PPM_GETB (*p) * 255 / maxval; - RgbYuv::rgbToYuv (r, g, b, Y, U, V); - *pi++ = (unsigned char) Y; - *pi++ = (unsigned char) U; - *pi++ = (unsigned char) V; -#else // ! USE_YUV - *pi++ = (unsigned char) (PPM_GETR (*p) * 255 / maxval); - *pi++ = (unsigned char) (PPM_GETG (*p) * 255 / maxval); *pi++ = (unsigned char) (PPM_GETB (*p) * 255 / maxval); -#endif // ! USE_YUV + *pi++ = (unsigned char) (PPM_GETG (*p) * 255 / maxval); + *pi++ = (unsigned char) (PPM_GETR (*p) * 255 / maxval); + *pi++ = 0; p++; } } @@ -73,17 +57,9 @@ 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]; - unsigned char *image = new unsigned char [m_width * m_height]; - // Lit l'image. - camera.read (image); - // Décode les couleurs. - for (int i = 0; i < m_width * m_height; ++i) - { - m_image[i * 3] = image[i]; - m_image[i * 3 + 1] = image[i]; - m_image[i * 3 + 2] = image[i]; - } + m_image = new unsigned char [m_width * m_height * 4]; + // Lit l'image. TODO si = 0. + while (!camera.read (m_image)); // Alloue de la memoire pour les zones. m_zones = new unsigned char [m_width * m_height]; // Initalisation @@ -109,15 +85,16 @@ void Image::filter (void) { int i; unsigned char *pz, *pi; - unsigned char r, g, b; // ou y, u, v, c'est le même traitement. + unsigned char r, g, b; // Filtre. pz = m_zones; pi = m_image; for (i = 0; i < m_width * m_height; i++) { - r = *pi++; - g = *pi++; b = *pi++; + g = *pi++; + r = *pi++; + pi++; *pz++ = m_thresholds->findZone (r, g, b); } } @@ -256,8 +233,9 @@ Image::groupFilter (void) 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 - || g2->y <= 0 || g2->y + g2->h >= m_height) + //|| g2->x <= 0 || g2->x + g2->w >= m_width + //|| g2->y <= 0 || g2->y + g2->h >= m_height) + ) { *g = g2->next; delete g2; @@ -286,11 +264,7 @@ Image::dump (const char *filename) // Allocate memory... row = ppm_allocrow (m_width); // Sauve l'image. -#ifdef USE_YUV - ppm_writeppminit (fp, m_width, m_height * 4, 255, 0); -#else // ! USE_YUV ppm_writeppminit (fp, m_width, m_height * 3, 255, 0); -#endif // ! USE_YUV // image. p = m_image; for (y = 0; y < m_height; y++) @@ -298,34 +272,15 @@ Image::dump (const char *filename) pr = row; for (x = 0; x < m_width; x++) { - r = *p++; - g = *p++; b = *p++; - PPM_ASSIGN (*pr, r, g, b); - pr++; - } - ppm_writeppmrow (fp, row, m_width, 255, 0); - } -#ifdef USE_YUV - // Image en couleurs RGB - p = m_image; - for (y = 0; y < m_height; y++) - { - pr = row; - for (x = 0; x < m_width; x++) - { - // Lit les YUV. - r = *p++; g = *p++; - b = *p++; - // Convertit. - RgbYuv::yuvToRgb (r, g, b, r, g, b); + r = *p++; + p++; PPM_ASSIGN (*pr, r, g, b); pr++; } ppm_writeppmrow (fp, row, m_width, 255, 0); } -#endif // USE_YUV // Sauve les zones. p = m_zones; for (y = 0; y < m_height; y++) diff --git a/2003/i/buzz/src/vision/test_image.cc b/2003/i/buzz/src/vision/test_image.cc index bfdc232..006c764 100644 --- a/2003/i/buzz/src/vision/test_image.cc +++ b/2003/i/buzz/src/vision/test_image.cc @@ -15,7 +15,7 @@ main (int argc, char **argv) ppm_init (&argc, argv); try { - t = new Thresholds ("palets.rgb"); + t = new Thresholds ("rc/vision/palets.rgb"); i = new Image (argc == 2 ? argv[1] : "test.ppm", t); i->filter (); i->group (); diff --git a/2003/i/buzz/src/vision/test_vision.cc b/2003/i/buzz/src/vision/test_vision.cc new file mode 100644 index 0000000..d60d915 --- /dev/null +++ b/2003/i/buzz/src/vision/test_vision.cc @@ -0,0 +1,41 @@ +// test_vision.cc +// buzz - Programme du robot Efrei Robotique I1-I2 2003 +// Copyright (C) 2003 Nicolas Schodet +// +#include "image.h" + +#include +extern "C" { +#include +}; + +int +main (int argc, char **argv) +{ + Image *i; + Camera *c; + Thresholds *t; + ppm_init (&argc, argv); + try + { + t = new Thresholds ("rc/vision/palets.rgb"); + c = new Camera (); + sleep (1); + i = new Image (*c, t); + i->filter (); + i->group (); + i->groupFilter (); + i->dumpGroups (); + i->dump ("dump.ppm"); + delete i; + delete c; + delete t; + } + catch (const char *s) + { + fprintf (stderr, "test_image: %s\n", s); + return 1; + } + return 0; +} + -- cgit v1.2.3