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
  • Former Member
    Former Member over 13 years ago in reply to Ramu

    Actually i need to avoid white line and not black. I am not doing a line follower. I am ding a robot which will move forward with in a boundary and by avoiding the obstacles.The boundary line may be of black or white.Robot should not cross the buondary. As first step to my project i am trying to do a line follower.So that i could get knowledge about image processing and communication part which makes it easy to my original project

    • 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