$search
00001 /* 00002 * Software License Agreement (Modified BSD License) 00003 * 00004 * Copyright (c) 2012, PAL Robotics, S.L. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of PAL Robotics, S.L. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 */ 00034 00037 #ifndef __PAL_IMAGE_PROCESSING_H__ 00038 #define __PAL_IMAGE_PROCESSING_H__ 00039 00040 #include <opencv/cv.h> 00041 #include <opencv2/core/core.hpp> 00042 00043 namespace pal_vision_util 00044 { 00051 class ImageRoi 00052 { 00053 public: 00054 ImageRoi(); 00055 00056 ImageRoi(const ImageRoi& roi); 00057 00058 ImageRoi(int left, int top, int w, int h); 00059 00060 ImageRoi(CvRect rect); 00061 00062 ~ImageRoi(); 00063 00064 void set(CvRect rect); 00065 00066 void clear(); 00067 00068 bool empty() const; 00069 00070 CvRect toCvRect() const; 00071 00076 void keepInside(int imgWidth, int imgHeight); 00077 00081 const ImageRoi& resize(double factorHorizontal, double factorVertical); 00082 00083 int x, y, width, height; 00084 }; 00085 00092 class Image 00093 { 00094 public: 00095 00099 Image(); 00100 00104 Image(IplImage *img); 00105 00109 ~Image(); 00110 00114 void freeImage(); 00115 00116 void loadImage(const std::string& fileName); 00117 00121 void set(IplImage *img); 00122 00127 IplImage *release(); 00128 00129 void resizeImage(int width, int height, int channels, int depth); 00130 00131 int getWidth() const { return _img->width; }; 00132 int getHeight() const { return _img->height; }; 00133 int getChannel() const { return _img->nChannels; }; 00134 int getDepth() const { return _img->depth; }; 00135 00136 unsigned char getPixelB(int col, int row, int ch) const; 00137 00138 float getPixelF(int col, int row, int ch) const; 00139 00140 short getPixelS(int col, int row, int ch) const; 00141 00142 void setPixelB(int col, int row, int ch, unsigned char value); 00143 00144 void setPixelS(int col, int row, int ch, short value); 00145 00146 void setPixelF(int col, int row, int ch, float value); 00147 00148 IplImage* getIplImg() { return _img; }; 00149 00150 IplImage* operator->(void) const { return _img; } 00151 00152 operator IplImage*() const { return _img; } //overloads cast to IplImage* operator 00153 00154 private: 00155 00156 IplImage *_img; 00157 }; 00158 00162 void getLab(const Image& img, Image& L, Image& a, Image& b); 00163 00167 void setLab(const Image& L, const Image& a, const Image& b, Image& img); 00168 00177 void dctNormalization(const Image& img, Image& normalizedImg, int coefficientsToCancel, const ImageRoi& roi = ImageRoi(0,0,0,0)); 00178 00182 void dctNormalization(const cv::Mat& img, cv::Mat& normalizedImg, int coefficientsToCancel, const ImageRoi& roi = ImageRoi(0,0,0,0)); 00183 00184 } // namespace pal_vision_util 00185 00186 #endif // __PAL_IMAGE_PROCESSING_H__