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

SDLLiveSourceTest.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 <SDLLiveSourceTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int usage ()
00017 {
00018     printf("\n\nUsage:\n");
00019     printf("\t--help            Display usage\n");
00020     printf("\t--test <value>    Sleep <value> seconds and then close test\n");
00021     printf("\n\n");
00022     exit(1);
00023 }
00024         
00025 /* ------------------------------------------------------------------------ */
00026 int main(int argc, char *argv[] )
00027 {
00028     phFUNCTION("main")
00029 
00030     char        *capture_path   = NULL;
00031     int         channel         = 0;
00032         
00033     uint32_t    width = 320;
00034     uint32_t    height = 240;
00035     
00036     int         displaysOpen= 1;
00037     SDLDisplay  *display    = NULL;
00038 #ifdef WIN32
00039     VFWSource   *capture = new VFWSource();
00040 #else
00041     V4LCapture  *capture = new V4LCapture();
00042 #endif
00043         
00044     /* Utility class to ease the starting and stopping of displays, captures and
00045      * pipelines */
00046     phSystem    system;
00047    
00048     /* Remove the code below when using this code as an example.
00049      * 
00050      * This just checks whether "--test" has been specified with
00051      * a time value argument. It's for testing all the examples
00052      * without the need for human intervention. */
00053     int             test = 0;
00054 
00055     phArgTable      *arg_parser = new phArgTable();
00056 
00057     rc = arg_parser->add("--test",&test,phARG_INT);
00058     phCHECK_RC(rc,NULL,"arg_parser->add");
00059     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00060     phCHECK_RC(rc,NULL,"arg_parser->add");
00061     
00062     rc = arg_parser->add("--path",&capture_path,phARG_CHAR);
00063     phCHECK_RC(rc,NULL,"arg_parser->add");
00064 
00065     rc = arg_parser->add("--channel",&channel,phARG_INT);
00066     phCHECK_RC(rc,NULL,"arg_parser->add");
00067     
00068     rc = arg_parser->parse(argc,argv);
00069     phCHECK_RC(rc,NULL,"arg_parser->parse");
00070     
00071     /* Set up the capture device */
00072     capture->set(width,height,capture_path);
00073 #if 1
00074     capture->setChannel(channel);
00075     capture->setColour(65000);
00076     capture->setHue(65500);
00077     capture->setContrast(31000);
00078     capture->setBrightness(29000);
00079 #else
00080     capture->setChannel(channel);
00081     capture->setColour(35000);
00082     capture->setHue(35500);
00083     capture->setContrast(31000);
00084     capture->setBrightness(35000);
00085 #endif
00086     capture->setFormat(phImageBGRA32);
00087 
00088     rc = system.addCapture(capture);
00089     phPRINT_RC(rc,NULL,"system.addCapture(capture)");
00090     
00091     display    = new SDLDisplay(width,height,"SDLLiveSourceTest");
00092  
00093     display->setLiveSourceInput(capture->getLiveSourceOutput());
00094 
00095     rc = system.addDisplay(display);
00096     phPRINT_RC(rc,NULL,"system.addDisplay(display)");
00097             
00098 
00099     /* startup */
00100     rc = system.startup();
00101     phPRINT_RC(rc,NULL,"system.startup()");
00102    
00103     while (displaysOpen)
00104     {
00105         /* Sleep a while, don't loop tightly */
00106 
00107         phMSleep(100);
00108         
00109         /* Yielding is optional. This gives up the thread's timeslice
00110          * to prevent slow response in other threads. It consumes more
00111          * CPU cycles than sleeping. Use it instead of sleeping if
00112          * this loop is processing anything */
00113         
00114         /* phYield(); */
00115         
00116         displaysOpen = 0;
00117         if (display->isOpen())
00118         {
00119             displaysOpen = 1;
00120         }
00121         
00122         /* Remove this if block when using this code as an example */
00123         /* Set the loop control value to end the loop when testing */
00124         if (test > 0)
00125         { 
00126             displaysOpen = 0;
00127             phSleep(test); /* test's value should be a time (in secs) value > 0*/
00128         }
00129     }
00130 
00131     rc = system.shutdown();
00132     phPRINT_RC(rc,NULL,"system.shutdown()");
00133 
00134 
00135 error:
00136     phDelete(display);
00137     phDelete(capture);
00138     
00139     phFree(capture_path);
00140     phDelete(arg_parser);
00141 
00142     return phSUCCESS;
00143 }




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