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

phImageReadLoopTest.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 <phImageReadLoopTest.h>
00013 #include <phission.h>
00014 
00015 /* ------------------------------------------------------------------------ */
00016 int glbl_disable_displays = 0;
00017 int glbl_preload_images = 1;
00018 
00019 /* ------------------------------------------------------------------------ */
00020 int usage()
00021 {
00022     printf("\n\n Usage:\n");
00023     printf("\t--help\t\t\tdisplay this usage message.\n\n");
00024     printf("\t--count <nfiles>     \twhere nfiles is the number of files to read\n\n");
00025     printf("\t--file  <path-prefix>\tfile names of the format file_0000.???\n");
00026     printf("\t                     \twhere ??? is ppm or jpg.\n");
00027     printf("\t                     \tEx. \"--file file --count 1\"\n\n");
00028     printf("\t--type <file-type>   \tjpg or ppm\n\n");
00029     printf("\t--nodisplay\tdisable the allocation, opening or any use of a display.\n\n");
00030     printf("\t--test <value>       Loop through <value> frames/files/images\n");
00031     printf("\n\n");
00032     exit(1);
00033 }
00034 
00035 /* ------------------------------------------------------------------------ */
00036 int main(int argc, char *argv[] )
00037 {
00038     phFUNCTION("main")
00039 
00040     phImage         image;
00041 
00042     int             displaysOpen= 1;
00043     
00044     unsigned int    i           = 0;
00045     unsigned int    image_count = 1;
00046     char            *prefix     = NULL;
00047     char            *prefixarg  = NULL;
00048     char            *type       = NULL;
00049     char            *typearg    = NULL;
00050     char            filename[255];
00051     phImage         *input_images = NULL;
00052 
00053     phDisplayInterface *display = NULL;
00054     
00055     /* Utility class to ease the starting and stopping of displays, captures and
00056      * pipelines */
00057     phSystem        system;
00058    
00059     /* Remove the code below when using this code as an example.
00060      * 
00061      * This just checks whether "--test" has been specified with
00062      * a time value argument. It's for testing all the examples
00063      * without the need for human intervention. */
00064     int             test = 0;
00065 
00066     phArgTable      *arg_parser = new phArgTable();
00067 
00068     /* Setup and parse all the arguments */
00069     rc = arg_parser->add("--test",&test,phARG_INT);
00070     phCHECK_RC(rc,NULL,"arg_parser->add");
00071     rc = arg_parser->add("--count",&image_count,phARG_UINT);
00072     phCHECK_RC(rc,NULL,"arg_parser->add");
00073     rc = arg_parser->add("--file",&prefixarg,phARG_CHAR);
00074     phCHECK_RC(rc,NULL,"arg_parser->add");
00075     rc = arg_parser->add("--type",&typearg,phARG_CHAR);
00076     phCHECK_RC(rc,NULL,"arg_parser->add");
00077     rc = arg_parser->add("--nodisplay",(void *)&glbl_disable_displays,phARG_BOOL);
00078     phCHECK_RC(rc,NULL,"arg_parser->add");
00079     rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC);
00080     phCHECK_RC(rc,NULL,"arg_parser->add");
00081     
00082     rc = arg_parser->parse(argc,argv);
00083     phCHECK_RC(rc,NULL,"arg_parser->parse");
00084     
00085     if (prefixarg == NULL)
00086     {
00087         prefix = "../images/thisisatest";
00088         image_count = 2;
00089     }
00090     else
00091     {
00092         prefix = prefixarg;
00093     }
00094 
00095     if (typearg == NULL)
00096     {
00097         type = "ppm";
00098     }
00099     else
00100     {
00101         type = typearg;
00102     }
00103    
00104     input_images = new phImage[image_count];
00105 
00106     if (glbl_preload_images == 1)
00107     {
00108         for (i = 0; i < image_count; i++ )
00109         {
00110             /* Get the files from V4LCaptureTest */
00111             sprintf(filename,"%s_%04u.%s",prefix,i,type);
00112             
00113             rc = input_images[i].load(filename);
00114             phPRINT_RC(rc,NULL,"image loading failed");
00115         }
00116     }
00117     
00118 
00119     if (glbl_disable_displays == 0)
00120     {
00121 #if defined(PH_HAVE_X11)
00122         display = new X11Display(320,240,"phImageReadLoopTest");
00123 #else
00124         display = new GDIDisplay(320,240,"phImageReadLoopTest");
00125 #endif
00126         
00127         /* Link the image to the display. Loading a new image
00128          * will generate a live source signal */
00129         display->setLiveSourceInput(&image);
00130         
00131         rc = system.addDisplay(display);
00132         phPRINT_RC(rc,NULL,"system.addDisplay(display)");
00133     }
00134     
00135 
00136     /* startup */
00137     rc = system.startup();
00138     phPRINT_RC(rc,NULL,"system.startup()");
00139    
00140     printf("Cycling through frames\n");
00141     fflush(stdout);
00142    
00143     i = 0;
00144     while (displaysOpen)
00145     {
00146         /* Sleep a while, don't loop tightly */
00147         
00148         /* phMSleep(100); */
00149         
00150         /* Yielding is optional. This gives up the thread's timeslice
00151          * to prevent slow response in other threads. It consumes more
00152          * CPU cycles than sleeping. Use it instead of sleeping if
00153          * this loop is processing anything */
00154         
00155         phYield();
00156         
00157         if (glbl_preload_images == 0)
00158         {
00159             /* Get the files from V4LCaptureTest */
00160             sprintf(filename,"%s_%04u.%s",prefix,i,type);
00161             rc = image.load(filename);
00162             phPRINT_RC(rc,NULL,"image loading failed");
00163         }
00164         else
00165         {
00166             rc = image.setImage(input_images[i]);
00167             phPRINT_RC(rc,NULL,"image.setImage(input_images[%u])",i);
00168         }
00169 
00170         if (rc != 0)
00171         {
00172             rc = system.shutdown();
00173             phPRINT_RC(rc,NULL,"system.shutdown()");
00174         }
00175         
00176         i++;
00177         if (i >= image_count) i = 0;
00178         
00179         if (glbl_disable_displays == 0)
00180         {
00181             displaysOpen = 0;
00182             if (display->isOpen())
00183             {
00184                 displaysOpen = 1;
00185             }
00186         }
00187         
00188         /* Remove this if block when using this code as an example */
00189         /* Set the loop control value to end the loop when testing */
00190         if (test > 0)
00191         { 
00192             test--;
00193             if (test == 0)
00194                 displaysOpen = 0;
00195         }
00196         else
00197         {
00198             phMSleep(500);
00199         }
00200     }
00201 
00202 error:
00203     rc = system.shutdown();
00204     phPRINT_RC(rc,NULL,"system.shutdown()");
00205 
00206     phDeleteArray(input_images);
00207     phDelete(display);
00208     phFree(prefixarg);
00209     phFree(typearg);
00210     
00211     phDelete(arg_parser);
00212 
00213     return phSUCCESS;
00214 }




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