Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Modules/ImageProcessor/ImageProcessorTools/LightingChangeTester.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file LightingChangeTester.cpp
    00003 * Implementation of class LightingChangeTester.
    00004 *
    00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
    00006 */
    00007
    00008 #include "LightingChangeTester.h"
    00009 #include "Tools/Debugging/Debugging.h"
    00010 #include "Tools/Math/Common.h"
    00011
    00012 LightingChangeTester::~LightingChangeTester()
    00013 {
    00014 }
    00015
    00016 LightingChangeTester::LightingChangeTester()
    00017 {
    00018   init();
    00019 }
    00020
    00021 void LightingChangeTester::addColor(int channel1, int channel2, int channel3)
    00022 {
    00023   accumulatedValueInImage[0] += channel1;
    00024   accumulatedValueInImage[1] += channel2;
    00025   accumulatedValueInImage[2] += channel3;
    00026   numberOfMeasurementsInImage++;
    00027 }
    00028
    00029 void LightingChangeTester::init()
    00030 {
    00031   numberOfImages = 0;
    00032   numberOfMeasurementsInImage = 0;
    00033   valuesOfLastImages[0].init();
    00034   valuesOfLastImages[1].init();
    00035   valuesOfLastImages[2].init();
    00036 }
    00037
    00038 void LightingChangeTester::startImage()
    00039 {
    00040   numberOfMeasurementsInImage = 0;
    00041   accumulatedValueInImage[0] = 0;
    00042   accumulatedValueInImage[1] = 0;
    00043   accumulatedValueInImage[2] = 0;
    00044 }
    00045
    00046 bool LightingChangeTester::lightingHasChanged()
    00047 {
    00048   int valuesInCurrentImage[3];
    00049   int averageOfLastValues[3];
    00050
    00051   if(numberOfMeasurementsInImage == 0) return false;
    00052
    00053   int channel;
    00054   for(channel = 0; channel < 3; channel++)
    00055   {
    00056     valuesInCurrentImage[channel] = accumulatedValueInImage[channel] / numberOfMeasurementsInImage;
    00057     valuesOfLastImages[channel].add(valuesInCurrentImage[channel]);
    00058   }
    00059   numberOfImages++;
    00060
    00061   for(channel = 0; channel < 3; channel++)
    00062   {
    00063     averageOfLastValues[channel] = valuesOfLastImages[channel].getSum() / valuesOfLastImages[channel].getNumberOfEntries();
    00064   }
    00065
    00066 //  {
    00067 //  OUTPUT(idText, text, "current: " << valuesInCurrentImage[0]);
    00068 //  OUTPUT(idText, text, averageOfLastValues[0]);
    00069 //  OUTPUT(idText, text, "y: " << abs(averageOfLastValues[0] - valuesInCurrentImage[0]) );
    00070 //  OUTPUT(idText, text, "u: " << abs(averageOfLastValues[1] - valuesInCurrentImage[1]) );
    00071 //  OUTPUT(idText, text, "v: " << abs(averageOfLastValues[2] - valuesInCurrentImage[2]) );
    00072   if(
    00073     (
    00074     abs(averageOfLastValues[0] - valuesInCurrentImage[0]) > 60 ||
    00075     abs(averageOfLastValues[1] - valuesInCurrentImage[1]) > 10 ||
    00076     abs(averageOfLastValues[2] - valuesInCurrentImage[2]) > 10
    00077     )
    00078     &&
    00079     numberOfImages > 1
    00080     )
    00081   {
    00082     OUTPUT(idText, text, "change");
    00083     OUTPUT(idText, text, "y: " << abs(averageOfLastValues[0] - valuesInCurrentImage[0]) );
    00084     OUTPUT(idText, text, "u: " << abs(averageOfLastValues[1] - valuesInCurrentImage[1]) );
    00085     OUTPUT(idText, text, "v: " << abs(averageOfLastValues[2] - valuesInCurrentImage[2]) );
    00086     init();
    00087     return true;
    00088   }
    00089   return false;
    00090 }