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 }
00171 
00172 /*
00173 * Change log :
00174 * 
00175 * $Log: ColorTableCuboids.cpp,v $
00176 * Revision 1.1.1.1  2004/05/22 17:19:47  cvsadm
00177 * created new repository GT2004_WM
00178 *
00179 * Revision 1.4  2003/12/30 23:55:01  roefer
00180 * Image size is now 208 x 160. Smaller images are placed in the upper left corner
00181 *
00182 * Revision 1.3  2003/12/15 11:46:14  juengel
00183 * Introduced CameraInfo
00184 *
00185 * Revision 1.2  2003/10/29 13:13:43  juengel
00186 * added method "clear"
00187 *
00188 * Revision 1.1  2003/10/23 07:15:17  juengel
00189 * Renamed ColorTableAuto to ColorTableReferenceColor,
00190 * added ColorTableCuboids.
00191 *
00192 */

Generated on Thu Sep 23 19:57:29 2004 for GT2004 by doxygen 1.3.6