Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

USAR GGier

By: a guest on Nov 13th, 2012  |  syntax: C++  |  size: 3.77 KB  |  views: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //
  2. //  USAR-ggier.cpp
  3. //  
  4. //
  5. //  Created by Graham Gier on 11/11/12.
  6. //
  7. //
  8.  
  9.  
  10. #include <Myro.h>
  11. #include <iostream>
  12. #include <string>
  13. #include <limits.h>
  14. #include <sstream>
  15. using namespace std;
  16. static int size= 100;
  17.  
  18. int main();
  19. void takePicture(PicturePtr pictures[], int &numpics);
  20. void analyzePicture(PicturePtr pictures[], PicturePtr found[], int &numpics, int &numfound);
  21. void SlideshowPics(PicturePtr pictures[], int numpics);
  22. void slideshowFound(PicturePtr found[], int numfound);
  23.  
  24. void SlideshowPics(PicturePtr pictures[], int numpics)
  25. {
  26.     for (int i=0; i<numpics; i++)
  27.         show(pictures[i]);
  28. }
  29.  
  30. void SlideshowFound(PicturePtr found[], int numfound)
  31. {
  32.     for (int i=0; i<numfound; i++)
  33.         show(found[i]);
  34. }
  35.  
  36. void takePicture(PicturePtr pictures[], int &numpics)
  37. {
  38.     pictures[numpics] = robot.takePicture("color");
  39.     numpics++;
  40. }
  41.  
  42. void analyzePicture(PicturePtr pictures[], PicturePtr found[], int &numpics, int &numfound)
  43. {
  44.     PicturePtr questionablepic = pictures[numpics-1];
  45.     Pixel pixelpic[1200][800];
  46.     for (int i=0; i<1200; i++)
  47.     {
  48.         for (int j; j<800; j++)
  49.         {
  50.             pixelpic[i][j] = questionablepic->getPixel(i, j);
  51.         }
  52.     }
  53.     int leftbound = 1200;
  54.     int rightbound= 0;
  55.     int topbound=800;
  56.     int bottombound=0;
  57.     bool scribbler = false;
  58.     for(int i = 0; i<1200; i++)
  59.         for (int j = 0; j< 800; j++)
  60.         {
  61.             Pixel current = pixelpic[i][j];
  62.             if(current.R >=200 && current.G <= 70 && current.B <=70)
  63.             {
  64.                 if (i< leftbound)
  65.                     leftbound=i;
  66.                 if (i>rightbound)
  67.                     rightbound=i;
  68.                 if (j<topbound)
  69.                     topbound=j;
  70.                 if (j>bottombound)
  71.                     bottombound = j;
  72.                 scribbler=true;
  73.             }
  74.         }
  75.    
  76.     if (scribbler)
  77.     {
  78.         for(int i= leftbound; i<rightbound; i++)
  79.         {
  80.             setPixelColor(questionablepic, i, topbound, 0, 255, 0);
  81.             setPixelColor(questionablepic, i, topbound+1, 0, 255, 0);
  82.             setPixelColor(questionablepic, i, topbound+2, 0, 255, 0);
  83.             setPixelColor(questionablepic, i, topbound+3, 0, 255, 0);
  84.             setPixelColor(questionablepic, i, topbound+4, 0, 255, 0);
  85.         }
  86.         for(int j= topbound; j<bottombound; j++)
  87.         {
  88.             setPixelColor(questionablepic, j, leftbound, 0, 255, 0);
  89.             setPixelColor(questionablepic, j, leftbound+1, 0, 255, 0);
  90.             setPixelColor(questionablepic, j, leftbound+2, 0, 255, 0);
  91.             setPixelColor(questionablepic, j, leftbound+3, 0, 255, 0);
  92.             setPixelColor(questionablepic, j, leftbound+4, 0, 255, 0);
  93.         }
  94.     found[numfound] = questionablepic;
  95.     numfound++;
  96.     }
  97. }
  98.  
  99. int main()
  100. {
  101.         connect("/dev/tty.Fluke2-0221-Fluke2");
  102.         PicturePtr pictures[size];
  103.     PicturePtr found[size];
  104.     cout << "WASD to move, Q to quit and display slideshow."<<endl;
  105.     int numpics =0;
  106.     int numfound=0;
  107.     bool disc = false;
  108.     char input;
  109.     while (!disc)
  110.     {
  111.        
  112.         cout << "T to take picture"<< endl;
  113.         cout <<"E to analyze last picture taken"<<endl;
  114.         cin>>input;
  115.         switch(input)
  116.         {
  117.     case 'q': disc=true;
  118.         break;
  119.     case 'w': robot.forward(1,1);
  120.         break;
  121.     case 's': robot.backward(1,1);
  122.         break;
  123.     case 'a': robot.turnLeft(1, .5);
  124.         break;
  125.     case 'd': robot.turnRight(1, .5);
  126.         break;
  127.     case 't': takePicture(pictures, numpics);
  128.         break;
  129.     case 'e':analyzePicture(pictures, found, numpics, numfound);
  130.         break;
  131.         }
  132.     }
  133.    
  134.     SlideshowPics(pictures, numpics);
  135.     SlideshowFound(found, numfound);
  136.     disconnect();
  137. }
clone this paste RAW Paste Data