minimal.cpp

Go to the documentation of this file.
00001 
00002 // ============================================================================
00003 // declarations
00004 // ============================================================================
00005 
00006 // ----------------------------------------------------------------------------
00007 // headers
00008 // ----------------------------------------------------------------------------
00009 
00010 /*
00011 // For compilers that support precompilation, includes "wx/wx.h".
00012 #include "wx/wxprec.h"
00013 
00014 #ifdef __BORLANDC__
00015     #pragma hdrstop
00016 #endif
00017 
00018 // for all others, include the necessary headers (this file is usually all you
00019 // need because it includes almost all "standard" wxWidgets headers)
00020 #ifndef WX_PRECOMP
00021     #include "wx/wx.h"
00022 #endif
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 //#include <string>
00040 //#include <iostream>
00041 
00042 
00043 
00044 
00045 //#include "liblnp.h"
00046 
00047 #include "com.h"
00048 
00049 void print_entities(ENTITYLIST *entitylist);
00050 void send_entities(ENTITYLIST *entitylist);
00051 
00052 
00053 // ----------------------------------------------------------------------------
00054 // private classes
00055 // ----------------------------------------------------------------------------
00056 
00057 // Define a new CONSOLE application type, each program should derive a class from wxApp
00058 class MyApp : public wxAppConsole
00059 {
00060 public:
00061     // override base class virtuals
00062     // ----------------------------
00063 
00064     // this one is called on application startup and is a good place for the app
00065     // initialization (doing it here and not in the ctor allows to have an error
00066     // return: if OnInit() returns false, the application terminates)
00067     virtual bool OnInit();
00068 
00069         // main 
00070         virtual int OnRun();
00071 };
00072 
00073 
00074 
00075 // Create a new CONSOLE application object: this macro will allow wxWidgets to create
00076 // the application object during program execution (it's better than using a
00077 // static object for many reasons) and also implements the accessor function
00078 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
00079 // not wxApp)
00080 IMPLEMENT_APP_CONSOLE(MyApp)
00081 
00082 // ============================================================================
00083 // implementation
00084 // ============================================================================
00085 
00086 // ----------------------------------------------------------------------------
00087 // the application class
00088 // ----------------------------------------------------------------------------
00089    
00090 bool MyApp::OnInit() 
00091 {
00092     //put initialization code here : run before OnRun    
00093         wxInitAllImageHandlers();
00094 
00095 
00096     init_com(0);
00097   
00098     return true;
00099 }
00100 
00101  
00102 
00103   int MyApp::OnRun() {
00104 
00105 /*
00106         int i=7;
00107         
00108         com_send(0,1,2,&i);
00109         
00110         
00111         printf("TRIGGER1 : %d \n",TRIGGER1);
00112     ::Sleep(5000);
00113         printf("TRIGGER1 : %d \n",TRIGGER1);
00114         sem_com.Wait();
00115         TRIGGER1=0;
00116         sem_com.Post();
00117         printf("TRIGGER1 : %d \n",TRIGGER1);
00118 
00119         */
00120 //      ::Sleep(4000);
00121   
00122   
00123         (void) setDisplay_Image(VIEWER, "PPM");
00124     CVFWImage bmp;
00125         //bmp.Capture();
00126         //bmp.SaveToFile("d:\\out.bmp");
00127 
00128         //wxImage image1=bmp.getWxImage();
00129         //image1.SaveFile("d:\\wx2.png");
00130     
00131 //      Image *tmp1;
00132 //      tmp1=bmp.getCVIPImage();
00133 
00134         //view_Image(tmp1,"out1.ppm");
00135 
00136         //wxImage image2=CVIP2WX(tmp1);
00137         //image2.SaveFile("d:\\wx3.png");
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  // (void) setDisplay_Image(VIEWER, "PPM");
00153   
00154    // read in image
00155    // inputfile1 = "c:\\cygwin\\tmp\\snapshots\\ring2_var.ppm";
00156   // inputfile1 = "c:\\cygwin\\tmp\\snapshots\\goededata\\rings_close_half.ppm";
00157    // inputfile1 = "c:\\cygwin\\tmp\\snapshots\\goededata\\rings_roodengroen.ppm";
00158 //inputfile1 = "c:\\cygwin\\tmp\\snapshots\\goededata\\rings_roodengeengroen.ppm";
00159 //inputImage1 = read_Image(inputfile1, 1);
00160    //inputImage2 = read_Image(inputfile1, 1);
00161    //inputImage3 = read_Image(inputfile1, 1);
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 //for (int x=0; x<5;x++) {
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 ) { // TRIGGER1
00183      sem_com.Wait();
00184          TRIGGER1=0;
00185      sem_com.Post();
00186      // send received aknowledgment to both rcx's
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 //   view_Image(inputImage1,"out0.ppm");
00199 
00200   // Gets the number of rows and columns in the input image  
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   //tmp=get_component(inputImage1,RGB_RED);
00209 
00210 // view_Image(tmp1,"out1.ppm");
00211 // view_Image(tmp2,"out2.ppm");
00212 // view_Image(tmp3,"out3.ppm");
00213 
00214   //print_entities(&entitylist);
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   //lnp_shutdown();
00229   return 0;
00230 }
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 void print_entities(ENTITYLIST *entitylist) 
00242 {
00243         //std::list <Entity>::iterator i;
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         //std::list <Entity>::iterator i;
00278         ENTITYLIST_ITER i;
00279     short x,y,angle;
00280         Entity::Color color;
00281         Entity::Type type;
00282     //myprintf("--------");
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         // fill the remaining space with ones
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 }

Generated on Wed Nov 29 01:27:41 2006 by  doxygen 1.4.6