LMDirectionalIntegralDistanceImage.h
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 #pragma once
00027 #include <opencv/cxcore.h>
00028
00029
00030 class LMDirectionalIntegralDistanceImage
00031 {
00032 public:
00033 LMDirectionalIntegralDistanceImage();
00034 ~LMDirectionalIntegralDistanceImage();
00035
00036 void CreateImage(int width, int height);
00037 void Construct(IplImage *image, float dx, float dy);
00038 inline float Sum(int x1, int y1, int x2, int y2, int& count);
00039
00040 private:
00041 void SafeRelease();
00042 void ComputeIndices();
00043 void ComputeII(IplImage* image);
00044
00045
00046 IplImage *iimage_;
00047 float ds_;
00048 int xindexed_;
00049 int* indices_;
00050 float factor_;
00051 int width_;
00052 int height_;
00053
00054 friend class LMDistanceImage;
00055 };
00056
00057
00058 inline float LMDirectionalIntegralDistanceImage::Sum(int x1, int y1, int x2, int y2, int& count)
00059 {
00060 double value = -1;
00061
00062 if (xindexed_)
00063 {
00064 if (x1 <= x2)
00065 {
00066 int qy = y1+indices_[x2]-indices_[x1];
00067 int qx = x2;
00068 int qy1 = y1-indices_[x1]+indices_[x1-1];
00069 int qx1 = x1-1;
00070
00071 if (qy >= 0 &&
00072 qy < height_ &&
00073 qx >= 0 &&
00074 qx < width_ &&
00075 qy1 >= 0 &&
00076 qy1 < height_ &&
00077 qx1 >= 0 &&
00078 qx1 < width_ )
00079 {
00080 value =
00081 + cvGetReal2D(iimage_,qy, qx)
00082 - cvGetReal2D(iimage_,qy1, qx1);
00083 } else {
00084 value = -1;
00085 }
00086
00087 count = x2-x1+1;
00088 }
00089 else
00090 {
00091 int qy = y2+indices_[x1]-indices_[x2];
00092 int qx = x1;
00093 int qy1 = y2-indices_[x2]+indices_[x2-1];
00094 int qx1 = x2-1;
00095 if (qy >= 0 &&
00096 qy < height_ &&
00097 qx >= 0 &&
00098 qx < width_ &&
00099 qy1 >= 0 &&
00100 qy1 < height_ &&
00101 qx1 >= 0 &&
00102 qx1 < width_ )
00103 {
00104 value =
00105 + cvGetReal2D(iimage_, qy, qx)
00106 - cvGetReal2D(iimage_, qy1, qx1);
00107 count = x1-x2+1;
00108 } else {
00109 value = -1;
00110 }
00111 }
00112
00113 }
00114 else
00115 {
00116 if (y1 <= y2)
00117 {
00118 int qy = y2;
00119 int qx =x1+indices_[y2]-indices_[y1];
00120 int qy1 = y1-1;
00121 int qx1 = x1-indices_[y1]+indices_[y1-1];
00122 if (qy >= 0 &&
00123 qy < height_ &&
00124 qx >= 0 &&
00125 qx < width_ &&
00126 qy1 >= 0 &&
00127 qy1 < height_ &&
00128 qx1 >= 0 &&
00129 qx1 < width_ )
00130 {
00131 value =
00132 + cvGetReal2D(iimage_, qy, qx)
00133 - cvGetReal2D(iimage_, qy1, qx1);
00134 } else {
00135 value = -1;
00136 }
00137
00138 count = y2-y1+1;
00139
00140 }
00141 else
00142 {
00143 int qy = y1;
00144 int qx =x2+indices_[y1]-indices_[y2];
00145 int qy1 = y2-1;
00146 int qx1 = x2-indices_[y2]+indices_[y2-1];
00147 if (qy >= 0 &&
00148 qy < height_ &&
00149 qx >= 0 &&
00150 qx < width_ &&
00151 qy1 >= 0 &&
00152 qy1 < height_ &&
00153 qx1 >= 0 &&
00154 qx1 < width_ )
00155 {
00156 value =
00157 + cvGetReal2D(iimage_, qy, qx)
00158 - cvGetReal2D(iimage_, qy1, qx1);
00159 } else {
00160 value = -1;
00161 }
00162
00163 count = y1-y2+1;
00164
00165 }
00166 }
00167
00168 return (float)(value*factor_);
00169 }