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

# Modules/ImageProcessor/ImageProcessorTools/ColorTableCuboids.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file ColorTableCuboids.cpp
    00003 * Implementation of class ColorTableCuboids.
    00004 *
    00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de>Matthias Jüngel</A>
    00006 */
    00007
    00008 #include "ColorTableCuboids.h"
    00009 #include "Platform/SystemCall.h"
    00010
    00011
    00012 ColorTableCuboids::ColorTableCuboids()
    00013 {
    00014   setThresholds(green, 100, 150, 100, 150, 100, 150);
    00015 }
    00016
    00017 ColorTableCuboids::~ColorTableCuboids()
    00018 {
    00019 }
    00020
    00021 int ColorTableCuboids::getThresholdMin(colorClass color, int channel) const
    00022 {
    00023   return thresholdMin[color][channel];
    00024 }
    00025
    00026 int ColorTableCuboids::getThresholdMax(colorClass color, int channel) const
    00027 {
    00028   return thresholdMax[color][channel];
    00029 }
    00030
    00031 void ColorTableCuboids::setThresholds(colorClass color, int minY, int minU, int minV, int maxY, int maxU, int maxV)
    00032 {
    00033   lastTimeWhenThresholdWasSet[color] = SystemCall::getCurrentSystemTime();
    00034   thresholdMin[color][0] = minY; thresholdMin[color][1] = minU; thresholdMin[color][2] = minV;
    00035   thresholdMax[color][0] = maxY; thresholdMax[color][1] = maxU; thresholdMax[color][2] = maxV;
    00036 }
    00037
    00038 void ColorTableCuboids::clear()
    00039 {
    00040   for(int color = 0; color < numOfColors; color++)
    00041   {
    00042     for(int channel = 0; channel < 3; channel++)
    00043     {
    00044       thresholdMin[color][channel] = 255;
    00045       thresholdMax[color][channel] = 0;
    00046     }
    00047   }
    00048
    00049 }
    00050
    00051 colorClass ColorTableCuboids::getColorClass
    00052 (
    00053  const unsigned char y,
    00054  const unsigned char u,
    00055  const unsigned char v
    00056  ) const
    00057 {
    00058   if(
    00059     y > thresholdMin[orange][0] &&
    00060     y < thresholdMax[orange][0] &&
    00061     u > thresholdMin[orange][1] &&
    00062     u < thresholdMax[orange][1] &&
    00063     v > thresholdMin[orange][2] &&
    00064     v < thresholdMax[orange][2] &&
    00065     SystemCall::getTimeSince(lastTimeWhenThresholdWasSet[orange]) < 2500 )
    00066   {
    00067     return orange;
    00068   }
    00069   else if(
    00070     y > thresholdMin[green][0] &&
    00071     y < thresholdMax[green][0] &&
    00072     u > thresholdMin[green][1] &&
    00073     u < thresholdMax[green][1] &&
    00074     v > thresholdMin[green][2] &&
    00075     v < thresholdMax[green][2] &&
    00076     SystemCall::getTimeSince(lastTimeWhenThresholdWasSet[green]) < 2500000 )
    00077   {
    00078     return green;
    00079   }
    00080   else if(
    00081     y > thresholdMin[white][0] &&
    00082     y < thresholdMax[white][0] &&
    00083     u > thresholdMin[white][1] &&
    00084     u < thresholdMax[white][1] &&
    00085     v > thresholdMin[white][2] &&
    00086     v < thresholdMax[white][2] &&
    00087     SystemCall::getTimeSince(lastTimeWhenThresholdWasSet[white]) < 5000 )
    00088   {
    00089     return white;
    00090   }
    00091   else if(
    00092     y > thresholdMin[skyblue][0] &&
    00093     y < thresholdMax[skyblue][0] &&
    00094     u > thresholdMin[skyblue][1] &&
    00095     u < thresholdMax[skyblue][1] &&
    00096     v > thresholdMin[skyblue][2] &&
    00097     v < thresholdMax[skyblue][2] &&
    00098     SystemCall::getTimeSince(lastTimeWhenThresholdWasSet[skyblue]) < 5000 )
    00099   {
    00100     return skyblue;
    00101   }
    00102   else if(
    00103     y > thresholdMin[yellow][0] &&
    00104     y < thresholdMax[yellow][0] &&
    00105     u > thresholdMin[yellow][1] &&
    00106     u < thresholdMax[yellow][1] &&
    00107     v > thresholdMin[yellow][2] &&
    00108     v < thresholdMax[yellow][2] &&
    00109     SystemCall::getTimeSince(lastTimeWhenThresholdWasSet[yellow]) < 5000 )
    00110   {
    00111     return yellow;
    00112   }
    00113   else return noColor;
    00114 }
    00115
    00116 void ColorTableCuboids::generateColorClassImage
    00117 (
    00118  const Image& image,
    00119  ColorClassImage& colorClassImage) const
    00120 {
    00121   colorClass color;
    00122   colorClassImage.width = image.cameraInfo.resolutionWidth;
    00123   colorClassImage.height = image.cameraInfo.resolutionHeight;
    00124
    00125   for (register int y=0; y < image.cameraInfo.resolutionHeight; y++)
    00126   {
    00127     for (register int x=0; x < image.cameraInfo.resolutionWidth; x++)
    00128     {
    00129       color = getColorClass(image.image[y][0][x],image.image[y][1][x],image.image[y][2][x]);
    00130       colorClassImage.image[y][x] = color;
    00131     }
    00132   }
    00133 }
    00134
    00135
    00136 In& operator>>(In& stream, ColorTableCuboids& colorTableCuboids)
    00137 {
    00138   int thresholdMin[numOfColors][3];
    00139   int thresholdMax[numOfColors][3];
    00140   for(int color = 0; color < numOfColors; color++)
    00141   {
    00142     for(int channel = 0; channel < 3; channel++)
    00143     {
    00144       stream >> thresholdMin[color][channel];
    00145       stream >> thresholdMax[color][channel];
    00146     }
    00147     colorTableCuboids.setThresholds((colorClass)color,
    00148       thresholdMin[color][0],
    00149       thresholdMin[color][1],
    00150       thresholdMin[color][2],
    00151       thresholdMax[color][0],
    00152       thresholdMax[color][1],
    00153       thresholdMax[color][2]);
    00154   }
    00155   return stream;
    00156 }
    00157
    00158 Out& operator<<(Out& stream, const ColorTableCuboids& colorTableCuboids)
    00159 {
    00160   for(int color = 0; color < numOfColors; color++)
    00161   {
    00162     for(int channel = 0; channel < 3; channel++)
    00163     {
    00164       stream << colorTableCuboids.getThresholdMin((colorClass)color, channel);
    00165       stream << colorTableCuboids.getThresholdMax((colorClass)color, channel);
    00166     }
    00167   }
    00168
    00169   return stream;
    00170 }