00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00037 #ifndef __PAL_IMAGE_PROCESSING_H__
00038 #define __PAL_IMAGE_PROCESSING_H__
00039
00040
00041 #include <opencv2/core/core.hpp>
00042
00043 #include <vector>
00044
00045 namespace pal_vision_util
00046 {
00055 void getConnectedComponents(const cv::Mat& binaryImage,
00056 std::vector< std::vector<cv::Point2i> >& components,
00057 std::vector< cv::Rect >& boundingBoxes);
00058
00059
00066 class ImageRoi
00067 {
00068 public:
00069 ImageRoi();
00070
00071 ImageRoi(const ImageRoi& roi);
00072
00073 ImageRoi(int left, int top, int w, int h);
00074
00075 ImageRoi(CvRect rect);
00076
00077 ~ImageRoi();
00078
00079 void set(CvRect rect);
00080
00081 void clear();
00082
00083 bool empty() const;
00084
00085 CvRect toCvRect() const;
00086
00091 void keepInside(int imgWidth, int imgHeight);
00092
00096 const ImageRoi& resize(double factorHorizontal, double factorVertical);
00097
00098 int x, y, width, height;
00099 };
00100
00107 class Image
00108 {
00109 public:
00110
00114 Image();
00115
00119 Image(IplImage *img);
00120
00124 ~Image();
00125
00129 void freeImage();
00130
00131 void loadImage(const std::string& fileName);
00132
00136 void set(IplImage *img);
00137
00142 IplImage *release();
00143
00144 void resizeImage(int width, int height, int channels, int depth);
00145
00146 int getWidth() const { return _img->width; };
00147 int getHeight() const { return _img->height; };
00148 int getChannel() const { return _img->nChannels; };
00149 int getDepth() const { return _img->depth; };
00150
00151 unsigned char getPixelB(int col, int row, int ch) const;
00152
00153 float getPixelF(int col, int row, int ch) const;
00154
00155 short getPixelS(int col, int row, int ch) const;
00156
00157 void setPixelB(int col, int row, int ch, unsigned char value);
00158
00159 void setPixelS(int col, int row, int ch, short value);
00160
00161 void setPixelF(int col, int row, int ch, float value);
00162
00163 IplImage* getIplImg() { return _img; };
00164
00165 IplImage* operator->(void) const { return _img; }
00166
00167 operator IplImage*() const { return _img; }
00168
00169 private:
00170
00171 IplImage *_img;
00172 };
00173
00177 void getLab(const Image& img, Image& L, Image& a, Image& b);
00178
00182 void setLab(const Image& L, const Image& a, const Image& b, Image& img);
00183
00192 void dctNormalization(const Image& img, Image& normalizedImg, int coefficientsToCancel, const ImageRoi& roi = ImageRoi(0,0,0,0));
00193
00197 void dctNormalization(const cv::Mat& img, cv::Mat& normalizedImg, int coefficientsToCancel, const ImageRoi& roi = ImageRoi(0,0,0,0));
00198
00199 }
00200
00201 #endif // __PAL_IMAGE_PROCESSING_H__