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 <FLPipelineTest.h> 00013 #include <phission.h> 00014 00015 /* ------------------------------------------------------------------------ */ 00016 int glbl_disable_displays = 0; 00017 int glbl_do_timing = 0; 00018 00019 /* ------------------------------------------------------------------------ */ 00020 void usage() 00021 { 00022 printf("\n\nUsage:\n"); 00023 printf("\t--help Display usage\n"); 00024 printf("\t--nodisplay Disable the allocation, opening or any use of a display.\n"); 00025 printf("\t--test <value> Loop <value> times and then close test\n"); 00026 printf("\t--timing Print pipeline runtime (forced when --test is used)\n"); 00027 printf("\n\n"); 00028 00029 exit(1); 00030 } 00031 00032 /* ------------------------------------------------------------------------ */ 00033 /* ------------------------------------------------------------------------ */ 00034 int main(int argc, char *argv[] ) 00035 { 00036 phFUNCTION("main") 00037 00038 unsigned int i = 0; 00039 00040 unsigned int nDisplays = 1; 00041 int displaysOpen= 1; 00042 char title[255]; 00043 phDisplayInterface **display = NULL; 00044 00045 char *capture_path = NULL; 00046 int channel = 0; 00047 00048 #ifdef WIN32 00049 VFWSource *capture = new VFWSource(); 00050 #else 00051 V4LCapture *capture = new V4LCapture(); 00052 #endif 00053 00054 phPipeline *pipeline = new phPipeline(); 00055 00056 empty_Filter *empty = new empty_Filter(); 00057 #if PH_HAVE_OPENCV 00058 cv_canny_Filter *canny = new cv_canny_Filter(50,105); 00059 #else 00060 canny_Filter *canny = new canny_Filter(50,105); 00061 #endif 00062 inverse_Filter *inverse = new inverse_Filter(); 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("--nodisplay",&glbl_disable_displays,phARG_BOOL); 00081 phCHECK_RC(rc,NULL,"arg_parser->add"); 00082 rc = arg_parser->add("--help",(void *)&usage,phARG_FUNC); 00083 phCHECK_RC(rc,NULL,"arg_parser->add"); 00084 00085 rc = arg_parser->add("--timing",&glbl_do_timing,phARG_BOOL); 00086 phCHECK_RC(rc,NULL,"arg_parser->add"); 00087 00088 rc = arg_parser->add("--path",&capture_path,phARG_CHAR); 00089 phCHECK_RC(rc,NULL,"arg_parser->add"); 00090 00091 rc = arg_parser->add("--channel",&channel,phARG_INT); 00092 phCHECK_RC(rc,NULL,"arg_parser->add"); 00093 00094 rc = arg_parser->parse(argc,argv); 00095 phCHECK_RC(rc,NULL,"arg_parser->parse"); 00096 00097 if (glbl_disable_displays) nDisplays = 0; 00098 if (test) glbl_do_timing = 1; 00099 00100 /* <> Setup the capture device parameters */ 00101 capture->set(320,240,capture_path); 00102 capture->setChannel(channel); 00103 00104 rc = system.addCapture(capture); 00105 phPRINT_RC(rc,NULL,"system.addCapture(capture)"); 00106 00107 00108 display = new phDisplayInterface *[nDisplays]; 00109 phCHECK_NULLPTR(display,"new","new phDisplayInterface *[nDisplays];"); 00110 00111 for (i = 0; i < nDisplays; i++ ) 00112 { 00113 sprintf(title,"FLPipelineTest[%u]",i); 00114 00115 display[i] = new FLDisplay(320,240,title); 00116 00117 rc = system.addDisplay(display[i]); 00118 phPRINT_RC(rc,NULL,"system.addDisplay(display[%u])",i); 00119 } 00120 00121 00122 rc = system.addPipeline(pipeline); 00123 phPRINT_RC(rc,NULL,"system.addPipeline(pipeline)"); 00124 00125 /* <> Attach the displays to the live sources */ 00126 /* Capture -> (b)phPipeline -> (a)Processed Output Display */ 00127 00128 /* <> Attach the Pipeline output image to the display so the 00129 * display updates when a processing has been completed 00130 * for each loop */ 00131 for (i = 0; i < nDisplays; i++) 00132 { 00133 display[i]->setLiveSourceInput(pipeline->getLiveSourceOutput()); 00134 } 00135 00136 /* <> Attach the capture image to the live source input of the 00137 * Pipeline so processing is done automatically once the 00138 * pipeline is started. */ 00139 pipeline->setLiveSourceInput(capture->getLiveSourceOutput()); 00140 00141 /* <> Add the filter(s) into the pipeline in the order they will 00142 * be used */ 00143 pipeline->add(empty); 00144 pipeline->add(canny); 00145 pipeline->add(inverse); 00146 00147 /* Since timing in the pipeline is disabled by default, enable it */ 00148 if (glbl_do_timing) 00149 { 00150 rc = pipeline->enableTiming(); 00151 phPRINT_RC(rc,NULL,"pipeline->enableTiming()"); 00152 } 00153 00154 /* <> Startup the system */ 00155 rc = system.startup(); 00156 phPRINT_RC(rc,NULL,""); 00157 00158 /* <> Keep going until all the windows are closed */ 00159 displaysOpen = 1; 00160 while (displaysOpen) 00161 { 00162 if (glbl_do_timing) 00163 { 00164 /* Reset the average calculations and sleep a second */ 00165 rc = pipeline->resetAverage(); 00166 phPRINT_RC(rc,NULL,"pipeline->resetAverage()"); 00167 00168 phMSleep(1000); 00169 00170 /* Report the average using the phTimeStamp report facility 00171 * to allow for portable/robust reporting */ 00172 pipeline->averageRuntime().report("FLPipelineTest - Filtering Average"); 00173 phPRINT_RC(rc,NULL,"pipeline->averageRuntime()"); 00174 } 00175 else 00176 { 00177 /* Sleep a while, don't loop tightly */ 00178 phMSleep(100); 00179 } 00180 00181 00182 /* Yielding is optional. This gives up the thread's timeslice 00183 * to prevent slow response in other threads. It consumes more 00184 * CPU cycles than sleeping. Use it instead of sleeping if 00185 * this loop is processing anything */ 00186 00187 /* phYield(); */ 00188 00189 if (nDisplays > 0) 00190 { 00191 displaysOpen = 0; 00192 for (i = 0; (i < nDisplays) && (displaysOpen == 0); i++) 00193 { 00194 if (display[i]->isOpen() == 1) 00195 { 00196 displaysOpen = 1; 00197 } 00198 } 00199 } 00200 00201 /* Remove this if block when using this code as an example */ 00202 /* Set the loop control value to end the loop when testing */ 00203 if (test > 0) 00204 { 00205 test--; 00206 if (test == 0) 00207 displaysOpen = 0; 00208 } 00209 } 00210 00211 /* <> Shutdown the system */ 00212 rc = system.shutdown(); 00213 phPRINT_RC(rc,NULL,""); 00214 00215 error: 00216 for (i = 0; (i < nDisplays) && (display != NULL); i++) 00217 { 00218 phDelete(display[i]); 00219 } 00220 00221 phDeleteArray(display); 00222 00223 phDelete(capture); 00224 00225 phDelete(empty); 00226 phDelete(canny); 00227 phDelete(inverse); 00228 00229 phDelete(pipeline); 00230 00231 phFree(capture_path); 00232 phDelete(arg_parser); 00233 00234 return phSUCCESS; 00235 }
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |