test-world1.C
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 #include "Component/ModelManager.H"
00037 #include "Media/FrameSeries.H"
00038 #include "Transport/FrameInfo.H"
00039 #include "Raster/GenericFrame.H"
00040 #include "Image/Image.H"
00041 #include "Image/ImageSet.H"
00042 #include "Image/DrawOps.H"
00043 #include "Image/ShapeOps.H"
00044 #include "Image/Layout.H"
00045 #include <math.h>
00046 #include <stdlib.h>
00047 #include "ObjRec/ObjRec.H"
00048 #include "GUI/ImageDisplayStream.H"
00049 #include "GUI/XWinManaged.H"
00050
00051 int main(const int argc, const char **argv)
00052 {
00053 MYLOGVERB = LOG_INFO;
00054 ModelManager *mgr = new ModelManager("Test ObjRec");
00055
00056 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(*mgr));
00057 mgr->addSubComponent(ofs);
00058
00059 nub::ref<InputFrameSeries> ifs(new InputFrameSeries(*mgr));
00060 mgr->addSubComponent(ifs);
00061
00062 nub::ref<ObjRec> objRec(new ObjRec(*mgr));
00063 mgr->addSubComponent(objRec);
00064
00065 mgr->exportOptions(MC_RECURSE);
00066
00067 if (mgr->parseCommandLine(
00068 (const int)argc, (const char**)argv, "", 0, 0) == false)
00069 return 1;
00070 mgr->start();
00071
00072
00073 ifs->updateNext();
00074
00075 GenericFrame input = ifs->readFrame();
00076 Image<PixRGB<byte> > worldImg = rescale(input.asRgb(), 256, 256);
00077 objRec->setImageDims(worldImg.getDims());
00078
00079
00080 while(0)
00081 {
00082
00083 double prob = objRec->predictWorld(worldImg);
00084 Image<PixRGB<byte> > worldPredictImg = objRec->getWorldPredictImage();
00085
00086 worldPredictImg += worldImg;
00087
00088 LINFO("World prob %f", prob);
00089
00090
00091 Layout<PixRGB<byte> > outDisp;
00092 outDisp = vcat(outDisp, hcat(worldImg, worldPredictImg));
00093
00094 Image<PixRGB<byte> > msgImg(worldImg.getWidth()*2, 20, ZEROS);
00095 char msg[255];
00096 sprintf(msg, "World p=%0.2e", prob);
00097 writeText(msgImg, Point2D<int>(0,0), msg, PixRGB<byte>(255), PixRGB<byte>(127));
00098 outDisp = vcat(outDisp, msgImg);
00099
00100 ofs->writeRgbLayout(outDisp, "Result", FrameInfo("Result", SRC_POS));
00101 }
00102
00103 double angle = 45;
00104 double length = 50;
00105 bool run = false;
00106 while(1)
00107 {
00108
00109
00110 const nub::soft_ref<ImageDisplayStream> ids =
00111 ofs->findFrameDestType<ImageDisplayStream>();
00112
00113 const rutz::shared_ptr<XWinManaged> uiwin =
00114 ids.is_valid()
00115 ? ids->getWindow("world")
00116 : rutz::shared_ptr<XWinManaged>();
00117
00118
00119 if (uiwin.is_valid())
00120 {
00121
00122 int key = uiwin->getLastKeyPress();
00123 if (key == 98) angle++;
00124 if (key == 104) angle--;
00125
00126 if (key == 100) length++;
00127 if (key == 102) length--;
00128
00129 if (key == 27) run=!run;
00130
00131 if (key != -1)
00132 LINFO("Length %f angle %f key %i", length, angle, key);
00133
00134 Point2D<int> pos = uiwin->getLastMouseClick();
00135 if (pos.isValid())
00136 {
00137 double prob = objRec->evalLikelihood(worldImg, pos, angle, length);
00138 LINFO("Prob %f", prob);
00139 }
00140 }
00141
00142 if (run)
00143 objRec->evalLikelihood(worldImg, Point2D<int>(0,0), angle, length);
00144
00145 Image<PixRGB<byte> > worldPredictImg = objRec->getWorldPredictImage();
00146
00147 if (worldPredictImg.initialized())
00148 worldPredictImg += worldImg;
00149 else
00150 worldPredictImg = worldImg;
00151
00152 ofs->writeRGB(worldImg, "world", FrameInfo("world", SRC_POS));
00153 ofs->writeRGB(worldPredictImg, "predict", FrameInfo("predict", SRC_POS));
00154
00155
00156 }
00157
00158
00159
00160 mgr->stop();
00161
00162 exit(0);
00163
00164 }
00165
00166