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

VFWSourceTest.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 <VFWSourceTest.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           Default to saving 30 frames.\n");
00021     printf("The following are valid only with the --test switch:\n");
00022     printf("\t--nimages <value> Save <value> number of images from capture.\n");
00023     printf("\t--cycle          Cycle through stop/start of the capture class every 3 seconds.\n");
00024     printf("\t                 This overloads the saving of 30 frames.\n");
00025     printf("\n\n");
00026 
00027     exit(1);
00028 }
00029 
00030 /* ------------------------------------------------------------------------ */
00031 int main(int argc, char *argv[] )
00032 {
00033     const char      *function   = "main";
00034     int             rc          = 0;
00035 
00036     uint32_t        width       = 640;
00037     uint32_t        height      = 480;
00038     
00039     phImage         image;
00040 
00041     int             i           = 0;
00042     int             nimages = 30;
00043     char            filename[255];
00044 
00045     int             displaysOpen= 1;
00046     VFWSource       capture;
00047     GDIDisplay      *display    = new GDIDisplay(width,height);
00048 
00049     int             cycle       = 0;
00050     int             cycle_count = 30;
00051         
00052     /* Utility class to ease the starting and stopping of displays, captures and
00053      * pipelines */
00054     phSystem        system;
00055    
00056     /* Remove the code below when using this code as an example.
00057      * 
00058      * This just checks whether "--test" has been specified with
00059      * a time value argument. It's for testing all the examples
00060      * without the need for human intervention. */
00061     int             test = 0;
00062 
00063     phArgTable      *arg_parser = new phArgTable();
00064 
00065     /* Setup and parse all the arguments */
00066     rc = arg_parser->add("--test",&test,phARG_BOOL);
00067     phCHECK_RC(rc,NULL,"arg_parser->add");
00068     rc = arg_parser->add("--nimages",(void *)&nimages,phARG_INT);
00069     phCHECK_RC(rc,NULL,"arg_parser->add");
00070     rc = arg_parser->add("--cycle",(void *)&cycle,phARG_BOOL);
00071     phCHECK_RC(rc,NULL,"arg_parser->add");
00072     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00073     phCHECK_RC(rc,NULL,"arg_parser->add");
00074     
00075     rc = arg_parser->parse(argc,argv);
00076     phCHECK_RC(rc,NULL,"arg_parser->parse");
00077 
00078     capture.set(width,height,"0");
00079     capture.setFormat(phImageRGB24);
00080 
00081     rc = system.addCapture(&capture);
00082     phPRINT_RC(rc,NULL,"system.addCapture(&capture)");
00083     
00084     memset(filename,0,255);
00085     
00086     rc = display->setInput(capture.getOutput());
00087     phCHECK_RC(rc,NULL,"display->setLiveSourceInput failed");
00088 
00089     rc = system.addDisplay(display);
00090     phPRINT_RC(rc,NULL,"system.add(display)");
00091 
00092     /* startup */
00093     rc = system.startup();
00094     phPRINT_RC(rc,NULL,"system.startup()");
00095    
00096     if (!capture.isOpen()) displaysOpen = 0;
00097 
00098     while (displaysOpen)
00099     {
00100         /* If it's not the test then we can read images and check to 
00101          * see if the display is still open */
00102         if ((test) && (cycle))
00103         {
00104             if (i < cycle_count)
00105             {
00106                 phMSleep(2000);
00107                 
00108                 i++;
00109 
00110                 phPRINT("Stopping capture device. (%d of %d)\n\n",
00111                         (i+1),cycle_count);
00112 
00113                 rc = system.stopCaptures();
00114                 phPRINT_RC(rc,NULL,"system.stopCaptures()");
00115 
00116                 phPRINT("Stopped capture class.\n\n");
00117 
00118                 phPRINT("Starting capture device. (%d of %d)\n\n",
00119                         i,cycle_count);
00120                         
00121                 rc = system.startCaptures();
00122                 phPRINT_RC(rc,NULL,"system.startCaptures()");
00123 
00124                 phPRINT("Started capture device.\n\n");
00125             }
00126             else
00127             {
00128                 displaysOpen = 0;
00129             }
00130         } 
00131         else if (test)
00132         {
00133             if (i == 0)
00134             {
00135                 printf("Saving frames:\t");
00136                 fflush(stdout);
00137 
00138                 rc = image.connect(capture.getOutput());
00139                 phCHECK_RC(rc,NULL,"image.connect failed");
00140             }
00141             if (image.update() == phLiveObjectUPDATED)
00142             {
00143                 /* If the image isn't NULL, then save it */
00144                 if (image.isNull() == 0)
00145                 {
00146                     sprintf(filename,"test_%d.ppm",i);
00147                     printf("%s, ",filename);
00148                     fflush(stdout);
00149 
00150                     image.save(filename);
00151                     i++;
00152 
00153                     /* If we're done saving images, then print the 
00154                      * last newline and disconnect the image. */
00155                     if (i > nimages)
00156                     {
00157                         printf("\n");
00158                         fflush(stdout);
00159 
00160                         rc = image.disconnect();
00161                         phPRINT_RC(rc,NULL,"image.disconnect()"); 
00162 
00163                         displaysOpen = 0;
00164                     }
00165                 }
00166             }
00167         }
00168         else
00169         {
00170             displaysOpen = 0;
00171             if (display->isOpen())
00172             {
00173                 phMSleep(200);
00174                 displaysOpen = 1;
00175             }
00176         }
00177     }
00178 
00179     rc = system.shutdown();
00180     phPRINT_RC(rc,NULL,"system.shutdown()");
00181 
00182 error:
00183 
00184     phDelete(display);
00185     phDelete(arg_parser);
00186 
00187     return phSUCCESS;
00188 }




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