78
L2Bot using C# and Emgu J. Ruszala

L2Bot using C# and - Robofest - HomeL2Bot Line Following • Once you have a Win Forms application that contains the essential files for both the motor controller and Emgu you can

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

L2Bot Line Following

• To follow any line the computer must be able to:

• Distinguish the line from the surroundings

• Determine where the line is in relation to the robot

• Distinguishing the line from the surroundings

• Since the line the robot will follow is white and the floor color is dark, the line can easily be distinguished by converting the image to a pure black and white image

• image.ThresholdBinary(loThresh, hiThresh);

59

L2Bot Line Following

• Once you have a Win Forms application that contains the essential files for both the motor controller and Emgu you can begin to add the line following logic

• From within the ImageGrabbed event handler:

• Retrieve a gray frame

• Convert the gray frame to a binary image

• Get the width and height of the captured image

• Create variables to hold the amount of white pixels in each column

• Iterate through all the image pixels to find white pixels and increment the corresponding column variable

• Command the L2Bot based on the column with the greatest number of white pixels

62

Black, White, Red

• You can easily create the image by following these steps:

• Retrieve a gray frame

• Convert the gray frame to a binary image

• Retrieve a color frame

• Create a new color image that will be used to create the black, white, and red image

• Iterate through the color image pixels, if the pixel is red set the final images pixel color to red. Else, set the pixel to the corresponding binary image pixel value

72

Black, White, Red

• There are two ways to get/set pixel values in Emgu

• Image[Row, Column].Blue

• Image[Row, Column].Green

• Image[Row, Column].Red

• Pros – Easier to follow/use

• Cons – Slow to execute

• Image.Data[Row, Column, 0] => Blue Component

• Image.Data[Row, Column, 1] => Green Component

• Image.Data[Row, Column, 2] => Red Component

• Pros – Faster

• Cons – Harder to follow

73