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
Parents
  • 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
Reply
  • 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
Children
  • 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
  • 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
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