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

FLIROverlayExample.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 <FLIROverlayExample.h>
00013 #include <stdio.h>
00014 #include <phission.h>
00015 #include <phEffectsThread.h>
00016 #include <invert_Filter.h>
00017 #include <key_matte_threshold_Filter.h>
00018 
00019 /* ------------------------------------------------------------------------ */
00020 int glbl_disable_displays   = 0;
00021 int glbl_save_images        = 0;
00022 
00023 /* ------------------------------------------------------------------------ */
00024 int usage()
00025 {
00026     printf("\n\n\tUsage:\n");
00027     printf("\t\t\t--help\t\t\tdisplay usage\n");
00028     printf("\t\t\t--nodisplay\tdisable the allocation, opening or any use of a display.\n");
00029     printf("\t\t\t--saveimages\tsave the frames to file\n");
00030     printf("\t\t\t--test <value>\tload 'value' number of frames/files/images\n");
00031     printf("\t\t\t--file <avi_data_file>\t\t\tavi source (required)\n");
00032     printf("\n\n");
00033     exit(1);
00034 }
00035 
00036 /* ------------------------------------------------------------------------ */
00037 int main(int argc, char *argv[] )
00038 {
00039     phFUNCTION("main")
00040 
00041     int             displaysOpen= 1;
00042     
00043     unsigned int    i           = 0;
00044     unsigned int    image_count = 50;
00045     char            *filename = NULL;
00046     char            savefilename[255];
00047 
00048     phDisplayInterface *display = NULL;
00049 
00050     int         count = 0;
00051     phImage     image;
00052     float       fps = 0.0;
00053     float       last_fps = 0.0;
00054 
00055     /* Utility class to ease the starting and stopping of displays, captures and
00056      * pipelines */
00057     phSystem        system;
00058     phPipeline      *pipeline = new phPipeline();
00059     phPipeline      *pipeline2 = new phPipeline();
00060     invert_Filter   *invert = new invert_Filter();
00061     key_matte_threshold_Filter   *key_matte = new key_matte_threshold_Filter(120);
00062     //phAvcodecSource *capture    = new phAvcodecSource();
00063     V4LCapture      *capture    = new V4LCapture();
00064     V4LCapture      *capture2   = new V4LCapture();
00065 
00066     phEffectsThread  effects_thread(pipeline->getLiveSourceOutput(),
00067                             pipeline2->getLiveSourceOutput(),
00068                             phImageRGBA32);
00069    
00070     /* Remove the code below when using this code as an example.
00071      * 
00072      * This just checks whether "--test" has been specified with
00073      * a time value argument. It's for testing all the examples
00074      * without the need for human intervention. */
00075     int             test = 0;
00076 
00077     phArgTable      arg_parser;
00078 
00079     /* Setup and parse all the arguments */
00080     rc = arg_parser.add("--test", &test, phARG_INT);
00081     phCHECK_RC(rc,NULL,"arg_parser.add");
00082     rc = arg_parser.add("--nodisplay", (void *)&glbl_disable_displays, phARG_BOOL);
00083     phCHECK_RC(rc,NULL,"arg_parser.add");
00084     rc = arg_parser.add("--saveimages", (void *)&glbl_save_images, phARG_BOOL);
00085     phCHECK_RC(rc,NULL,"arg_parser.add");
00086     rc = arg_parser.add("--help",(void *)&usage, phARG_FUNC);
00087     phCHECK_RC(rc,NULL,"arg_parser.add");
00088     
00089     rc = arg_parser.parse(argc,argv);
00090     phCHECK_RC(rc,NULL,"arg_parser.parse");
00091 
00092     /* Pipeline 1 */
00093     rc = pipeline->setLiveSourceInput(capture->getOutput());
00094     phCHECK_RC(rc,NULL,"pipeline->setLiveSourceInput");
00095 
00096     rc = pipeline->add(invert);
00097     phCHECK_RC(rc,NULL,"pipeline->add");
00098 
00099     rc = system.add(pipeline);
00100     phCHECK_RC(rc,NULL,"system.add");
00101 
00102     /* Pipeline 2 */
00103     rc = pipeline2->setLiveSourceInput(capture2->getOutput());
00104     phCHECK_RC(rc,NULL,"pipeline2->setLiveSourceInput");
00105 
00106     rc = pipeline2->add(key_matte);
00107     phCHECK_RC(rc,NULL,"pipeline2->add");
00108 
00109     rc = system.add(pipeline2);
00110     phCHECK_RC(rc,NULL,"system.add");
00111 
00112 
00113     /* Set up the capture parameters */
00114     capture->set        ( 320, 240, "/dev/video0" );
00115     capture->setChannel ( 0 );
00116     capture->setFormat  ( phImageRGBA32 );
00117 
00118     rc = system.add(capture);
00119     phCHECK_RC(rc,NULL,"system.add(capture:%p)",capture);
00120     
00121     capture2->set        ( 320, 240, "/dev/video2" );
00122     capture2->setChannel ( 0 );
00123     capture2->setFormat  ( phImageGREY8 );
00124 
00125     rc = system.add(capture2);
00126     phCHECK_RC(rc,NULL,"system.add(capture2:%p)",capture2);
00127 
00128     /* TODO: init capture */
00129     if (glbl_disable_displays == 0)
00130     {
00131 #if 0
00132         display = new X11Display(capture->getWidth(),
00133                                  capture->getHeight(),
00134                                  "phAvcodecSourceTest");
00135         phCHECK_PTR(display,"new","new X11Display failed.");
00136         
00137         display->setLiveSourceInput(capture->getLiveSourceOutput());
00138 #else
00139         display = new X11Display(320,240,
00140                                  "FLIROverlayExample");
00141         phCHECK_PTR(display,"new","new X11Display failed.");
00142         
00143         display->setLiveSourceInput(effects_thread.getLiveSourceOutput());
00144 #endif
00145         rc = system.addDisplay(display);
00146     }
00147 
00148     rc = system.add(&effects_thread);
00149     phCHECK_RC(rc,NULL,"system.add(&effects_thread)");
00150 
00151     if (glbl_save_images)
00152     {
00153         rc = image.connect(effects_thread.getLiveSourceOutput());
00154         phCHECK_RC(rc,NULL,"image.connect");
00155     }
00156 
00157     /* startup */
00158     rc = system.startup();
00159     phPRINT_RC(rc,NULL,"system.startup()");
00160     
00161     // now loop continuously for as long as we have a display open and a frame available from the avi file
00162     while ((displaysOpen) && (system.capturesActive()))
00163     {
00164         if (glbl_disable_displays == 0)
00165         {
00166             displaysOpen = 0;
00167             if (system.displaysOpen())
00168             {
00169                 displaysOpen = 1;
00170             }
00171         }
00172 
00173         /* Remove this if block when using this code as an example */
00174         /* Set the loop control value to end the loop when testing */
00175         if (test > 0)
00176         { 
00177             /* loop once through for this test */
00178             if (i == (image_count - 1))
00179             {
00180                 displaysOpen = 0;
00181             }
00182         }
00183 
00184         if (glbl_save_images)
00185         {
00186             sprintf(savefilename,"jpegs/flir%09d.jpg",count);
00187             count++;
00188             
00189             rc = image.update();
00190             phPRINT_RC(rc,NULL,"image.update");
00191             
00192             if (rc == phLiveObjectUPDATED)
00193             {
00194                 rc = image.save(savefilename);
00195                 phPRINT_RC(rc,NULL,"image.save");
00196             }
00197         }
00198         else
00199         {
00200             phMSleep(100);
00201         }
00202         
00203         fps = display->getImageWindow()->getFps();
00204         if (fps != last_fps)
00205         {
00206             last_fps = fps;
00207             phPRINT("%f\n", fps);
00208         }
00209     }
00210     
00211  error:
00212     rc = system.shutdown();
00213     phPRINT_RC(rc,NULL,"system.shutdown()");
00214     
00215     phDelete(display);
00216     phDelete(capture);
00217     phDelete(capture2);
00218 
00219     // free up the filename string allocation
00220     phFree(filename);
00221 
00222     return phSUCCESS;
00223 }




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