FlintHill / SUAS-Competition

SUAS Competition Code for team Animus Ferus
4 stars 10 forks source link

Correcting the Color Classifier's Text Color Accruacy #123

Closed jvillemare closed 6 years ago

jvillemare commented 6 years ago

Problem

In a round of synthetic testing with 10,000 images, shape color accuracy for the color classifier was around 98%, while text color was around 67%. We need to correct this now to be prepared for the competition in June.

Explanation

Shown here is an example of a target that will be sent to color classifier:

screen shot 2018-04-03 at 6 19 48 am

Here is the result of the image after k-means (color quantization has been applied):

screen shot 2018-04-03 at 6 21 09 am

As you can see in the original image, the text color is definitively black, but, after quantization, appears to be brown. This is because the black text color in RGB is (0, 0, 0), and with some of the yellow pixels bleeding in (yellow being (255, 255, 0)) enough pixels have been shifted colors to make OpenCV quantize the text color to brown (165, 42, 42).

Solution

We have to use quantization because it rules out problems with pixel-by-pixel color variations.

If we know for sure the shape color is yellow since we have a lot of pixels for OpenCV to work with at the fixed height we fly at (100 ft, with a specific camera,) then we just have to check the letter color.

OpenCV image in this instance means the second image. Received image in this instances means the first image.

The solution is we check the OpenCV image for pixels that have been identified as the text color, in this case, brown. We create a list of all brown pixel locations in the OpenCV image that are surrounded by brown pixels. This rules out the possibility of some of the brown pixels on the edge of the OpenCV image, or another artifacts or blobs being picked up.

We then go to the received image, and store the color values of the pixels we identified as being the text color in the OpenCV image. We then average all these color values on the received image in order to determine the real text color.

TL;DR: We essentially determine from the OpenCV image what pixels are the innermost text color pixels, look at those innermost text color pixels in the received image, and calculate the text color from there based on average.

Implementation

Fixes will be saved to the new color-classifier-text-color-accuracy branch.

jvillemare commented 6 years ago

Pull Request immediately above this comment has been merged—closing issue.