]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
camera/color-finder: Add recognition on robot color
authorMonika Svedirohova <svedimon@fel.cvut.cz>
Sun, 30 Sep 2012 09:27:10 +0000 (11:27 +0200)
committerMonika Svedirohova <svedimon@fel.cvut.cz>
Sun, 30 Sep 2012 09:27:10 +0000 (11:27 +0200)
src/camera/color-finder/main/revue.cpp

index 5c2d0e34e35603ed264a14b59e1ca7150a76477e..b247ba76af2fa5fc9b2d986e43673ee1d65740fb 100644 (file)
@@ -9,6 +9,7 @@
 extern "C" {
 #include <roboorte_robottype.h>
 #include <robot.h>
+#include "../control/CRecognition.h"
 }
 
 int i = 0;
@@ -28,6 +29,8 @@ Uint8 lastKeys[10000];
 int keyNumber = 1000;
 Uint8 *keys = NULL;
 
+unsigned char* color;
+
 /* Public data for ORTE comuunication */
 struct robottype_orte_data orte;
 bool camera_control_on = false;
@@ -37,10 +40,12 @@ void rcv_cmr_ctrl_cb(const ORTERecvInfo *info, void *vinstance, void *recvCallBa
 
 
 void processKeys()
-{
+{       
+#ifdef __i386__
        while (SDL_PollEvent(&event)){
-               if (event.type == SDL_MOUSEBUTTONDOWN) recognition->learnPixel(&image->data[3*(image->width*event.motion.y + event.motion.x)]);
+               if (event.type == SDL_MOUSEBUTTONDOWN) color = &image->data[3*(image->width*event.motion.y + event.motion.x)];
        }
+#endif
        keys = SDL_GetKeyState(&keyNumber);
        if (keys[SDLK_ESCAPE]) stop = true;
        if (keys[SDLK_a]) camera->setBrightness(camera->getBrightness()+1);
@@ -50,7 +55,7 @@ void processKeys()
        if (keys[SDLK_u]) camera->setExposition(7);
        if (keys[SDLK_SPACE] && lastKeys[SDLK_SPACE] == false) move = (move == false);
        if (keys[SDLK_m]) recognition->increaseTolerance();
-       if (keys[SDLK_n])  recognition->decreaseTolerance();
+       if (keys[SDLK_n]) recognition->decreaseTolerance();
        if (keys[SDLK_l]) recognition->learnPixel(&image->data[3*(640*240+320)]);
        if (keys[SDLK_RETURN])image->saveBmp();
        memcpy(lastKeys,keys,keyNumber);
@@ -174,7 +179,9 @@ int main(int argc,char* argv[])
 
        camera->setExposition(8);
        CTimer timer;
-       while (stop == false){
+        while(stop){
+        while (camera_control_on){
+                recognition->learnPixel(color);
                //Nacteni obrazku
                camera->renewImage(image);
 
@@ -185,8 +192,7 @@ int main(int argc,char* argv[])
                //zpracovani obrazku
                //meanPosition = recognition->findMean(image);
                meanPosition = recognition->findSegment(image);
-
-               //vypis timeru doby zpracovani obrazu
+                       //vypis timeru doby zpracovani obrazu
                //fprintf(stdout,"Timer %i\n",timer.getTime());
                //vypocet rychlosti
                //command = robot->computeCommand(meanPosition);
@@ -194,7 +200,6 @@ int main(int argc,char* argv[])
                //if (move) robot->sendCommand(command);
 
                //vykresleni vysledku zpracovani
-               if (cp == true){ 
                 if (move==false || i%1 ==0){
                        image->plotLine(meanPosition.x,meanPosition.y);
                        image->plotCenter();
@@ -207,7 +212,7 @@ int main(int argc,char* argv[])
                        //Zpracovani udalosti z klavesnice
                        processKeys();
                 }
-               }
+               
                //fprintf(stderr,"Device exposition=%d\n",camera->getExposition());
                //fprintf(stderr,"%d\n\nBR=%lf\n",i,image->getOverallBrightness(true));
                i++;
@@ -215,8 +220,8 @@ int main(int argc,char* argv[])
                        controlExposition(image,camera);        
                }
         
-       } 
+         
+        }
        delete recognition;
        //delete robot;
        delete image;