Thursday, 10 March 2016

Colour Detection with NeoPixle Display

Team : ESD
Name: Luke Byrne
Section: Colour Detection

So, almost done with this sprint. For it I was tasked with getting the basic colour detection thread up and running. This thread will be used to mimic the colour that is placed in front of it by obtaining the RGB values and inputting them to the NeoPixels that will be used. Before I explain the ins and outs of it here is the first Demo of this code in action.

Under The Hood

All the code associated with this project can be found on my Github and the links will be supplied as we go along. Firstly is the OpenCV Colour Detection Module. This is one of two threads that are designed for this sprint. The code starts off rather like that of my first sprints code in that it the PiCamera is used to obtain a display that will later be used in getting the RGB values.

RGB stands for Red Green Blue. For those that don't know this is how a lot of colours are represented. A mixture of the primary colours Red, Green and Blue can get almost any colour imaginable depending on the level of each. These values can be representative of an 8 bit number from 0 - 255. R:G:B set to 255:255:255 will give white, 000:000:255 will give Blue and so on. This however is not the only colour scale that can be used. HSV stands for Hue Saturation Value (also known as brightness) and is commonly used in the application of digital colour. In the search for code for the NeoPixels (which is described below) most of what I found pertained to HSV values so I was inclined to use this method. However as luck would have it OpenCV Proved to be an awkward one for the HSV range. the Arduino code for the HSV Value is in the same range as that of RGB but OpenCV does not utilise the full 8 Bits due to the way the Hue is calculated meaning that the Hue squashes the full range from 0-255 down to 0-179 (the Saturation and Value where not effected by this). Another deterrent is that 0 is Red on the Arduino but Yellow with OpenCV.

This led me to concentrate on sending the RGB values instead as it was less time consuming than converting the HSV values.

With the method chosen the next obstacle was to output the the RGB Values for the the Serial Thread to pick up. This part involved a lot of messing around to find the correct method to obtain the values automatically and it took moving from an automatic system back to a predefined system to figure out where the codes needed to be changed.

The Serial Comms Module and the NeoPixles Module are linked to the core. the first is RPi side. this reads the thread for the RGB values and splits them up. After this is done they are then wrapped into a Serial write command and transferred to the Arduino. This sends it in the form "XXX:XXX:XXX" where ":" is the divider that is used to separate, using the strtok() function, the values to be used in sending out the right code to the NeoPixles. 

For the control of the LED's a brilliant library was found at that allowed for a wide range of control of a number of different NeoPixle LED's and other programmable LED's.

The code that is supplied is not the final version and will be refined in the coming week but hopefully this will serve as an outline to what has been done so far. It is our plan to incorporate this thread with that of the Object Detection to create a game that will request a shape of a specific colour. If the correct colour is displayed then the Lights will turn Green to indicate a correct match, however if it is incorrect then Red could be flashed and the correct colour displayed or the shape called out.

Luke, 5th Blog Entry

No comments:

Post a Comment