00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "wx/wx.h"
00025 #include "CVIPtoolsInc.h"
00026
00027 #define VIEWER "C:\\Progra~1\\XnView\\xnview.exe"
00028
00029 #include <list>
00030
00031 #include "Entity.h"
00032
00033
00034 #include "VFWImage.h"
00035
00036
00037 #include "imageprocessing.h"
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include "com.h"
00048
00049 void print_entities(ENTITYLIST *entitylist);
00050 void send_entities(ENTITYLIST *entitylist);
00051
00052
00053
00054
00055
00056
00057
00058 class MyApp : public wxAppConsole
00059 {
00060 public:
00061
00062
00063
00064
00065
00066
00067 virtual bool OnInit();
00068
00069
00070 virtual int OnRun();
00071 };
00072
00073
00074
00075
00076
00077
00078
00079
00080 IMPLEMENT_APP_CONSOLE(MyApp)
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 bool MyApp::OnInit()
00091 {
00092
00093 wxInitAllImageHandlers();
00094
00095
00096 init_com(0);
00097
00098 return true;
00099 }
00100
00101
00102
00103 int MyApp::OnRun() {
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 (void) setDisplay_Image(VIEWER, "PPM");
00124 CVFWImage bmp;
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 int r,center_row,center_col,arrow_col,arrow_row, *ctr;
00142 byte **image;
00143 unsigned int no_of_rows,no_of_cols;
00144 Matrix *mat;
00145 Image *inputImage1, *inputImage2, *inputImage3;
00146 Image *band1, *band2, *band3, *tmp1, *tmp2, *tmp3, *lab;
00147 IMAGE_FORMAT format;
00148 char *inputfile1, *inputfile2, *outputfile;
00149
00150 ENTITYLIST entitylist;
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 init_imageprocessing();
00164 char *automode = getenv( "AUTO" );
00165 int AUTO=0;
00166 if (automode) AUTO=atoi(automode);
00167 int akn=1;
00168
00169
00170 while (1 ) {
00171 if ( TEMPERATURE ) {
00172 printf("TEMPERATURE : %d",TEMPERATURE);
00173 com_send(0,1,6,&akn);
00174 com_send(0,2,6,&akn);
00175 sem_com.Wait();
00176 TEMPERATURE=0;
00177 sem_com.Post();
00178 }
00179
00180 if ( AUTO || TRIGGER1 ) {
00181
00182 if ( !AUTO ) {
00183 sem_com.Wait();
00184 TRIGGER1=0;
00185 sem_com.Post();
00186
00187 com_send(0,1,1,&akn);
00188 com_send(0,2,1,&akn);
00189 }
00190
00191
00192 bmp.Capture();
00193 inputImage1=bmp.getCVIPImage();
00194
00195 inputImage2 = duplicate_Image(inputImage1);
00196 inputImage3 = duplicate_Image(inputImage1);
00197
00198
00199
00200
00201 no_of_rows = getNoOfRows_Image(inputImage1);
00202 no_of_cols = getNoOfCols_Image(inputImage1);
00203
00204
00205 tmp3=find_color_entities(inputImage3,RGB_BLUE,&entitylist);
00206 tmp2=find_color_entities(inputImage2,RGB_GREEN,&entitylist);
00207 tmp1=find_color_entities(inputImage1,RGB_RED,&entitylist);
00208
00209
00210
00211
00212
00213
00214
00215 entitylist.sort();
00216 print_entities(&entitylist);
00217 send_entities(&entitylist);
00218 entitylist.clear();
00219
00220 } else {
00221 ::Sleep(50) ;
00222 }
00223 }
00224
00225
00226
00227
00228
00229 return 0;
00230 }
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241 void print_entities(ENTITYLIST *entitylist)
00242 {
00243
00244 ENTITYLIST_ITER i;
00245 short x,y,angle;
00246 Entity::Color color;
00247 Entity::Type type;
00248
00249 printf("\r\n"); printf("\r\n");
00250 printf("--------------------------------------------------\r\n");
00251 for ( i= entitylist->begin(); i != entitylist->end(); ++i )
00252 {
00253 color=(*i).getColor();
00254 x=(*i).getX();
00255 y=(*i).getY();
00256 type=(*i).getType();
00257 if ( type == Entity::ROBOT ) {
00258 angle=(*i).getAngle();
00259 printf("robot x=%d,y=%d,angle=%d,color=%d \r\n",x,y,angle,color);
00260 }
00261 if ( type == Entity::SUBJECT ) {
00262 printf("subject x=%d,y=%d,color=%d \r\n",x,y,color);
00263 }
00264 if ( type == Entity::GOAL ) {
00265 printf("goal x=%d,y=%d,color=%d \r\n",x,y,color);
00266 }
00267 }
00268 printf("--------------------------------------------------\r\n");
00269 printf("\r\n"); printf("\r\n");
00270
00271 }
00272
00273
00274 void send_entities(ENTITYLIST *entitylist)
00275 {
00276
00277
00278 ENTITYLIST_ITER i;
00279 short x,y,angle;
00280 Entity::Color color;
00281 Entity::Type type;
00282
00283 int k=0;
00284 int coordnts[9];
00285
00286 for ( i= entitylist->begin(); i != entitylist->end() && k < 3 ; ++i,++k )
00287 {
00288 color=(*i).getColor();
00289 x=(*i).getX();
00290 y=(*i).getY();
00291 type=(*i).getType();
00292
00293 coordnts[3*k]=x;
00294 coordnts[3*k+1]=y;
00295 coordnts[3*k+2]=color;
00296
00297 }
00298
00299 for ( ; k < 3 ; k++) {
00300 coordnts[3*k]=1;
00301 coordnts[3*k+1]=1;
00302 coordnts[3*k+2]=1;
00303 }
00304 com_send(0,1,7,coordnts);
00305
00306 }