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/GlobalOpts.H"
00037 #include "Component/ModelManager.H"
00038 #include "Component/ModelOptionDef.H"
00039 #include "Component/ModelParam.H"
00040 #include "Component/ModelParamBatch.H"
00041
00042 #include "Media/FrameSeries.H"
00043 #include "Transport/FrameIstream.H"
00044 #include "Raster/GenericFrame.H"
00045 #include "Media/MediaOpts.H"
00046 #include "Transport/FrameInfo.H"
00047 #include "Neuro/EnvSegmenterConfigurator.H"
00048 #include "Image/Image.H"
00049 #include "Image/Pixels.H"
00050 #include "Image/DrawOps.H"
00051 #include "Raster/Raster.H"
00052
00053 #include "SeaBee/SiftRec.H"
00054
00055 const ModelOptionCateg MOC_SIFTREC = {
00056 MOC_SORTPRI_2, "SiftRec Options" };
00057
00058 static const ModelOptionDef OPT_TrainingLabel =
00059 { MODOPT_ARG_STRING, "TrainingLabel", &MOC_SIFTREC, OPTEXP_CORE,
00060 "If this label is set, then the system goes into training mode, "
00061 "Traing all of the image with this label Whether to include an ",
00062 "training-label", '\0', "", "" };
00063
00064 static const ModelOptionDef OPT_TrainUnknown =
00065 { MODOPT_FLAG, "TrainUnknown", &MOC_SIFTREC, OPTEXP_CORE,
00066 "Wether to train all images with the label or just the unknown."
00067 "Note that with value of false, many more entries in the database will be entered.",
00068 "train-unknown", '\0', "", "true" };
00069
00070
00071
00072 int main(int argc, char* argv[])
00073 {
00074
00075 ModelManager mgr("SiftRec Tester");
00076
00077 OModelParam<bool> trainUnknown(&OPT_TrainUnknown, &mgr);
00078 OModelParam<std::string> trainingLabel(&OPT_TrainingLabel, &mgr);
00079
00080 nub::soft_ref<SiftRec> siftRec(new SiftRec(mgr));
00081 mgr.addSubComponent(siftRec);
00082
00083 nub::ref<EnvSegmenterConfigurator> esec(new EnvSegmenterConfigurator(mgr));
00084 mgr.addSubComponent(esec);
00085
00086
00087
00088 nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(mgr));
00089 mgr.addSubComponent(ifs);
00090
00091 nub::ref<OutputFrameSeries> ofs(new OutputFrameSeries(mgr));
00092 mgr.addSubComponent(ofs);
00093
00094 mgr.exportOptions(MC_RECURSE);
00095
00096 if (mgr.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00097
00098 mgr.start();
00099
00100 siftRec->initVDB();
00101
00102 nub::soft_ref<EnvSegmenter> seg = esec->getSeg();
00103
00104 while(true)
00105 {
00106 const FrameState is = ifs->updateNext();
00107 if (is == FRAME_COMPLETE) break;
00108
00109 GenericFrame input = ifs->readFrame();
00110 if (!input.initialized()) break;
00111 Image<PixRGB<byte> > img = input.asRgb();
00112
00113 Image<byte> foamask;
00114 Image<PixRGB<byte> > segmentdisp;
00115
00116 const Rectangle segRect = seg->getFoa(img, Point2D<int>(0,0),
00117 &foamask, &segmentdisp);
00118
00119 std::string objName;
00120 float score = 0;
00121 Rectangle matchRect;
00122 if (trainingLabel.getVal().size() > 0)
00123 {
00124
00125 if (trainUnknown.getVal())
00126 {
00127
00128 objName = siftRec->matchObject(img, score,matchRect);
00129 }
00130
00131 if (objName == "nomatch" || objName.size() == 0)
00132 {
00133 LINFO("Training with object name %s", trainingLabel.getVal().c_str());
00134 siftRec->trainObject(img, trainingLabel.getVal());
00135 }
00136 } else {
00137
00138 objName = siftRec->matchObject(img, score,matchRect);
00139
00140 }
00141
00142
00143 const std::string txt =
00144 sformat("%s:%0.2f", objName.c_str(), score);
00145 writeText(img, Point2D<int>(0,0),
00146 txt.c_str(),
00147 PixRGB<byte>(255), PixRGB<byte>(0));
00148
00149 if (matchRect.isValid() && img.rectangleOk(matchRect))
00150 {
00151 drawRect(img, matchRect, PixRGB<byte>(255, 255, 0), 1);
00152 drawCircle(img, matchRect.center(), 6, PixRGB<byte>(0,255,0));
00153 }
00154
00155 if (segRect.isValid() && img.rectangleOk(segRect))
00156 {
00157 drawRect(img, segRect, PixRGB<byte>(0, 255, 0), 1);
00158 }
00159
00160 ofs->writeRGB(img, "Input", FrameInfo("Input", SRC_POS));
00161 ofs->writeRGB(segmentdisp, "Seg", FrameInfo("Seg", SRC_POS));
00162 ofs->updateNext();
00163 }
00164
00165
00166
00167 mgr.stop();
00168 return 0;
00169 }
00170
00171
00172
00173
00174
00175