tpimage.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Mårten Björkman (celle@csc.kth.se) 
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are
00007  * met:
00008  *
00009  *  1.Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  *  2.Redistributions in binary form must reproduce the above
00012  *    copyright notice, this list of conditions and the following
00013  *    disclaimer in the documentation and/or other materials provided
00014  *    with the distribution.  
00015  *  3.The name of Mårten Björkman may not be used to endorse or
00016  *    promote products derived from this software without specific
00017  *    prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  */
00031 
00032 #ifndef TPIMAGE_H
00033 #define TPIMAGE_H
00034 
00035 #include <fstream>
00036 #include <iostream>
00037 #include <string>
00038 #include <cstring>
00039 #include <cassert>
00040 #include <typeinfo>
00041 #include <stdint.h>
00042 
00043 
00044 #include <sensor_msgs/Image.h>
00045 
00046 typedef unsigned char uchar;
00047 
00051 
00052 template<class T>
00053 class Image {
00054   int width, height;
00055   T *image, *img;
00056   bool localalloc;
00057 public:
00059 
00062   Image(int w, int h, T *ptr=NULL);
00063   //  ~Image() { if (localalloc) delete [] img; }
00064   ~Image() { if (localalloc) free(img); }
00066 
00068   void SetSize(int w, int h);
00070 
00071   void SetData(T *ptr) { image = ptr; }
00073 
00076   void SetDataAlign(T *ptr, int w, int h);
00078 
00081   void SetDataAlign(const sensor_msgs::Image &img_msg, int w, int h, bool withColor = true);
00083 
00084   bool Load(const char *filename);
00086 
00087   bool LoadRGB(const char *filename);
00089 
00092   void Store(const char *filename, bool norm = false, bool ascii =false) const;
00094 
00095   void StoreRGB(const char *filename) const;
00097 
00098   void StoreYUV(const char *filename) const;
00100   T *GetData() const { return image; }
00102   int GetWidth() const { return width; }
00104   int GetHeight() const { return height; }
00106   T *operator[](int i) { return &image[i*width]; }
00108   void operator=(Image<T> &src);
00109 };
00110 
00111 #endif // TPIMAGE_H


active_realtime_segmentation
Author(s): Mårten Björkman. Maintained by Jeannette Bohg
autogenerated on Fri Jan 3 2014 12:02:50