element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Robotics
  • Technologies
  • More
Robotics
Forum vision guided robot  using android and arduino
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Robotics to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 11 replies
  • Subscribers 62 subscribers
  • Views 1252 views
  • Users 0 members are here
Related

vision guided robot  using android and arduino

Former Member
Former Member over 13 years ago

i am doing vision gudied robot with arduino and android through bluetooth communication . i have done the image processing part using andriod.But i am facing problems in image processing. The colored image is getting transformed to black and white image. but the code that is written to detect the black tape is not working properly.. Could some one help me to debug.

 

 

public class DrawOnTop extends View

{

          BtConn btcon;

          //Display

          Bitmap mBitmap;

          Paint mPaint;

          int mImageWidth, mImageHeight;

 

          //Frame data

          byte[] mYUVData;

          int[] mRGBData;

          int[] mBWData;

 

          //FPS

                    long lastFrame = System.currentTimeMillis();

 

                    //PID

                    float proportional;

                    float integral;

                    float derivative;

                    float last_proportional;

                    int Kp=1;

                    int Kd=2;

                    int Ki=0;

 

                    //Motor Controls

                    int right_speed=0;

                    int left_speed=0;

                    int max_speed = 255;

 

          //Line Tracking

          static int tracking;

 

          int minPixels = 10;

          int threshold = 60;

          int tapeCenter;

    public DrawOnTop(Context context) {

        super(context);

 

        // Start off PAUSED

        tracking = 0;

 

        mPaint = new Paint();

        mPaint.setStyle(Paint.Style.FILL);

        mPaint.setColor(Color.RED);

        mPaint.setTextSize(25);

 

        mBitmap = null;

        mYUVData = null;

        mRGBData = null;

    }

 

 

    @Override

    protected void onDraw(Canvas canvas) {

        if (mBitmap != null)

        {

                  int canvasWidth = canvas.getWidth();

                  int canvasHeight = canvas.getHeight();                         

 

                  grayscaleToBlackWhite(mRGBData, mYUVData, mImageWidth, mImageHeight,canvas);

                  int tapeCenter=DetectingArea(canvas,mRGBData, mImageWidth, mImageHeight);

 

                  //PID

                        proportional = tapeCenter - mImageHeight/2;

                        integral = integral + proportional;

                        derivative = proportional - last_proportional;

                        last_proportional = proportional;

                        int lineError = (int)(proportional * Kp + integral * Ki + derivative * Kd);

 

                        // Restricting the error value between +/- max_speed.

                        if (lineError< -max_speed)

                        {

                                  lineError = -max_speed;

                        }

                        if (lineError> max_speed)

                        {

                                  lineError = max_speed;

                        }

 

                        // If error_value is less than zero calculate right turn speed values

                        if (lineError> 0)

                        {

                        right_speed = max_speed + lineError;

                        left_speed = max_speed;

 

                        }

                        // If error_value is greater than zero calculate left turn values

                        else

                        {    

                    right_speed = max_speed;

                        left_speed = max_speed - lineError;

 

                        }    

 

 

                        int[] data = new int[3];

                        data[0] = 0; //Forward

                        data[1] = right_speed;

                        data[2] = left_speed;

 

 

                  long curFrame = System.currentTimeMillis();

                  float fps = 1000/(curFrame - lastFrame);

                  lastFrame = curFrame;

 

 

 

 

                  // Draw bitmap

                  mBitmap.setPixels(mRGBData, 0, mImageWidth, 0, 0, mImageWidth, mImageHeight);

                  Rect src = new Rect(0, 0, mImageWidth, mImageHeight);

                  Rect dst = new Rect(0, 0, canvasWidth, canvasHeight);

                  canvas.drawBitmap(mBitmap, src, dst, mPaint);

 

 

 

 

 

                  canvas.rotate(-90, canvasWidth/2, canvasHeight/2);

                  mPaint.setTextSize(25);

                  canvas.drawText(mImageWidth + "x" + mImageHeight, 200, -140, mPaint);

                  canvas.drawText("fps: " + fps, 500, -100, mPaint);

 

 

        }

        super.onDraw(canvas);    

    }

 

 

 

 

    public void grayscaleToBlackWhite(int[] rgb, byte[] yuv420sp, int width, int height, Canvas canvas)

    {

 

              final int frameSize = width * height;

 

              mPaint.setTextSize(25);

 

 

              for (int pix = 0; pix < frameSize; pix++)

              {

                        int pixVal = (0xff & ((int) yuv420sp[pix])) - 16;

                        if (pixVal < threshold)

                        {

                                  pixVal = 0;

                        }

 

 

                        else

                                  pixVal = 255;

                        rgb[pix] = 0xff000000 | (pixVal << 16) | (pixVal << 8) | pixVal;

 

 

              }

             

 

    }

  public int DetectingArea(Canvas canvas,int rgb[],int height, int width)

  {

 

            int start=-1;

            int stop=-1;

            int tmpStart=-1;

            int tmpStop=-1;

          int scanline=-1;

            for(int i=0;i<width;i+=10)

            {

 

                                for(int j=0;j<height;j++)

                                 {

                                          //check for black line only.

                                          //find all black line centres and compare with the centre of the screen

                                          int pixVal = (0xff & (int) rgb[i+j*width]);

 

                                          if (pixVal == 0)

                                                      {

                                                              if(tmpStart==-1)

                                                              {

                                                                        tmpStart=j;

                                                              }

                                                              else

                                                              {

                                                                        tmpStop=j;

                                                                        if(tmpStop-tmpStart>minPixels &&

                                                                                            (Math.abs((tmpStop-tmpStart)/2 - height/2)

                                                                                            <  Math.abs(stop-start)/2 - height/2))

                                                                        {

                                                                                  start=tmpStart;

                                                                                  stop=tmpStop;

                                                                                  scanline=i;

                                                                        }

                                                                        else

                                                                        {

                                                                                  tmpStart=-1;

                                                                                  tmpStop=-1;

                                                                        }

                                                              }

 

                                                      }

                                 }

 

            }

            if (start > -1 && stop > -1 && scanline >-1) {

                        for (int pix = start; pix <= stop; pix++) {

                                        rgb[scanline+pix*width] = 0xff000000 | (0 << 16) | (255 << 8) | 0;

                        }

            }

 

 

            return (start+stop)/2;

 

  }

}

  • Sign in to reply
  • Cancel
  • Ramu
    Ramu over 13 years ago

    For comunication you can use something like this:
    http://www.ebay.com/itm/HC-07-Wireless-Bluetooth-to-UART-converter-RS232-TTL-COM-serial-port-slave-mode-/261096926176?pt=LH_DefaultDomain_0&hash=item3cca96ebe0

    but for this you will have to make shematic to pover and protect Bluatooth device. Because is uses 3.3V and inputs should be 3.3V or you can use something like this:

    http://www.ebay.com/itm/Bluetooth-Slave-CSR-TTL-Board-for-AVR-Arduino-UNO-R3-Mega-2560-1280-Mini-Pro-/170936257401?pt=LH_DefaultDomain_0&hash=item27cc984b79

     

    There are 3 types of this devices:

    1 - slave - other devices (like PC, phone and other Bluetooth master devices) can connect to it. You can set its name and all over AT commands.

    2 - master - this mode devices connect to other bluetoothe slave devices.

    3 - master/slave - this type devices can be changed from master to slave mode any time you want over AT commands.

     

    I think it is easier to buy slave and use mobile device to connect to the bluetoothe to uart slave device. I neves used it to connect it to mobile device, because I cant make apps for mobile devices, but I have tested it with my laptp. used it on arduino and on atmel devices.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Ramu
    Ramu over 13 years ago

    If you need computer vision on android device, I know OpenCV can vork on android. I have never tryed it on android, but on PC it works good. I have programmed some of the applications and I'm happy with it image

    Some information about it:

    http://opencv.org/platforms/android.html

    http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/O4A_SDK.html

     

    I think some day I need to learn programming on android. image with all mobile phones and tablet pc's it has good potential image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Ramu
    Ramu over 13 years ago

    And please do not forget to write how is it going to develop your project. And it it is not a secret, can you tell us more about it? It would be interesting to hear about it image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to Ramu

    I am trying to do vision guided robot using Arduino uno. i am using android phone to do the image processing. I dont know wheter image processing can be easily done using android or some other language like opencv.The exact thing is with a live video i need to process the image and guide the robot to move and avoid obstacles

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to Ramu

    Thank you

    Raimondas

    i am doing a project vision guided robot.And i need to control the arduino uno based robot. I am using android phone to control the robot through bluetooth.The exact thing is with live video i need to process the frames and send commands to arduino to move and to avoid obstacles.Currently i am doing in eclipse. but I dont know wether image processing is easy with android programming or opencv. and how to send the commands to arduino board. didi i need external support to connect android phone to arduino using bluetooth

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to Ramu

    Thank you

    i got that we need a bluetooth module. But will it support evry android device

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Ramu
    Ramu over 13 years ago in reply to Former Member

    OpenCV is not programming language, but its a library complect for image processing, computer vision and similar works with images image So it will add only funtions to your eclipse project. Just need to learn using OpenCV functions image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Ramu
    Ramu over 13 years ago in reply to Former Member

    Basicly this devices I have showed you is bluetooth to serial converters, when you connect a pc to this device, it will install serial port or 2 serial ports. and then if your device is in range, you start using this new port as normal serial port and computer connects to BT device it self (if it was pairted and installled all needed drivers). Atleast it was like this for me. Drivers ar auto instald on win7.

    I do not know what about android... never tryed it. But as I know this device is seen with android.

    Maybe someone will tell you more how to use it on android.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Ramu
    Ramu over 13 years ago

    And why do you want to seperate black region to other frame? T think the easyest way is to set the camera that botom will see near the robot front, ant top of the screen some centimeters avay.

    Then i think of 2 ways:

    1 - manualy look for begining and ending of a black kolor in one line. if its center is in center, then you are in the right place. And scan 10 lines of all lines, or less. if the screen is 64x64 then scan every 6 lines. If you get that all lines have black in the center, you go top speed, if lovest line is in center, and hier line has black going to sone side, then start turning. And so on.

    2 - use edge detectin, and based on the corners get some lines. And based on lines positions and oriantations you can decide how to go. but this is harder, because bended lines will make a lot of short stait linesor in some realy bended ones, you may get no strait lines. so i think 1rst option is more easy one.

     

    Or you can try to detect a center of all black line in the screen and then decide how to go. this has a problem if you have a road fork, it will not tell you that. it vil calculate center in betwean them.

     

    and before looking for a black line, you may want to filter out small black parts.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 13 years ago in reply to Ramu

    Thank you,

       The image proceesing part is done.I didnt use edge detection. i used the first way.But how to send these data to arduino board so that my robot can move.I mean what hardware and software should i usefor communication through bluetooth. My robot have to move through the black line .

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube