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
00125 Image(const cv::Mat& mat);
00126
00130 ~Image();
00131
00135 void freeImage();
00136
00137 void loadImage(const std::string& fileName);
00138
00142 void set(IplImage *img);
00143
00148 IplImage *release();
00149
00150 void resizeImage(int width, int height, int channels, int depth);
00151
00152 int getWidth() const { return _img->width; };
00153 int getHeight() const { return _img->height; };
00154 int getChannel() const { return _img->nChannels; };
00155 int getDepth() const { return _img->depth; };
00156
00157 unsigned char getPixelB(int col, int row, int ch) const;
00158
00159 float getPixelF(int col, int row, int ch) const;
00160
00161 short getPixelS(int col, int row, int ch) const;
00162
00163 void setPixelB(int col, int row, int ch, unsigned char value);
00164
00165 void setPixelS(int col, int row, int ch, short value);
00166
00167 void setPixelF(int col, int row, int ch, float value);
00168
00169 IplImage* getIplImg() { return _img; };
00170
00171 IplImage* operator->(void) const { return _img; }
00172
00173 operator IplImage*() const { return _img; }
00174
00175 private:
00176
00177 IplImage _iplFromMat;
00178 IplImage *_img;
00179 bool _releaseOnDestroyer;
00180 };
00181
00185 void getLab(const Image& img, Image& L, Image& a, Image& b);
00186
00190 void setLab(const Image& L, const Image& a, const Image& b, Image& img);
00191
00200 void dctNormalization(const Image& img, Image& normalizedImg, int coefficientsToCancel, const ImageRoi& roi = ImageRoi(0,0,0,0));
00201
00205 void dctNormalization(const cv::Mat& img, cv::Mat& normalizedImg, int coefficientsToCancel, const ImageRoi& roi = ImageRoi(0,0,0,0));
00206
00207 }
00208
00209 #endif // __PAL_IMAGE_PROCESSING_H__