After installing Matlab with Raspberry PI as shown in my previous post I show a simple algorithm for color detection and calibration on Matlab and implement that on Raspberry PI. this is the first step for the robot to detect it's route which is marked using colors.
First, brief explanation of the color detection methodology.
the color detection is done using what's called trichromatic coefficients of the colors (you can refer to the very famous text digital image processing by gonzalez Page: 224). this method provides better robustness in terms of brightness differences.
For the coding of that, these coefficients are always less than one, so it's turned into percentage-like values by multiplying by 100 to ease the processing in programming.
the code used is attached (mohaned_code.m) and a snap shot from running this code using PI is shown here (also a photo of the robot and a photo after using a blue paper to cover the body to protect from interfering colors):
Second, it's very important to calibrate the max-min percentages for each color based on the exact objects to be detected later during the project run.
although, as mentioned before calibrating for various color intensities is important but not so severe due to using the trichromatic coefficients.
the calibration process is done using the attached code segment (RGB_percent_cal.m) and this video explains how it's done:
first an image is taken.
MATLAB imcrop function is used to manually segment the required object.
the program calculates the maximum and minimum RGB percentages over the whole selected region.
this process should be repeated for all required objects and the final RGB percentage values is the Union of all the partial regions.
Video Link on Youtube:
next step is to run the motors using Raspberry PI PWM pins.