23 using namespace KKLSC;
29 const uchar* _compensationTable
31 compensationTable (_compensationTable),
34 highPointLastSeen (NULL),
36 lastHistoryIdxAdded (_numSampleLines - 1),
37 lineWidth (_lineWidth),
38 numSampleLines (_numSampleLines),
39 numSampleLinesAdded (0),
44 highPoint =
new uchar[lineWidth];
45 highPointLastSeen =
new kkint32[lineWidth];
46 for (x = 0; x < lineWidth; x++)
49 highPointLastSeen[x] = 0;
52 history =
new uchar*[numSampleLines];
53 for (x = 0; x < numSampleLines; x++)
55 history[x] =
new uchar[lineWidth];
56 for (y = 0; y < lineWidth; y++)
60 totalLine =
new kkint32[lineWidth];
62 lookUpTable =
new uchar*[lineWidth];
63 for (x = 0; x < lineWidth; x++)
65 lookUpTable[x] =
new uchar[256];
66 for (y = 0; y < 256; y++)
67 lookUpTable[x][y] = y;
70 for (
kkint32 col = 0; col < lineWidth; col++)
71 ReComputeLookUpForColumn (col);
80 delete highPoint; highPoint = NULL;
81 delete highPointLastSeen; highPointLastSeen = NULL;
83 for (x = 0; x < numSampleLines; x++)
91 for (x = 0; x < lineWidth; x++)
93 delete lookUpTable[x];
94 lookUpTable[x] = NULL;
97 delete lookUpTable; lookUpTable = NULL;
98 delete totalLine; totalLine = NULL;
104 compensationTable = _compensationTable;
105 for (
kkint32 x = 0; x < lineWidth; ++x)
106 ReComputeLookUpForColumn (x);
114 lastHistoryIdxAdded++;
115 if (lastHistoryIdxAdded >= numSampleLines)
116 lastHistoryIdxAdded = 0;
118 uchar* historyLine = history[lastHistoryIdxAdded];
119 for (
kkint32 x = 0; x < lineWidth; ++x)
121 historyLine[x] = sampleLine[x];
122 if (sampleLine[x] < highPoint[x])
124 highPointLastSeen[x]++;
125 if (highPointLastSeen[x] > numSampleLines)
126 ReComputeLookUpForColumn (x);
128 else if ((sampleLine[x] - 5) > highPoint[x])
130 ReComputeLookUpForColumn (x);
131 highPointLastSeen[x] = 0;
135 highPointLastSeen[x] = 0;
139 numSampleLinesAdded++;
149 highPointLastSeen[col] = 1;
151 kkint32 historyIdx = lastHistoryIdxAdded;
162 uchar hv = history[historyIdx][col];
165 hp2 = hp1; hp2Age = hp1Age;
166 hp1 = hp0; hp1Age = hp0Age;
167 hp0 = hv; hp0Age = age;
171 hp2 = hp1; hp2Age = hp1Age;
172 hp1 = hv; hp1Age = age;
176 hp2 = hv; hp2Age = age;
186 historyIdx = numSampleLines - 1;
188 if (historyIdx == lastHistoryIdxAdded)
199 highPoint[col] = hp2;
200 highPointLastSeen[col] = hp2Age;
211 if (compensationTable)
212 newPixelValue = compensationTable[newPixelValue];
213 newPixelValue = 255 - newPixelValue;
214 for (row = 0; row < 256; ++row)
215 lookUpTable[col][row] = newPixelValue;
225 for (row = 0; row < 256; ++row)
228 newPixelValue = (
kkint32)(0.5f + (255.0f * (
float)row) / (
float)hp);
232 if ((newPixelValue < 0) || (newPixelValue > 255))
234 cout <<
"Woaaaaa!!!!! it went beyond 255 or less that 0 [" << newPixelValue <<
"]." << endl;
238 if (compensationTable)
239 newPixelValue = compensationTable[newPixelValue];
241 newPixelValue = 255 - newPixelValue;
243 lookUpTable[col][row] = (
uchar)newPixelValue;
249 for (
kkint32 row = 0; row < 256; ++row)
252 if (compensationTable)
253 newPixelValue = compensationTable[newPixelValue];
255 newPixelValue = 255 - newPixelValue;
257 lookUpTable[col][row] = (
uchar)newPixelValue;
266 for (
kkint32 col = 0; col < lineWidth; col++)
267 scanLine[col] = lookUpTable[col][scanLine[col]];
278 for (
kkint32 col = 0; col < lineWidth; col++)
279 destScanLine[col] = lookUpTable[col][srcScanLine[col]];
283 for (
kkint32 col = 0; col < lineWidth; col++)
284 destScanLine[col] = srcScanLine[col];
292 vector<uchar>* results =
new vector<uchar> ();
293 for (kkint32 x = 0; x < lineWidth; x++)
294 results->push_back (highPoint[x]);
302 n = Min (n, numSampleLines);
304 vector<uchar>* highPoints =
new vector<uchar>(lineWidth, 0);
306 kkint32 row = lastHistoryIdxAdded;
307 for (
kkint32 x = 0; x < n; ++x)
310 row = numSampleLines - 1;
311 uchar* sampleRow = history[row];
313 for (
kkint32 col = 0; col < lineWidth; ++col)
315 if (sampleRow[col] > (*highPoints)[col])
316 (*highPoints)[col] = sampleRow[col];
void ApplyFlatFieldCorrection(uchar *scanLine)
FlatFieldCorrection(kkint32 _numSampleLines, kkint32 _lineWidth, const uchar *_compensationTable)
void CompensationTable(const uchar *_compensationTable)
VectorUcharPtr CameraHighPoints() const
void AddSampleLine(const uchar *sampleLine)
Provide sample of one scan line as from the camera; where 0 = foreground and 255 = background...
unsigned char uchar
Unsigned character.
Contains Classes that are specific to Cameras physical characteristics.
VectorUchar * VectorUcharPtr
VectorUcharPtr CameraHighPointsFromLastNSampleLines(kkint32 n) const
Will return the high point for each pixel from the last 'n' sample lines taken.
void ApplyFlatFieldCorrection(uchar *srcScanLine, uchar *destScanLine)