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

X11MultiCapPipelineTest.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 <X11MultiCapPipelineTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 
00018 /* Connect multiple pipelines to multiple capture devices.
00019  * Connect multiple displays to pipelines and captures. */
00020 
00021 /* ------------------------------------------------------------------------ */
00022 int usage ()
00023 {
00024     printf("\n\nUsage:\n");
00025     printf("\t--help            Display usage\n");
00026     printf("\t--nodisplay       Disable the allocation, opening or any use of a display.\n");
00027     printf("\t--test <value>    Sleep 'value' seconds and then close test\n");
00028     printf("\n\n");
00029     exit(1);
00030 }
00031         
00032 /* ------------------------------------------------------------------------ */
00033 int main(int argc, char *argv[] )
00034 {
00035     phFUNCTION("main")
00036 
00037     uint32_t        i = 0;
00038 
00039     /* CAPTURE ------------------------------------------------------------ */
00040     uint32_t        nCaptures   = 4;
00041     char            device[255];
00042 #ifdef WIN32
00043     VFWSource       *capture[nCaptures];
00044 #else
00045     V4LCapture      *capture[nCaptures];
00046 #endif
00047 
00048     uint32_t        width = 320;
00049     uint32_t        height = 240;
00050 
00051     char        *capture_path   = NULL;
00052     int         channel         = 0;
00053         
00054     /* PIPIELINE AND FILTERS ---------------------------------------------- */
00055     uint32_t        nPipelines  = 2;
00056     phPipeline      *pipelines[nPipelines];
00057     uint32_t        format      = phImageRGB24;
00058 
00059     sobel_Filter    *sobels[nPipelines];
00060     phFilter        *gauss[nPipelines];
00061     phFilter        *mean[nPipelines];
00062     phFilter        *median[nPipelines];
00063     
00064     /* DISPLAYS ----------------------------------------------------------- */
00065     uint32_t            nDisplays   = nPipelines + nCaptures;
00066     int                 displaysOpen= 1;
00067     char                title[255];
00068     phDisplayInterface  **display = NULL;
00069     
00070     /* Utility class to ease the starting and stopping of displays, captures and
00071      * pipelines */
00072     phSystem        system;
00073    
00074     /* Remove the code below when using this code as an example.
00075      * 
00076      * This just checks whether "--test" has been specified with
00077      * a time value argument. It's for testing all the examples
00078      * without the need for human intervention. */
00079     int             test = 0;
00080 
00081     phArgTable      *arg_parser = new phArgTable();
00082 
00083     rc = arg_parser->add("--test",&test,phARG_INT);
00084     phCHECK_RC(rc,NULL,"arg_parser->add");
00085     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
00086     phCHECK_RC(rc,NULL,"arg_parser->add");
00087     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00088     phCHECK_RC(rc,NULL,"arg_parser->add");
00089     
00090     rc = arg_parser->parse(argc,argv);
00091     phCHECK_RC(rc,NULL,"arg_parser->parse");
00092     
00093     if (glbl_disable_displays) nDisplays = 0;
00094     
00095 
00096     /* SETUP ROUTINES ----------------------------------------------------- */
00097     for (i = 0; i < nCaptures; i++ )
00098     {   
00099         
00100 #ifdef WIN32
00101         sprintf(device,"%d",i);
00102         capture[i] = new VFWSource();
00103 #else
00104         sprintf(device,"/dev/video%u",i);
00105         capture[i] = new V4LCapture();
00106 #endif
00107         
00108         capture[i]->set(width,height,device);
00109         capture[i]->setChannel(channel);
00110         capture[i]->setBrightness(20000);
00111 
00112         rc = system.addCapture(capture[i]);
00113         phPRINT_RC(rc,NULL,"system.addCapture(capture[%u])",i);
00114     }
00115     
00116     for (i = 0; i < nPipelines; i++)
00117     {
00118         pipelines[i] = new phPipeline();
00119         
00120         /* TODO: This causes a BUG; */
00121         /* if (i < nCaptures && 0) */
00122         if (i < nCaptures)
00123         {
00124             pipelines[i]->setLiveSourceInput(capture[i]->getLiveSourceOutput());
00125             format = capture[i]->getFormat();
00126         }
00127         else if (nCaptures > 0) /* Make sure there is a capture to retrieve from */
00128         {
00129             format = capture[nCaptures-1]->getFormat();
00130         }
00131         else /* default not gauranteed to be correct */
00132         {
00133             format = phImageRGB24;
00134         }
00135         
00136         /* use the optimized version, this really should be done internally */
00137         if (format & (phImageRGB24 | phImageRGBA32))
00138         {
00139             gauss[i] = new gaussian3x3_Filter();
00140             mean[i] = new meanNxN_Filter(3);
00141             median[i] = new medianBlur_Filter(3);
00142         }
00143         else
00144         {
00145             gauss[i] = new gaussianBlur_Filter();
00146             mean[i] = new meanBlur_Filter(3);
00147             median[i] = new medianBlur_Filter(3);
00148         }
00149         sobels[i] = new sobel_Filter();
00150 
00151         pipelines[i]->add(gauss[i]);
00152         pipelines[i]->add(mean[i]);
00153         pipelines[i]->add(median[i]);
00154         pipelines[i]->add(sobels[i]);
00155 
00156         rc = system.addPipeline(pipelines[i]);
00157         phPRINT_RC(rc,NULL,"system.addPipeline(pipelines[%u])",i);
00158     }
00159     
00160     display = new phDisplayInterface *[nDisplays];
00161     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00162 
00163     for (i = 0; i < nDisplays; i++)
00164     {
00165         sprintf(title,"X11MultiCapPipelineTest[%u]",i);
00166         
00167         display[i] = new X11Display(width,height,title);
00168 
00169         rc = system.addDisplay(display[i]);
00170         phPRINT_RC(rc,NULL,"system.addDisplay(display[%d])",i);
00171        
00172         /* Connect the lower indexed displays to the pipeline output */
00173         /* Connect displays to pipeline outputs */
00174         if (i < nPipelines)
00175             display[i]->setLiveSourceInput(pipelines[i]->getLiveSourceOutput());
00176         /* Connect displays to capture outputs */
00177         else if (( i >= nPipelines ) && ((i - nPipelines) > nCaptures))            
00178             display[i]->setLiveSourceInput(capture[i - nPipelines]->getLiveSourceOutput());
00179     }
00180     
00181 
00182     /* startup */
00183     rc = system.startup();
00184     phPRINT_RC(rc,NULL,"system.startup()");
00185     
00186     displaysOpen = 1;
00187     while (displaysOpen)
00188     {
00189         /* Sleep a while, don't loop tightly */
00190 
00191         phMSleep(100);
00192         
00193         /* Yielding is optional. This gives up the thread's timeslice
00194          * to prevent slow response in other threads. It consumes more
00195          * CPU cycles than sleeping. Use it instead of sleeping if
00196          * this loop is processing anything */
00197         
00198         /* phYield(); */
00199         
00200         if (nDisplays > 0)
00201         {
00202             displaysOpen = 0;
00203             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00204             {
00205                 if (display[i]->isOpen() == 1)
00206                 {
00207                     displaysOpen = 1;
00208                 }
00209             }
00210         }
00211         
00212         /* Remove this if block when using this code as an example */
00213         /* Set the loop control value to end the loop when testing */
00214         if (test > 0)
00215         { 
00216             displaysOpen = 0;
00217             phSleep(test); /* test's value should be a time (in secs) value > 0*/
00218         }
00219     }
00220 
00221     rc = system.shutdown();
00222     phPRINT_RC(rc,NULL,"system.shutdown()");
00223     
00224 
00225 error:
00226     for (i = 0; i < nCaptures; i++)
00227     {
00228         phDelete(capture[i]);
00229     }
00230 
00231     for (i = 0; i < nPipelines; i++)
00232     {
00233         phDelete(pipelines[i]);
00234         phDelete(gauss[i]);
00235         phDelete(mean[i]);
00236         phDelete(median[i]);
00237         phDelete(sobels[i]);
00238     }
00239 
00240     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00241     {
00242         phDelete(display[i]);
00243     }
00244  
00245     phDeleteArray(display);
00246 
00247     phFree(capture_path);
00248     phDelete(arg_parser);
00249 
00250     return phSUCCESS;
00251 }




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:08 2007 for phission by  doxygen 1.4.4