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 <DrawTest.h> 00013 #include <phission.h> 00014 00015 /* ------------------------------------------------------------------------ */ 00016 int glbl_disable_displays = 0; 00017 00018 /* ------------------------------------------------------------------------ */ 00019 void usage() 00020 { 00021 printf("\n\nUsage:\n"); 00022 printf("\t--help Display usage\n"); 00023 printf("\t--nodisplay Disable the allocation, opening or any use of a display.\n"); 00024 printf("\t--test <value> Iterate <value> times through the loop\n"); 00025 printf("\t--path <pathstr> Path to the input device\n"); 00026 printf("\t--channel <value> The channel to set a capture card to\n"); 00027 printf("\n\n"); 00028 exit(1); 00029 } 00030 00031 /* ------------------------------------------------------------------------ */ 00032 int main(int argc, char *argv[] ) 00033 { 00034 phFUNCTION("main") 00035 00036 /* Display variables */ 00037 char *capture_path = NULL; 00038 int channel = 0; 00039 int i = 0; 00040 int j = 0; 00041 char title[255]; 00042 00043 phImageCapture *capture = NULL; 00044 phPipeline *pipeline = new phPipeline(); 00045 phDisplayInterface *display = NULL; 00046 phSystem *system = new phSystem(); 00047 00048 draw_Filter *draw = new draw_Filter(); 00049 const int width = 320; 00050 const int height = 240; 00051 const int cols = 4; 00052 const int rows = 4; 00053 const int divisions = cols * rows; 00054 const int32_t rect_width = width/cols; 00055 const int32_t rect_height = height/rows; 00056 phDrawing drawing[divisions] = {0}; 00057 int32_t x1; 00058 int32_t y1; 00059 00060 /* Remove the code below when using this code as an example. 00061 * 00062 * This just checks whether "--test" has been specified with 00063 * a time value argument. It's for testing all the examples 00064 * without the need for human intervention. */ 00065 int test = 0; 00066 int done = 0; 00067 00068 /* --------------------------------------------------------------------- */ 00069 phArgTable *arg_parser = new phArgTable(); 00070 00071 rc = arg_parser->add("--nodisplay",&glbl_disable_displays, phARG_BOOL); 00072 phCHECK_RC(rc,NULL,"arg_parser->add"); 00073 00074 rc = arg_parser->add("--test",&test, phARG_INT); 00075 phCHECK_RC(rc,NULL,"arg_parser->add"); 00076 00077 rc = arg_parser->add("--help",(void *)&usage, phARG_FUNC); 00078 phCHECK_RC(rc,NULL,"arg_parser->add"); 00079 00080 rc = arg_parser->add("--path",&capture_path,phARG_CHAR); 00081 phCHECK_RC(rc,NULL,"arg_parser->add"); 00082 00083 rc = arg_parser->add("--channel",&channel,phARG_INT); 00084 phCHECK_RC(rc,NULL,"arg_parser->add"); 00085 00086 rc = arg_parser->parse(argc,argv); 00087 phCHECK_RC(rc,NULL,"arg_parser->parse"); 00088 00089 /* --------------------------------------------------------------------- */ 00090 /* If the command line switch to disable the displays was given, then 00091 * don't allocate or open any displays */ 00092 #ifdef WIN32 00093 capture = new VFWSource(); 00094 #else 00095 capture = new V4LCapture(); 00096 #endif 00097 capture->set(width,height,capture_path ); 00098 capture->setChannel(channel); 00099 #if 1 00100 capture->setColour(48495); 00101 capture->setHue(30583); 00102 capture->setContrast(30583); 00103 capture->setBrightness(38447); 00104 #endif 00105 rc = system->addCapture(capture); 00106 phPRINT_RC(rc,NULL,"system->addCapture(capture)"); 00107 00108 /* --------------------------------------------------------------------- */ 00109 if (!glbl_disable_displays) 00110 { 00111 sprintf(title,"DrawTest[%u]",i); 00112 00113 #if defined(PH_HAVE_X11) 00114 display = new X11Display(width,height,title); 00115 #elif defined(PH_HAVE_GDI) 00116 display = new GDIDisplay(width,height,title); 00117 #endif 00118 00119 rc = system->addDisplay(display); 00120 phPRINT_RC(rc,NULL,"system->addDisplay(display)"); 00121 } 00122 00123 /* --------------------------------------------------------------------- */ 00124 rc = system->addPipeline(pipeline); 00125 phPRINT_RC(rc,NULL,"system->addPipeline(pipeline)"); 00126 00127 /* --------------------------------------------------------------------- */ 00128 /* <> Attach the displays to the live sources */ 00129 /* Image -> (b)phPipeline -> (a)Processed Output Display */ 00130 00131 /* <> Attach the Pipeline output image to the display so the 00132 * display updates when a processing has been completed 00133 * for each loop */ 00134 if (!glbl_disable_displays) 00135 display->setLiveSourceInput(pipeline->getLiveSourceOutput()); 00136 00137 pipeline->setLiveSourceInput(capture->getLiveSourceOutput()); 00138 00139 /* --------------------------------------------------------------------- */ 00140 /* 00141 * Example 1: 00142 * Add the drawing data to the draw filter directly. 00143 * This shows the ability to add primitives to the the draw filter's 00144 * internal phDrawing object. 00145 */ 00146 capture->setFormat(phImageRGB24); 00147 draw->add(phCircle_new( 160,120,5 ), 00148 phColorRGB24_new(0,255,0), 00149 1, /* size */ 00150 phDrawingNoFill, /* color fill */ 00151 0 /* transparency */ 00152 ); 00153 00154 draw->add(phCircle_new( 160,120,20 ), 00155 phColorRGB24_new(255,0,255), 00156 1, /* size */ 00157 phDrawingNoFill, /* color fill */ 00158 0 /* transparency */ 00159 ); 00160 00161 draw->add(phCircle_new( 260,120,30 ), 00162 phColorRGB24_new(255,255,0), 00163 1, /* size */ 00164 phDrawingFill, /* color fill */ 00165 50 /* transparency */ 00166 ); 00167 00168 draw->add(phRectangle_new( 0, 10, 50, 100 ), 00169 phColorRGB24_new(0,255,255), 00170 1, /* size */ 00171 phDrawingFill, /* color fill */ 00172 50 /* transparency */ 00173 ); 00174 00175 draw->add(phRectangle_new( 200, 10, 70, 50 ), 00176 phColorRGB24_new(0,255,255), 00177 1, /* size */ 00178 phDrawingNoFill, /* color fill */ 00179 0 /* transparency */ 00180 ); 00181 00182 draw->add(phTriangle_new( 40,40, 220,120, 10,120 ), 00183 phColorRGB24_new(128,128,128), 00184 1, /* size */ 00185 phDrawingNoFill, /* color fill */ 00186 50 /* transparency */ 00187 ); 00188 00189 draw->add(phTriangle_new( 40,60, 220,140, 10,141 ), 00190 phColorRGB24_new(128,128,255), 00191 1, /* size */ 00192 phDrawingFill, /* color fill */ 00193 75 /* transparency */ 00194 ); 00195 00196 draw->add(phLine_new( 4,230, 220,0 ), 00197 phColorRGB24_new(128,0,128), 00198 1, /* size */ 00199 0 /* transparency */ 00200 ); 00201 00202 draw->add(phPoint_new(260,120), 00203 phColorRGB24_new(255,0,0), 00204 1, /* size */ 00205 0 /* transparency */ 00206 ); 00207 00208 draw->add(phCross_new(200,200,20,10), 00209 phColorRGB24_new(255,100,128), 00210 1, /* size */ 00211 0 /* transparency */ 00212 ); 00213 00214 /* Example 2: 00215 * Create a couple phDrawings and switch between them while the system is 00216 * running. 00217 * This shows a way of cycling through overlaying information on the image 00218 * using prestored phDrawing objects. 00219 */ 00220 for (j = 0; j < divisions; j++) 00221 { 00222 drawing[j] = NULL; 00223 rc = phDrawing_alloc(&drawing[j]); 00224 for (i = 0; i < divisions; i++) 00225 { 00226 x1 = (i % cols) * rect_width; 00227 y1 = (i / cols) * rect_height; 00228 00229 /* i != j leaves the division open */ 00230 if (i != j) 00231 { 00232 phDrawing_addRectangle( 00233 drawing[j], /* phDrawing */ 00234 phRectangle_new(x1,y1, 00235 rect_width, 00236 rect_height), /* phRectangle */ 00237 phColorRGB24_new(0,0,0), /* color */ 00238 1, /* size */ 00239 phDrawingFill, /* fill */ 00240 50 /* transparency */ 00241 ); 00242 } 00243 } 00244 } 00245 /* --------------------------------------------------------------------- */ 00246 /* Add the draw filter to the pipeline */ 00247 pipeline->add(draw); 00248 00249 /* <> Startup the system */ 00250 rc = system->startup(); 00251 phPRINT_RC(rc,NULL,"system->startup()"); 00252 00253 phMSleep(3500); 00254 /* --------------------------------------------------------------------- */ 00255 /* <> Keep going until all the windows are closed */ 00256 i = 0; 00257 while ((system->displaysOpen() > 0) && (!done)) 00258 { 00259 /* Cycle through the drawings */ 00260 rc = draw->set(drawing[i]); 00261 phPRINT_RC(rc,NULL,"draw->set(drawing[%d])",i); 00262 i = (i + 1) % divisions; 00263 phMSleep(125); 00264 00265 /* Yielding is optional. This gives up the thread's timeslice 00266 * to prevent slow response in other threads. It consumes more 00267 * CPU cycles than sleeping. Use it instead of sleeping if 00268 * this loop is processing anything */ 00269 00270 phYield(); 00271 00272 /* Remove this if block when using this code as an example */ 00273 /* Set the loop control value to end the loop when testing */ 00274 if (test > 0) 00275 { 00276 test--; 00277 phSleep(1); 00278 if (test == 0) done = 1; 00279 } 00280 } 00281 00282 /* --------------------------------------------------------------------- */ 00283 /* <> Shutdown the system */ 00284 rc = system->shutdown(); 00285 phPRINT_RC(rc,NULL,"system->shutdown()"); 00286 00287 error: 00288 for (j = 0; j < 4; j++) 00289 phDrawing_free(&drawing[j]); 00290 phDelete(draw); 00291 phDelete(display); 00292 phDelete(pipeline); 00293 phDelete(capture); 00294 phDelete(system); 00295 00296 phFree(capture_path); 00297 00298 phDelete(arg_parser); 00299 00300 return phSUCCESS; 00301 }
Copyright (C) 2002 - 2007 |
Philip D.S. Thoren ( pthoren@users.sourceforge.net ) University Of Massachusetts at Lowell Robotics Lab |