The problem of automated LED color detection seems relatively easy to solve. However, the devil is in details and when it comes to practice, there is always something which goes not as expected and our practical implementation was not an exception as we encountered multiple challenges. Nevertheless, there are some ways to overcome those challenges. The task was simple to formulate: implement a reliably functioning way of automated LED color recognition for PCBAs coming off a production line. Each PCBA had a three RGB LEDs and there was a requirement to check every basic color and make sure that those colors could be controlled individually, i.e., there was no shorts. Our first approach was to take a generic Web camera and by switching LED colors sequentially take three shapshots for red, green and blue colors, then apply a blob recognizing algorithm to count points of light and detect color for each point. As a result of first experiment, a few issues arised. First of all, bright LEDs very saturating the picture and always looked like a glowing white halo with either red, blue or green rim around it making it impossible to do blob and color detection. Secondly, the background acted like noise so it had to be at least reduced if not cancelled. And thirdly, the same setup keept giving very different pictures which depended on ambient lighting conditions. A typical picture taken with a generil web camera is given below:
We began experimenting with different Web cameras and soon established that much better results are subject to deliberate camera defocus. The most dramatic effect is given on the picture below, it is seen when a camera is defocused the LEDs are turning into nice round blobs evenly painted with monotonous color. Then is becomes possible to do blob recognition and count and detect color of each blob. The only problem is a distance between camera and LEDs under test – in oder for a camera to be able to defocus more, the longer focal length that camera must have and the greater distance between LEDs and camera must be to fit all theree LEDs in narrow camera’s angle of view. The best results with point of light defocusing we got with an USB microscope but it required at least 300 mm between LEDs and the camera which was simply impractical.
Continuing our search for an optimal camera we finally found LI-OV5640-USB-72 – a 5M USB camera with manual focus. The only modification that we needed to do was removal of two white illuminating LEDs:
The camera didn’t have to be placed far away from the PCBA under test and at the same time it gave satisfactory results in terms of even color distribution accross the blobs while having blob borders sharp enough for reliable work of blob detection algorithm. In addition to ability to adjust brightness and saturation the camera also allowed for gain control and by finding optimal values for those three parameters and by adding a couple of layers of gray film in front of the camera lenses it also became possible to cancel the background altogether signigicanly simplyfing further image processing process. With the final tuning the camera generates pictures with the following quality which is really easy to postprocess: