summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/img.cc
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/ovision/see/img.cc')
-rw-r--r--2005/i/robert/src/ovision/see/img.cc99
1 files changed, 99 insertions, 0 deletions
diff --git a/2005/i/robert/src/ovision/see/img.cc b/2005/i/robert/src/ovision/see/img.cc
new file mode 100644
index 0000000..5dd4d28
--- /dev/null
+++ b/2005/i/robert/src/ovision/see/img.cc
@@ -0,0 +1,99 @@
+// img.cc - Classe Image
+// robert - Programme du robot APBteam
+// Copyright (C) 2005 Olivier Gaillard
+
+/// @file img.cc Chargement des images, conversion en YUV, HSI, detection des contours, transformation d'une image segmentee en RGB, ecriture de l'image sur le disque
+
+#include "img.hh"
+#include <iostream>
+#include <fstream>
+#include <stdlib.h>
+
+/// Constructeur
+Img::Img (void)
+ : tabData_ (0), tabSegm_ (0)
+{
+}
+
+/// Destructeur
+Img::~Img (void)
+{
+ delete [] tabData_;
+ delete [] tabSegm_;
+}
+
+/// Ecrit les valeurs RGB dans un fichier
+void
+Img::writeRaw (const char *filename, unsigned char *tab) const
+{
+ if (!tab) tab = tabData_;
+ std::ofstream file (filename, std::ios::out | std::ios::trunc);
+ if (file)
+ file.write ((char *)tab, nbPixels_*3);
+ else
+ std::cerr << "Img::writeRaw Erreur d'ouverture de fichier" << std::endl;
+ file.close ();
+}
+
+/// Charge les valeurs RGB dans un fichier
+void
+Img::loadRaw (const char *filename, const Image::PixelFormat colorMode_, const int width_, const int height_)
+{
+ // Enregistre les paramètres de l'image
+ this->width_ = width_;
+ this->height_ = height_;
+ nbPixels_ = width_ * height_;
+ this->colorMode_ = colorMode_;
+ // Initialise tabData_
+ delete[] tabData_;
+ tabData_ = new unsigned char[nbPixels_*3];
+ // Ouvre l'image
+ std::ifstream file (filename, std::ios::in);
+ if (file)
+ file.read ((char *)tabData_, nbPixels_*3);
+ else
+ std::cerr << "Img::loadRaw Erreur d'ouverture de fichier " << filename << std::endl;
+ file.close ();
+}
+
+/// Charge plusieurs fichiers
+void
+Img::loadMultipeRaw (const std::vector<std::string> &imgList, const Image::PixelFormat colorMode_, const int width_, const int height_)
+{
+ // Enregistre les paramètres de l'image
+ this->width_ = width_;
+ this->height_ = height_ * imgList.size ();
+ nbPixels_ = width_ * height_;
+ this->colorMode_ = colorMode_;
+ // Initialise tabData_
+ delete[] tabData_;
+ tabData_ = new unsigned char[nbPixels_*3];
+ // Ouvre les images et stocke les données dans tabData_
+ for (std::vector<std::string>::const_iterator iter=imgList.begin(); iter != imgList.end(); iter++)
+ {
+ std::ifstream file (iter->c_str (), std::ios::in);
+ if (file)
+ file.read ((char *)tabData_, nbPixels_*3);
+ else
+ std::cerr << "Img::loadRaw Erreur d'ouverture de fichier " << *iter << std::endl;
+ file.close ();
+ }
+}
+
+
+/// Lit une image depuis un Image.
+void
+Img::load (ImageReader &loader)
+{
+ delete[] tabData_;
+ // Ouvre l'image
+ Image image;
+ image.read (loader);
+ image.getSize (width_, height_);
+ nbPixels_ = width_ * height_;
+ tabData_ = new unsigned char[image.getBufSize ()];
+ memcpy (tabData_, image.getBuf (), image.getBufSize ());
+ // Récupère le format de couleur
+ colorMode_ = image.getPixelFormat ();
+}
+