Computer Vision
in FRC
By Max DeVos
What is Computer Vision?
2
Vision Processor
RoboRIO
Camera
Target
What isn’t Computer Vision?
3
RoboRIO
Camera
Target
Driver
How Vision Processing Works
Acquiring, Transferring, and Using Data
The 3 Parts of Computer Vision Tracking
Transferring Vision Data
Moving data from the processor to a place where it can be used by the central robot controller to adjust actuators
Acquiring Vision Data
Using a processor to collect and manipulate camera input to get meaningful data and information
Using Vision Data
Using the Vision data to move actuators and solve engineering problems.
5
Camera
Vision Processor
RoboRIO
Vision Processor
RoboRIO
Motor
Piston
Getting Vision Data
The Process of Turning Camera Input into Usable Data
Cameras - Acquiring Vision Data
7
Camera
Choosing a Camera Type - Acquiring Vision Data
Standard RGB
Pros:
Cons:
Example:
Microsoft Lifecam
HD-3000
Infrared (IR)
Pros:
Cons:
Example:�Infrared Camera Module
(NoIR) V2
8
The Vision Processor- Acquiring Vision Data
C++, Python, or Java
9
Vision Processor
Vision Processor Options - Acquiring Vision Data
10
The Vision Processing Program
The Software Itself
The Program Pipeline - Acquiring Vision Data
Program runs a script on loop to handle new images.
12
1
3
4
2
Filtering
Program filters the image using both color and geometry to achieve a set of pixel coordinates of the points of the target
Image Manipulation
Image is blurred and converted into a format that can be easily filtered.
Input
Image from the camera is loaded into the program as a 2D array of colored pixel data called a Mat (matrix)
Calculations
Pixel points of the target received from the filtering step are used to run calculations and compared to the last image to verify sensibility.
Step 1 - “Input”
Python
C++
13
Step 2 - “Image Manipulation”
14
Image is blurred and converted into easily filterable format (HSV).
Blur
Color Conversion
Blur - Step 2 “Image Manipulation”
Python
C++
15
Color Conversion - Step 2 “Image Manipulation”
16
Color Storage Formats - Step 2 “Image Manipulation”
BGR (RGB)
Classic images - contain a different amount of blue, green, or red to create any color. Terrible for filtering because of 3 different hue values.
Note: For some reason OpenCV refers to this format by default as BGR. Your IDE may suggest an RGB enum, but do not use it.
HSV
A coloring format optimized for filtering.
Like BGR, has 3 data points, but instead of different amounts of base colors includes one value (H) for the hue range, (S) for saturation (difference from white), and V (difference from black).
Mask Image (Boolean Image)
Pixels are activated or inactivated.
Used for contour detection and math. Often referred to as a 2-channel image/mask.
17
Color Conversion- Step 2 “Image Manipulation”
Python
C++
18
Step 3 - “Filtering”
19
Geometric Filtering
Program filters image using both color and geometry to determine a set of pixel coordinates of the target
Color Filtering
Contour
Detect
Color Conversion- Step 3 “Filtering”
Python
C++
20
Contour Detection - Step 3 “Filtering”
Python
C++
21
Geometric Filtering - Step 3 “Filtering”
Types of geometric filters:
22
Geometric Filtering (cont.) - Step 3 “Filtering”
Example: peg rectangles in Steamworks
23
Geometric Filtering (cont.) - Step 3 “Filtering”
Process:
Ex. Implementation:
24
All Contours Array
Large Contours Array
For: Larger than 100px2
For: Aspect Ratio ~ 2/5
Correct Shape
Sorting: Largest Two
Final Contour(s)
Step 4 - Calculations
25
Pixel points are used to run calculations to compare with previous data and discard invalid points.
Geometric Math
Comparison
Relative Tuning - Geometric Calculations
Absolute Tuning:
Using complex math and real world measurements to find exact pose of target, and then tuning robot mechanisms to that data.
Relative Tuning:
Using simple math and geometric properties to find relative position of target, and then tuning robot mechanisms to that data.
26
Solving Math Problems - Geometric Calculations
27
Note:
To determine which corner is which
Important Math Functions - Geometric Calculations
Yaw
Pitch
28
TargetX = The X value of the center of your target
TotalX = Total Width of screen
This will return a value -1 to 1 of how much the robot needs to move/rotate
-1 is left, 1 is right
TargetY = The Y value of the center of your target
TotalY = Total Height of screen
This will return a value -1 to 1 of how much the robot needs to move
1 is up, -1 is down
Comparison- Step 4 “Calculations”
Due to mis-detections, it’s important to verify sensibility of data. This can be done through comparing current point to previous data.
29
Store
If the data point is good, store it in the place of the previous data for future comparisons.
Timestamp
Use your language’s time system to assign a variable to the time of the frame for latency comparison
Compare
Compare your current point to your most recent data to verify that it is possible. If not, disregard that point and wait for next data point.
Transferring Vision Data
Moving Vision Data from the Processor To Your Robot Controller
Methods of Communication - Moving Vision Data
Serial Communication
Network Communication
31
Network Communication - Moving Vision Data
32
Vision Processor
RoboRIO
Radio
Using Vision Data
Moving Vision Data from the Processor to the Robot Controller
Using Vision Data to Actuate Actuators
34
Relative Tuning - Using Vision Data
Relative Tuning:
Use relative tuning to find a function that tells the robot specifically how to behave based on sensor data (in this case, Vision data)
Example:
Sensor Data: Height of contour for distance
Feedback: RPM of flywheel
Goal: Adjust RPM of flywheel to match distance
35
Vision Processor
RoboRIO
PID Loop
Motor
Piston
Relative Tuning - How To
36
What is Computer Vision?
37
Vision Processor
RoboRIO
Camera
Target
Thanks!
Any questions?
You can email us at programming@kingtec2169.com
Or me personally at devosmaxwell@gmail.com
Or see me after the presentation :)
Presentation can be found on https://kingtec2169.com/resources/documents/