00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef TESTBEOSUBCANNY_H_DEFINED
00039 #define TESTBEOSUBCANNY_H_DEFINED
00040
00041 #include "BeoSub/BeoSubCanny.H"
00042
00043
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046
00047 #include "Component/ModelManager.H"
00048 #include "Devices/FrameGrabberFactory.H"
00049 #include "Util/Timer.H"
00050 #include "Util/Types.H"
00051 #include "Util/log.H"
00052
00053 #include <cstdio>
00054 #include <cstdlib>
00055 #include <cstring>
00056
00057
00058
00059 #include "CannyModel.H"
00060
00061
00062 int main(int argc, char **argv)
00063 {
00064 if(MYLOGVERB) printf("This should never print\n");
00065
00066 char *infilename = NULL;
00067 char *shapeArg = NULL;
00068 char *colorArg = NULL;
00069
00070 if(argc < 3){
00071 fprintf(stderr,"\n<USAGE> %s image shape color \n",argv[0]);
00072 fprintf(stderr,"\n image: An image to process. Must be in PGM format.\n");
00073 fprintf(stderr," Type 'none' for camera input.\n");
00074 fprintf(stderr," shape: Shape on which to run recognition\n");
00075 fprintf(stderr," Candidates: Rectangle, Square, Circle, Octagon.\n");
00076 fprintf(stderr," color: Color to track\n");
00077 fprintf(stderr," Candidates: Blue, Yellow, none (for no color tracking).\n");
00078 exit(1);
00079 }
00080 infilename = argv[1];
00081 shapeArg = argv[2];
00082 colorArg = argv[3];
00083
00084 printf("READ: 1: %s 2: %s 3: %s\n", infilename, shapeArg, colorArg);
00085
00086
00087
00088 ModelManager manager("Canny Tester");
00089
00090
00091 nub::soft_ref<FrameIstream>
00092 gb(makeIEEE1394grabber(manager, "cannycam", "cc"));
00093
00094 if(!strcmp(infilename, "none")){
00095
00096
00097 manager.addSubComponent(gb);
00098
00099 }
00100
00101
00102 nub::soft_ref<BeoSubCanny> test(new BeoSubCanny(manager));
00103 manager.addSubComponent(test);
00104
00105 if(!strcmp(infilename, "none")){
00106
00107 manager.loadConfig("camconfig.pmap");
00108 }
00109
00110 manager.start();
00111
00112
00113 rutz::shared_ptr<ShapeModel> shape;
00114
00115 Image< PixRGB<byte> > Img;
00116
00117 double* p;
00118
00119
00120
00121 if(!strcmp(shapeArg, "Rectangle")){
00122
00123 p = (double*)calloc(6, sizeof(double));
00124 p[1] = 150.0;
00125 p[2] = 120.0;
00126 p[4] = 80.0f;
00127 p[5] = 80.0f;
00128 p[3] = (3.14159/4.0);
00129 shape.reset(new RectangleShape(120.0, p, true));
00130 }
00131 else if(!strcmp(shapeArg, "Square")){
00132
00133 p = (double*)calloc(5, sizeof(double));
00134 p[1] = 150.0;
00135 p[2] = 120.0;
00136 p[3] = 100.0;
00137 p[4] = (3.14159/4.0);
00138 shape.reset(new SquareShape(100.0, p, true));
00139 }
00140 else if(!strcmp(shapeArg, "Octagon")){
00141
00142 p = (double*)calloc(5, sizeof(double));
00143 p[1] = 150.0;
00144 p[2] = 120.0;
00145 p[3] = 60.0f;
00146 p[4] = (3.14159/4.0);
00147 shape.reset(new OctagonShape(80.0, p, true));
00148 }
00149 else if(!strcmp(shapeArg, "Circle")){
00150
00151 p = (double*)calloc(4, sizeof(double));
00152 p[1] = 150.0;
00153 p[2] = 120.0;
00154 p[3] = 50.0;
00155 shape.reset(new CircleShape(40.0, p, true));
00156 }
00157 else if(!strcmp(shapeArg, "Parallel")){
00158
00159 p = (double*)calloc(6, sizeof(double));
00160 p[1] = 150.0;
00161 p[2] = 120.0;
00162 p[4] = 120.0f;
00163 p[5] = 50.0f;
00164 p[3] = (3.14159/4.0);
00165 shape.reset(new ParallelShape(120.0, p, true));
00166 }
00167 else{
00168 printf("Cannot run shape recognition without a shape to recognize! Returning...\n");
00169 p = (double*)calloc(1, sizeof(double));
00170 shape.reset(new CircleShape(9999.0, p, false));
00171 return(false);
00172 }
00173
00174
00175
00176 while(1){
00177
00178
00179 if(!strcmp(infilename, "none")){
00180 Img = gb->readRGB();
00181 }
00182 else{
00183
00184 Img = Raster::ReadRGB(infilename);
00185 }
00186
00187 shape->setDimensions(p);
00188
00189
00190 test->setupCanny(colorArg, Img, true);
00191
00192
00193
00194
00195
00196 bool shapeFound = test->runCanny(shape);
00197
00198 if(!shapeFound){
00199
00200 }
00201
00202
00203
00204 if(!shapeFound){
00205 p[1] = 60.0;
00206 p[2] = 180.0;
00207 shape->setDimensions(p);
00208 shapeFound = test->runCanny(shape);
00209 }
00210 if(!shapeFound){
00211 p[1] = 260.0;
00212 p[2] = 180.0;
00213 shape->setDimensions(p);
00214 shapeFound = test->runCanny(shape);
00215 }
00216 if(!shapeFound){
00217 p[1] = 60.0;
00218 p[2] = 60.0;
00219 shape->setDimensions(p);
00220 shapeFound = test->runCanny(shape);
00221 }
00222 if(!shapeFound){
00223 p[1] = 260.0;
00224 p[2] = 60.0;
00225 shape->setDimensions(p);
00226 shapeFound = test->runCanny(shape);
00227 }
00228
00229 }
00230 return 0;
00231 }
00232
00233 #endif
00234
00235
00236
00237
00238