Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MotionBlobThreshConvertTest.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission : 
00003         Realtime Vision Processing System
00004     
00005     Copyright (C) 2003 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008     
00009     This file is part of Phission.
00010 
00011  ---------------------------------------------------------------------------*/
00012 #include <MotionBlobThreshConvertTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 
00018 /* ------------------------------------------------------------------------ */
00019 void usage()
00020 {
00021     printf("\n\nUsage:\n");
00022     printf("\t--help            Display usage\n");
00023     printf("\t--nodisplay       Disable the allocation, opening or any use of a display.\n");
00024     printf("\t--test <count>    Loops <count> times\n");
00025     printf("\n\n");
00026     exit(1);
00027 }
00028 
00029 /* ------------------------------------------------------------------------ */
00030 int main(int argc, char *argv[] )
00031 {
00032     phFUNCTION("main")
00033 
00034     unsigned int    i           = 0;
00035 
00036     unsigned int        nDisplays   = 2;
00037     int                 displaysOpen= 1;
00038     char                title[255];
00039     phDisplayInterface  **display   = NULL;
00040     
00041     char            *capture_path   = NULL;
00042     int             channel         = 0;
00043     
00044 #ifdef WIN32
00045     VFWSource           *capture        = new VFWSource();
00046 #else
00047     V4LCapture          *capture        = new V4LCapture();
00048 #endif
00049     
00050     phPipeline          *pipeline       = new phPipeline();
00051 
00052     phColor             incolor_limit   = phColorGREY8_new(255);
00053     phColor             threshold_limit = phColorGREY8_new(0);
00054     phColor             outcolor_limit  = phColorRGB24_new(255,0,0);
00055     phBlobData          blob_data;
00056     blob_Filter         *blob           = new blob_Filter();
00057     
00058     gaussianBlur_Filter *gauss          = new gaussianBlur_Filter();
00059     meanBlur_Filter     *mean           = new meanBlur_Filter();
00060     convert_Filter      *convert        = new convert_Filter(phImageGREY8);
00061     threshold_Filter    *threshold      = new threshold_Filter(0,20);
00062     subtract_Filter     *sub            = new subtract_Filter(3,3);
00063     add_Filter          *add            = new add_Filter(2,2);
00064     ddimage_Filter      *ddimg          = new ddimage_Filter();
00065     /*
00066 #if PH_HAVE_OPENCV
00067     cv_canny_Filter *canny              = new cv_canny_Filter(50,105);
00068 #else
00069     canny_Filter    *canny              = new canny_Filter(50,105);
00070 #endif
00071      */
00072 
00073     /* Utility class to ease the starting and stopping of displays, captures and
00074      * pipelines */
00075     phSystem            *system         = new phSystem();
00076    
00077     /* Remove the code below when using this code as an example.
00078      * 
00079      * This just checks whether "--test" has been specified with
00080      * a time value argument. It's for testing all the examples
00081      * without the need for human intervention. */
00082     int             test            = 0;
00083 
00084     phArgTable *arg_parser = new phArgTable();
00085 
00086     rc = arg_parser->add("--test", &test, phARG_INT);
00087     phCHECK_RC(rc,NULL,"arg_parser->add");
00088 
00089     rc = arg_parser->add("--nodisplay", (void *)&glbl_disable_displays, phARG_BOOL);
00090     phCHECK_RC(rc,NULL,"arg_parser->add");
00091 
00092     rc = arg_parser->add("--help",(void *)&usage, phARG_FUNC);
00093     phCHECK_RC(rc,NULL,"arg_parser->add");
00094 
00095     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00096     phCHECK_RC(rc,NULL,"arg_parser->add");
00097 
00098     rc = arg_parser->add("--channel",&channel,phARG_INT);
00099     phCHECK_RC(rc,NULL,"arg_parser->add");
00100     
00101     rc = arg_parser->parse(argc,argv);
00102     phCHECK_RC(rc,NULL,"arg_parser->parse");
00103 
00104     if (glbl_disable_displays) nDisplays = 0;
00105     
00106     /* <>) Setup the capture device parameters */
00107     capture->set(320,240,capture_path);
00108     capture->setChannel(channel);
00109 
00110     rc = system->addCapture(capture);
00111     phPRINT_RC(rc,NULL,"system->addCapture(capture)");
00112         
00113     display = new phDisplayInterface *[nDisplays];
00114     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00115     
00116     for (i = 0; i < nDisplays; i++ )
00117     {
00118         sprintf(title,"MotionBlobThreshConvertTest[%u]",i);
00119         
00120 #ifdef WIN32
00121         display[i] = new GDIDisplay(320,240,title);
00122 #else
00123         display[i] = new X11Display(320,240,title);
00124 #endif
00125 
00126         rc = system->addDisplay(display[i]);
00127         phPRINT_RC(rc,NULL,"system->addDisplay(display[i:%d])",i);
00128     }
00129     
00130     rc = system->addPipeline(pipeline);
00131     phPRINT_RC(rc,NULL,"system->addPipeline(pipeline)");
00132     
00133 
00134     /* <> Attach the displays to the live sources */
00135     /* Capture -> (b)phPipeline -> (a)Processed Output Display */
00136     
00137     /* <> Attach the Pipeline output image to the display so the
00138      * display updates when a processing has been completed
00139      * for each loop */
00140     if (nDisplays > 0)
00141         display[0]->setLiveSourceInput(pipeline->getLiveSourceOutput());
00142     if (nDisplays > 1)
00143         display[1]->setLiveSourceInput(capture->getLiveSourceOutput());
00144     
00145     /* <> Attach the capture image to the live source input of the
00146      * Pipeline so processing is done automatically once the 
00147      * pipeline is started. */
00148     pipeline->setLiveSourceInput(capture->getLiveSourceOutput());
00149     
00150     /* <> Add the filter(s) into the pipeline in the order they will 
00151      * be used */
00152     /* pipeline->add(canny); */
00153     pipeline->add(convert);
00154     //pipeline->add(gauss);
00155     //pipeline->add(gauss);
00156     //pipeline->add(gauss);
00157     pipeline->add(gauss);
00158     //pipeline->add(mean);
00159     //pipeline->add(mean);
00160     //pipeline->add(sub);
00161     //pipeline->add(add);
00162     pipeline->add(ddimg);
00163     pipeline->add(threshold);
00164     
00165     blob->set(&incolor_limit,&threshold_limit,1,&outcolor_limit,1,1);
00166     pipeline->add(blob);
00167 
00168     rc = blob_data.connect(blob->getLiveBlobOutput());
00169     phPRINT_RC(rc,NULL,"blob_data.connect()");
00170 
00171     /* <> Startup the system */
00172     rc = system->startup();
00173     phPRINT_RC(rc,NULL,"system->startup()");
00174     
00175     /* <> Keep going until all the windows are closed */
00176     displaysOpen = 1;
00177     while (displaysOpen)
00178     {
00179         /* Yielding is optional. This gives up the thread's timeslice
00180          * to prevent slow response in other threads. It consumes more
00181          * CPU cycles than sleeping. Use it instead of sleeping if
00182          * this loop is processing anything */
00183         phMSleep(10);
00184         //phYield();
00185         
00186         if ((rc = blob_data.update()) == phLiveObjectUPDATED)
00187         {
00188             //blob_data.print_data(300);
00189         } 
00190         else
00191         {
00192             phPRINT_RC(rc,NULL,"blob_data.update()");
00193         }
00194         
00195         if (nDisplays > 0)
00196         {
00197             displaysOpen = 0;
00198             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00199             {
00200                 if (display[i]->isOpen() == 1)
00201                 {
00202                     displaysOpen = 1;
00203                 }
00204             }
00205         }
00206 
00207         /* Remove this if block when using this code as an example */
00208         /* Set the loop control value to end the loop when testing */
00209         if (test > 0)
00210         { 
00211             test--;
00212             if (test == 0)
00213                 displaysOpen = 0;
00214             else
00215                 phSleep(1); /* test's value should be a time (in secs) value > 0*/
00216         }
00217     }
00218     /* <> Shutdown the system */
00219     rc = system->shutdown();
00220     phPRINT_RC(rc,NULL,"system->shutdown()");
00221 
00222 error:
00223     rc = blob_data.disconnect();
00224     phPRINT_RC(rc,NULL,"blob_data.disconnect()");
00225     
00226     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00227     {
00228         phDelete(display[i]);
00229     }
00230   
00231     phDeleteArray(display);
00232 
00233     phDelete(capture);
00234     
00235     phDelete(sub);
00236     phDelete(add);
00237     phDelete(convert);
00238     phDelete(threshold);
00239     phDelete(mean);
00240     phDelete(gauss);
00241     phDelete(blob);
00242     phDelete(ddimg);
00243   
00244     phDelete(pipeline);
00245 
00246     phDelete(system);
00247 
00248     phFree(capture_path);
00249     phDelete(arg_parser);
00250 
00251     return phSUCCESS;
00252 }




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:06 2007 for phission by  doxygen 1.4.4