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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Component/ModelManager.H"
00039 #include "Devices/FrameGrabberConfigurator.H"
00040 #include "GUI/XWindow.H"
00041 #include "Image/DrawOps.H"
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Transport/FrameIstream.H"
00045 #include "Util/Timer.H"
00046 #include "Util/log.H"
00047
00048 #include <cstdio>
00049 #include <cstdlib>
00050 #include <cstring>
00051
00052 #define NAVG 20
00053
00054
00055
00056
00057
00058 int main(const int argc, const char **argv)
00059 {
00060
00061 ModelManager manager("Frame Grabber Tester");
00062
00063
00064 nub::soft_ref<FrameGrabberConfigurator>
00065 gbc(new FrameGrabberConfigurator(manager));
00066 manager.addSubComponent(gbc);
00067
00068
00069 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00070
00071
00072 nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00073 if (gb.isInvalid())
00074 LFATAL("You need to select a frame grabber type via the "
00075 "--fg-type=XX command-line option for this program "
00076 "to be useful");
00077
00078
00079 manager.start();
00080
00081
00082 XWindow win(gb->peekDims(), -1, -1, "test-HSV window");
00083 XWindow histoH(Dims(425,210), -1, -1, "Histogram Hue");
00084 XWindow histoS(Dims(425,210), -1, -1, "Histogram Satutation");
00085 XWindow histoV(Dims(425,210), -1, -1, "Histogram Value");
00086
00087 int sizeX, sizeY;
00088 int winXleft, winXright, winYtop, winYbottom;
00089 long pixels;
00090 float H,S,V;
00091
00092 float Hmax,Smax,Vmax;
00093 int Hhist[200];
00094 int Shist[200];
00095 int Vhist[200];
00096
00097 PixRGB<float> pix;
00098 Image<PixRGB<byte> > HistoH;
00099 Image<PixRGB<byte> > HistoS;
00100 Image<PixRGB<byte> > HistoV;
00101 while(1) {
00102 HistoH.resize(425,210,true);
00103 HistoS.resize(425,210,true);
00104 HistoV.resize(425,210,true);
00105
00106 for(int i = 0; i < 200 ; i++)
00107 {
00108 Hhist[i] = 0;
00109 Shist[i] = 0;
00110 Vhist[i] = 0;
00111 }
00112 H = 0; S = 0; V = 0;
00113 Hmax = 0; Smax = 0; Vmax = 0;
00114 pixels = 0;
00115 Image< PixRGB<byte> > ima = gb->readRGB();
00116 sizeX = ima.getWidth();
00117 sizeY = ima.getHeight();
00118 winXleft = sizeX/3;
00119 winXright = sizeX - sizeX/3;
00120 winYtop = sizeY/3;
00121 winYbottom = sizeY - sizeY/3;
00122 for(int i = winXleft; i < winXright; i++)
00123 {
00124 for(int j = winYtop; j < winYbottom; j++)
00125 {
00126 float pixH,pixS,pixV;
00127 int doH,doS,doV;
00128 pix = PixRGB<float>(ima.getVal(i,j));
00129 PixHSV<float>(pix).getHSV(pixH,pixS,pixV);
00130 doH = (int)((pixH/360)*200);
00131 doS = (int)(pixS*200);
00132 doV = (int)((pixV/255)*200);
00133 Hhist[doH]++;
00134 Shist[doS]++;
00135 Vhist[doV]++;
00136 H += pixH;
00137 S += pixS;
00138 V += pixV;
00139 pixels++;
00140 }
00141 }
00142 H = H/pixels;
00143 S = S/pixels;
00144 V = V/pixels;
00145 for(int i = 0; i < 200 ; i++)
00146 {
00147 if(Hhist[i] > Hmax) Hmax = Hhist[i];
00148 if(Shist[i] > Smax) Smax = Shist[i];
00149 if(Vhist[i] > Vmax) Vmax = Vhist[i];
00150 }
00151 for(int i = 0; i < 200 ; i++)
00152 {
00153 drawRect(HistoH, Rectangle::tlbrI(1,((i+1)*2-1),(int)((Hhist[i]/Hmax)*200.0F)+2,((i+1)*2)),
00154 PixRGB<byte>(255,0,0),1);
00155 drawRect(HistoS, Rectangle::tlbrI(1,((i+1)*2-1),(int)((Shist[i]/Smax)*200.0F)+2,((i+1)*2)),
00156 PixRGB<byte>(0,255,0),1);
00157 drawRect(HistoV, Rectangle::tlbrI(1,((i+1)*2-1),(int)((Vhist[i]/Vmax)*200.0F)+2,((i+1)*2)),
00158 PixRGB<byte>(0,0,255),1);
00159 }
00160 drawRect(ima, Rectangle::tlbrI(winYtop,winXleft,winYbottom,winXright),
00161 PixRGB<byte>(255,255,0),1);
00162 LINFO("H %f S %f V %f",H,S,V);
00163 win.drawImage(ima);
00164 histoH.drawImage(HistoH);
00165 histoS.drawImage(HistoS);
00166 histoV.drawImage(HistoV);
00167 }
00168
00169 manager.stop();
00170
00171
00172 return 0;
00173 }
00174
00175
00176
00177
00178
00179