FTC Color Sensor 20230424
From wikidb
Contents
Why
- Color imaging is used for object detection in machine learning applications.
- Tensorflow is an example software framework that leverages camera sensing. We'll learn about it in another lab.
- In this lab will learn about using simple color sensors as a first step.
- We'll start by seeing how we can convert the RGB (Red Green Blue) color space from our sensors to HSV (Hue, Saturation and Value).
- This will make it easier to compare color objects and understand how color works when we get to Tensorflow labs.
Color Sensor Demo Setup
Color Sensor Demo Code
Physical Connection
- Connect Color Sensor to one of the I2C ports - 1 in my case
Configure Hardware
colorSensor = hardwareMap.get(NormalizedColorSensor.class, "sensor_color");
- Control Hub
- I2C Bus 1
- Port 0 MR IR Color Sensor V3
- sensor_color
- I2C Bus 1
Example HW color senso configuration entry. Change ColorV3 to sensor_color for our examples.
From: https://docs.revrobotics.com/color-sensor/application-examples.
Exercise
- Exercise 1: Load the TestColorSensorEpp Op Mode into Android Studio and execute it.
- Note: There is a switch on the REV Color Sensor V3 that turns its light off.
RGB (Red Green Blue) and HSV (Hue Saturation Value) Color Models
RGB Camera Sensor
- Bayer Pattern on a Sensor used in digital cameras.
Color Calculator
HSV Color Wheel
- Colors of the rainbow: Hue
- HSV Component Meaning Stackexchange
- "Saturation mixes the original color with white to make varying degrees of pastel color."
- "Intensity/Value mixes the above color with black to make varying degrees of brightness."
- Note: Divide the Hue angle number by two. They we implemented that way so color angle 0 to 360 could fit into one byte (0 to 255).
- broken link: FTC Forum: HSV color wheel copied from this site.
Question
Cobalt Green is also called Bluish Green. It has a Hue of 135. Use the color rapid table above and find its RGB values to tell me why. Set the Saturation and Value to 100%.
Why HSV
"... two shades of red colour might have similar Hue values, but widely different RGB values. In real life scenarios such as object racking based on colour, we need to make sure the our program rus well irrespective of environment changes ..."
Exercises
- Exercise 2: Modify the TestColorSensorEpp.java to stop the robot when it reaches the blue tape.
// Code hint: Suppose you wanted to stop at a cobalt green line with a hue angle of 135. // You could put something like the following in your while loop. Remember, we have to // divide the hue by 2 so cobalt green is 68 in FTC Java. if (hue > 63 && hue < 73) { break; }
- Exercise 3: Cando Challenge:
- Modify the TestColorSensorEpp.java to knock at soda can out of a circle.
- Time the runs and see which tutorial team does it the fastest.
References
- Color Sensor V3 - Overview
- Class ColorSensorV3
- Convert RGB to HSV in Android
- Alpha Compositing: "In computer graphics, alpha compositing or alpha blending is the process of combining one image with a background to create the appearance of partial or full transparency."
- Overview of Color Sensors from FTC Tricks
- Broken Link: Why Use HSV for Color Detection