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