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

X11LiveSourceTest.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 <X11LiveSourceTest.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--file <outfilename>  prefix of file name output\t\t\n");
00024     printf("\t--nodisplay           disable the allocation, opening or any use of a display.\n");
00025     printf("\t--test <value>        Run for <value> loops and then close test\n");
00026     printf("\n\n");
00027     
00028     exit(1);
00029 }
00030 
00031 /* ------------------------------------------------------------------------ */
00032 /* ------------------------------------------------------------------------ */
00033 int main(int argc, char *argv[] )
00034 {
00035     phFUNCTION("main")
00036 
00037     unsigned int    i           = 0;
00038 
00039     unsigned int        nDisplays   = 1;
00040     char                title[255];
00041     int                 displaysOpen= 1;
00042     phDisplayInterface  **display   = NULL;
00043 
00044     phImage             img;
00045 
00046     uint32_t            width   = 640;
00047     uint32_t            height  = 480;
00048 
00049     uint32_t            x = 0;
00050     char                filename[255];
00051 
00052     char                *filetype = "ppm";
00053     char                *outfilename = NULL;
00054     
00055     char        *capture_path   = NULL;
00056     int         channel         = 0;
00057         
00058 #ifdef WIN32
00059     VFWSource       *capture    = new VFWSource();
00060 #else
00061     V4LCapture      *capture    = new V4LCapture();
00062 #endif
00063         
00064     /* Utility class to ease the starting and stopping of displays, captures and
00065      * pipelines */
00066     phSystem        system;
00067    
00068     /* Remove the code below when using this code as an example.
00069      * 
00070      * This just checks whether "--test" has been specified with
00071      * a time value argument. It's for testing all the examples
00072      * without the need for human intervention. */
00073     int             test = 0;
00074 
00075     phArgTable      *arg_parser = new phArgTable();
00076 
00077     /* Setup and parse all the arguments */
00078     rc = arg_parser->add("--test",&test,phARG_INT);
00079     phCHECK_RC(rc,NULL,"arg_parser->add");
00080     rc = arg_parser->add("--file",&outfilename,phARG_CHAR);
00081     phCHECK_RC(rc,NULL,"arg_parser->add");
00082     rc = arg_parser->add("-f",&outfilename,phARG_CHAR);
00083     phCHECK_RC(rc,NULL,"arg_parser->add");
00084     rc = arg_parser->add("--nodisplay",&glbl_disable_displays,phARG_BOOL);
00085     phCHECK_RC(rc,NULL,"arg_parser->add");
00086     rc = arg_parser->add("--ndisplays",&nDisplays,phARG_INT);
00087     phCHECK_RC(rc,NULL,"arg_parser->add");
00088     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00089     phCHECK_RC(rc,NULL,"arg_parser->add");
00090     
00091     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00092     phCHECK_RC(rc,NULL,"arg_parser->add");
00093 
00094     rc = arg_parser->add("--channel",&channel,phARG_INT);
00095     phCHECK_RC(rc,NULL,"arg_parser->add");
00096     
00097     rc = arg_parser->parse(argc,argv);
00098     phCHECK_RC(rc,NULL,"arg_parser->parse");
00099  
00100     if (glbl_disable_displays) nDisplays = 0;
00101     
00102 
00103     capture->set(width,height,capture_path);
00104     //capture->setFormat(phImageBGRA32);
00105 #if 1
00106     capture->setChannel(channel);
00107     capture->setColour(35000);
00108     capture->setHue(35500);
00109     capture->setContrast(25000);
00110     capture->setBrightness(21000);
00111 #else
00112     capture->setChannel(channel);
00113     capture->setColour(57000);
00114     capture->setHue(34500);
00115     capture->setContrast(36000);
00116     capture->setBrightness(36000);
00117 #endif
00118  
00119     rc = system.addCapture(capture);
00120     phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00121 
00122     display = new phDisplayInterface *[nDisplays];
00123     phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];");
00124 
00125     for (i = 0; i < nDisplays; i++)
00126     {
00127         sprintf(title,"X11LiveSourceTest[%u]",i);
00128         
00129         display[i] = new X11Display(width,height,title);
00130         
00131         /* Set all parameters for the display so when the phSystem
00132          * starts them up, they are the desired size*/
00133         display[i]->setLiveSourceInput(capture->getLiveSourceOutput());
00134         
00135         rc = system.addDisplay(display[i]);
00136         phPRINT_RC(rc,NULL,"system.addDisplay(display[i])");
00137     }
00138 
00139     img.connect(capture->getLiveSourceOutput());
00140 
00141     /* startup */
00142     rc = system.startup();
00143     phPRINT_RC(rc,NULL,"system.startup()");
00144    
00145     displaysOpen = 1;
00146     while (displaysOpen)
00147     {
00148         /* Sleep a while, don't loop tightly */
00149 
00150         //phUSleep(100000);
00151         img.update();
00152 
00153         if (outfilename != NULL)
00154         {
00155             sprintf(filename,"output/%s%08u.%s",outfilename,x,filetype);
00156             
00157             img.save(filename);
00158             x++;
00159         }
00160         else
00161         {
00162             phMSleep(100);
00163         }
00164         
00165         /* Yielding is optional. This gives up the thread's timeslice
00166          * to prevent slow response in other threads. It consumes more
00167          * CPU cycles than sleeping. Use it instead of sleeping if
00168          * this loop is processing anything */
00169         
00170         /* phYield(); */
00171         
00172         if (nDisplays > 0)
00173         {   
00174             displaysOpen = 0;
00175             for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++)
00176             {
00177                 if (display[i]->isOpen() == 1)
00178                 {
00179                     displaysOpen = 1;
00180                 }
00181             }
00182         }
00183         
00184         /* Remove this if block when using this code as an example */
00185         /* Set the loop control value to end the loop when testing */
00186         if (test > 0)
00187         { 
00188             test--;
00189             if (test == 0)
00190                 displaysOpen = 0;
00191         }
00192     }
00193 
00194     rc = system.shutdown();
00195     phPRINT_RC(rc,NULL,"system.shutdown()");
00196 
00197 
00198 error:
00199     phDelete(capture);
00200 
00201     for (i = 0; (i < nDisplays) && (display != NULL); i++)
00202     {
00203         phDelete(display[i]);
00204     }
00205  
00206     phDeleteArray(display);
00207 
00208     phFree(outfilename);
00209     phFree(capture_path);
00210     phDelete(arg_parser);
00211 
00212     return phSUCCESS;
00213 }




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