Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // USAR-ggier.cpp
- //
- //
- // Created by Graham Gier on 11/11/12.
- //
- //
- #include <Myro.h>
- #include <iostream>
- #include <string>
- #include <limits.h>
- #include <sstream>
- using namespace std;
- static int size= 100;
- int main();
- void takePicture(PicturePtr pictures[], int &numpics);
- void analyzePicture(PicturePtr pictures[], PicturePtr found[], int &numpics, int &numfound);
- void SlideshowPics(PicturePtr pictures[], int numpics);
- void slideshowFound(PicturePtr found[], int numfound);
- void SlideshowPics(PicturePtr pictures[], int numpics)
- {
- for (int i=0; i<numpics; i++)
- show(pictures[i]);
- }
- void SlideshowFound(PicturePtr found[], int numfound)
- {
- for (int i=0; i<numfound; i++)
- show(found[i]);
- }
- void takePicture(PicturePtr pictures[], int &numpics)
- {
- pictures[numpics] = robot.takePicture("color");
- numpics++;
- }
- void analyzePicture(PicturePtr pictures[], PicturePtr found[], int &numpics, int &numfound)
- {
- PicturePtr questionablepic = pictures[numpics-1];
- Pixel pixelpic[1200][800];
- for (int i=0; i<1200; i++)
- {
- for (int j; j<800; j++)
- {
- pixelpic[i][j] = questionablepic->getPixel(i, j);
- }
- }
- int leftbound = 1200;
- int rightbound= 0;
- int topbound=800;
- int bottombound=0;
- bool scribbler = false;
- for(int i = 0; i<1200; i++)
- for (int j = 0; j< 800; j++)
- {
- Pixel current = pixelpic[i][j];
- if(current.R >=200 && current.G <= 70 && current.B <=70)
- {
- if (i< leftbound)
- leftbound=i;
- if (i>rightbound)
- rightbound=i;
- if (j<topbound)
- topbound=j;
- if (j>bottombound)
- bottombound = j;
- scribbler=true;
- }
- }
- if (scribbler)
- {
- for(int i= leftbound; i<rightbound; i++)
- {
- setPixelColor(questionablepic, i, topbound, 0, 255, 0);
- setPixelColor(questionablepic, i, topbound+1, 0, 255, 0);
- setPixelColor(questionablepic, i, topbound+2, 0, 255, 0);
- setPixelColor(questionablepic, i, topbound+3, 0, 255, 0);
- setPixelColor(questionablepic, i, topbound+4, 0, 255, 0);
- }
- for(int j= topbound; j<bottombound; j++)
- {
- setPixelColor(questionablepic, j, leftbound, 0, 255, 0);
- setPixelColor(questionablepic, j, leftbound+1, 0, 255, 0);
- setPixelColor(questionablepic, j, leftbound+2, 0, 255, 0);
- setPixelColor(questionablepic, j, leftbound+3, 0, 255, 0);
- setPixelColor(questionablepic, j, leftbound+4, 0, 255, 0);
- }
- found[numfound] = questionablepic;
- numfound++;
- }
- }
- int main()
- {
- connect("/dev/tty.Fluke2-0221-Fluke2");
- PicturePtr pictures[size];
- PicturePtr found[size];
- cout << "WASD to move, Q to quit and display slideshow."<<endl;
- int numpics =0;
- int numfound=0;
- bool disc = false;
- char input;
- while (!disc)
- {
- cout << "T to take picture"<< endl;
- cout <<"E to analyze last picture taken"<<endl;
- cin>>input;
- switch(input)
- {
- case 'q': disc=true;
- break;
- case 'w': robot.forward(1,1);
- break;
- case 's': robot.backward(1,1);
- break;
- case 'a': robot.turnLeft(1, .5);
- break;
- case 'd': robot.turnRight(1, .5);
- break;
- case 't': takePicture(pictures, numpics);
- break;
- case 'e':analyzePicture(pictures, found, numpics, numfound);
- break;
- }
- }
- SlideshowPics(pictures, numpics);
- SlideshowFound(found, numfound);
- disconnect();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement