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
00039 #include "Component/ModelManager.H"
00040 #include "Devices/DeviceOpts.H"
00041 #include "Devices/FrameGrabberConfigurator.H"
00042 #include "GUI/XWinManaged.H"
00043 #include "Image/ColorOps.H"
00044 #include "Image/DrawOps.H"
00045 #include "Image/FilterOps.H"
00046 #include "Image/Image.H"
00047 #include "Image/ImageSet.H"
00048 #include "Image/MathOps.H"
00049 #include "Image/Pixels.H"
00050 #include "Image/PyramidOps.H"
00051 #include "Image/ShapeOps.H"
00052 #include "Image/Transforms.H"
00053 #include "Image/colorDefs.H"
00054 #include "Transport/FrameIstream.H"
00055 #include "Util/log.H"
00056
00057 #define DOSTAIN
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 int main(const int argc, const char **argv)
00068 {
00069 LOG_FLAGS &= (~LOG_FULLTRACE);
00070
00071 const int numGrabs = 3;
00072 const byte colMin = 0;
00073 const byte colMax = 255;
00074 const float RGBYthresh = 25.0F;
00075
00076
00077 ModelManager manager("Show Filters");
00078
00079
00080 nub::soft_ref<FrameGrabberConfigurator>
00081 gbc(new FrameGrabberConfigurator(manager));
00082 manager.addSubComponent(gbc);
00083
00084
00085
00086 manager.setOptionValString(&OPT_FrameGrabberType, "V4L");
00087 manager.setOptionValString(&OPT_FrameGrabberDevice,"/dev/v4l/video0");
00088 manager.setOptionValString(&OPT_FrameGrabberDims, "320x240");
00089 manager.setOptionValString(&OPT_FrameGrabberChannel, "0");
00090 manager.setOptionValString(&OPT_FrameGrabberMode,"YUV420P");
00091
00092
00093 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00094
00095
00096 nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00097 if (gb.isInvalid())
00098 LFATAL("You need to select a frame grabber type via the "
00099 "--fg-type=XX command-line option for this program "
00100 "to be useful");
00101 const Dims dims = gb->peekDims();
00102
00103
00104 manager.start();
00105
00106
00107
00108 CloseButtonListener clist;
00109 XWinManaged xCap(dims,-1,-1,"Captured"); clist.add(xCap);
00110
00111 XWinManaged xRL(dims,-1,-1,"pos(RG) - Standard, clamped"); clist.add(xRL);
00112 XWinManaged xGL(dims,-1,-1,"neg(RG) - Standard, clamped"); clist.add(xGL);
00113 XWinManaged xBL(dims,-1,-1,"pos(BY) - Standard, clamped"); clist.add(xBL);
00114 XWinManaged xYL(dims,-1,-1,"neg(BY) - Standard, clamped"); clist.add(xYL);
00115
00116 XWinManaged xRD1(dims,-1,-1,"pos(RG) - Simple"); clist.add(xRD1);
00117 XWinManaged xGD1(dims,-1,-1,"neg(RG) - Simple"); clist.add(xGD1);
00118 XWinManaged xBD1(dims,-1,-1,"pos(BY) - Simple"); clist.add(xBD1);
00119 XWinManaged xYD1(dims,-1,-1,"neg(BY) - Simple"); clist.add(xYD1);
00120
00121 #ifdef DOSTAIN
00122 XWinManaged xCL(dims,-1,-1,"Colors, Standard"); clist.add(xCL);
00123 XWinManaged xCD1(dims,-1,-1,"Colors, Simple"); clist.add(xCD1);
00124 #endif
00125
00126
00127 while (!clist.pressedAnyCloseButton())
00128 {
00129
00130 Image<PixRGB <byte> > iCap;
00131 for (int i = 0; i < numGrabs; ++i)
00132 iCap = gb->readRGB();
00133 xCap.drawImage(iCap);
00134
00135 Image<float> rg,by,rgp,rgn,byp,byn;
00136 Image<PixRGB <byte> > cR,cG,cY,cB,cCol;
00137 Image<float> zero(iCap.getDims(),ZEROS);
00138
00139
00140 getRGBY(iCap,rg,by,RGBYthresh);
00141
00142 rgp = rg; rgn = zero - rg;
00143 byp = by; byn = zero - by;
00144
00145 inplaceClamp(rgp, 0.0f,1.0f);
00146 inplaceClamp(rgn, 0.0f,1.0f);
00147 inplaceClamp(byp, 0.0f,1.0f);
00148 inplaceClamp(byn, 0.0f,1.0f);
00149
00150 #ifdef DOSTAIN
00151 cR = colorStain(Image<byte>(rgp*255.0f),colMin,colMax,COL_RED);
00152 cG = colorStain(Image<byte>(rgn*255.0f),colMin,colMax,COL_GREEN);
00153 cB = colorStain(Image<byte>(byp*255.0f),colMin,colMax,COL_BLUE);
00154 cY = colorStain(Image<byte>(byn*255.0f),colMin,colMax,COL_YELLOW);
00155 cCol = takeMax(takeMax(cR,cG),takeMax(cB,cY));
00156 xRL.drawImage(cR); xGL.drawImage(cG);
00157 xBL.drawImage(cB); xYL.drawImage(cY);
00158 xCL.drawImage(cCol);
00159 #else
00160 drawImage(xRL, rgp); drawImage(xGL, rgn);
00161 drawImage(xBL, byp); drawImage(xYL, byn);
00162 #endif
00163
00164
00165
00166 getRGBYsimple(iCap,rg,by,RGBYthresh);
00167
00168 rgp = rg; rgn = zero - rg;
00169 byp = by; byn = zero - by;
00170
00171 inplaceClamp(rgp, 0.0f,1.0f);
00172 inplaceClamp(rgn, 0.0f,1.0f);
00173 inplaceClamp(byp, 0.0f,1.0f);
00174 inplaceClamp(byn, 0.0f,1.0f);
00175
00176 #ifdef DOSTAIN
00177 cR = colorStain(Image<byte>(rgp*255.0f),colMin,colMax,COL_RED);
00178 cG = colorStain(Image<byte>(rgn*255.0f),colMin,colMax,COL_GREEN);
00179 cB = colorStain(Image<byte>(byp*255.0f),colMin,colMax,COL_BLUE);
00180 cY = colorStain(Image<byte>(byn*255.0f),colMin,colMax,COL_YELLOW);
00181 cCol = takeMax(takeMax(cR,cG),takeMax(cB,cY));
00182 xRD1.drawImage(cR); xGD1.drawImage(cG);
00183 xBD1.drawImage(cB); xYD1.drawImage(cY);
00184 xCD1.drawImage(cCol);
00185 #else
00186 xRD1.drawImage(rgp); xGD1.drawImage(rgn);
00187 xBD1.drawImage(byp); xYD1.drawImage(byn);
00188 #endif
00189
00190
00191 }
00192 manager.stop();
00193 }
00194
00195
00196
00197
00198
00199
00200
00201