test-ColorSegmenter.C

00001 
00002 
00003 
00004 #include "Component/ModelManager.H"
00005 
00006 #include "Media/FrameSeries.H"
00007 #include "Transport/FrameIstream.H"
00008 #include "Media/MediaOpts.H"
00009 
00010 #include "Image/Image.H"
00011 #include "Image/Pixels.H"
00012 #include "Raster/Raster.H"
00013 #include "Image/CutPaste.H"
00014 
00015 #include "BeoSub/IsolateColor.H"
00016 #include "Image/DrawOps.H"
00017 #include "Image/ColorOps.H"
00018 
00019 #include "GUI/XWinManaged.H"
00020 #include "SeaBee/PipeRecognizer.H"
00021 
00022 #include "ColorSegmenter.H"
00023 
00024 int main(const int argc, const char** argv)
00025 {
00026 
00027   MYLOGVERB = LOG_INFO;
00028 
00029   ModelManager manager("PipeRecognizer Tester");
00030 
00031   nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00032   manager.addSubComponent(ifs);
00033 
00034   manager.exportOptions(MC_RECURSE);
00035 
00036   // Parse command-line:
00037   if (manager.parseCommandLine(argc, argv,
00038                                "[image {*.ppm}]",
00039                                0, 1)
00040       == false) return(1);
00041 #ifndef HAVE_OPENCV
00042   LFATAL("I am useless because I was compiled without OpenCV support...");
00043 #else
00044   int w = ifs->getWidth(),  h = ifs->getHeight();
00045   std::string dims = convertToString(Dims(w, h));
00046   LINFO("image size: [%dx%d]", w, h);
00047   manager.setOptionValString(&OPT_InputFrameDims, dims);
00048 
00049   manager.setModelParamVal("InputFrameDims", Dims(w, h),
00050                            MC_RECURSE | MC_IGNORE_MISSING);
00051 
00052   manager.start();
00053 
00054   bool goforever = true;
00055 
00056   rutz::shared_ptr<XWinManaged> dispWin;
00057   dispWin.reset(new XWinManaged(Dims(w*2,h*2), 0, 0, "Pipe Recognizer Display"));
00058 
00059   // input and output image
00060 
00061   Image< PixRGB<byte> > img(w,h, ZEROS);
00062 
00063 //   rutz::shared_ptr<Image<byte> > orangeIsoImage;
00064 //   orangeIsoImage.reset(new Image<byte>(w,h, ZEROS));
00065 
00066   //  rutz::shared_ptr<Image< PixRGB<byte> > > outputImg(new Image<PixRGB<byte> >(w,h, ZEROS));
00067 
00068   rutz::shared_ptr<PipeRecognizer> pipeRecognizer(new PipeRecognizer());
00069   rutz::shared_ptr<Point2D<int> > pipeCenter(new Point2D<int>(0,0));
00070 
00071   Point2D<int> projPoint(Point2D<int>(0,0));
00072   rutz::shared_ptr<double> pipeAngle(new double);
00073 
00074 
00075   //create a colorsegmeter class to test it
00076   ColorSegmenter colorSegmenter;
00077   colorSegmenter.setupColorSegmenter("Orange",false);//color,debug
00078   uint fNum = 0;
00079   while(goforever)
00080     {
00081       Image< PixRGB<byte> > dispImg(w*2,h*2, ZEROS);
00082       rutz::shared_ptr<Image< PixRGB<byte> > > outputImg(new Image<PixRGB<byte> >(w,h, ZEROS));
00083 
00084       rutz::shared_ptr<Image<byte> > orangeIsoImage;
00085       orangeIsoImage.reset(new Image<byte>(w,h, ZEROS));
00086 
00087       ifs->updateNext(); img = ifs->readRGB();
00088       if(!img.initialized()) {Raster::waitForKey(); break; }
00089 
00090       inplacePaste(dispImg, img, Point2D<int>(0,0));
00091 
00092       orangeIsoImage->resize(w,h);
00093       isolateOrange(img, *orangeIsoImage);
00094       inplacePaste(dispImg, toRGB(*orangeIsoImage), Point2D<int>(w,h));
00095 
00096 
00097         //try calling the colorsegmenter class
00098       colorSegmenter.isolateOrange(img, *orangeIsoImage);
00099       inplacePaste(dispImg, toRGB(*orangeIsoImage), Point2D<int>(w,0));
00100 
00101 //       pipeRecognizer->getPipeLocation(orangeIsoImage,
00102 //                                       outputImg,
00103 //                                       PipeRecognizer::HOUGH,
00104 //                                       pipeCenter,
00105 //                                       pipeAngle);
00106 
00107       projPoint.i = (int)(pipeCenter->i+30*cos(*pipeAngle));
00108       projPoint.j = (int)(pipeCenter->j+30*sin(*pipeAngle));
00109 
00110       drawLine(*outputImg, *pipeCenter, projPoint, PixRGB <byte> (255, 255,0), 3);
00111 
00112       inplacePaste(dispImg, *outputImg, Point2D<int>(0,h));
00113 
00114       dispWin->drawImage(dispImg, 0, 0);
00115       LINFO("%d",fNum); fNum++;
00116 
00117       //wait a little
00118       Raster::waitForKey();
00119     }
00120 #endif
00121 
00122   // get ready to terminate:
00123   manager.stop();
00124   return 0;
00125 }
Generated on Sun May 8 08:40:20 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3