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