Reputation: 91
I am trying to identify and differentiate the colours of LEDs against a black background using OpenCV on an Android phone, but am currently struggling. My investigations to date point to two separate issues:
Consequently I have three questions:
Thanks
Upvotes: 5
Views: 3289
Reputation: 91
My answer to question 1 (meaning I didn't require an answer to question 2) was to use Using the OpenCV Tutorial 3 code (Camera Control) (see OpenCV4Android samples) and modify the colour effects methods to allow the setting of white balance:
public List<String> getWhiteBalanceList() {
return mCamera.getParameters().getSupportedWhiteBalance();
}
public boolean isWhiteBalanceSupported() {
return (mCamera.getParameters().getWhiteBalance() != null);
}
public String getWhiteBalance() {
return mCamera.getParameters().getWhiteBalance();
}
public void setWhiteBalance(String whiteBalance) {
Camera.Parameters params = mCamera.getParameters();
params.setWhiteBalance(whiteBalance);
mCamera.setParameters(params);
}
Once I knew that worked I was able to add a call to my main thread to set the correct white balance:
mOpenCvCameraView.setWhiteBalance(Parameters.WHITE_BALANCE_CLOUDY_DAYLIGHT);
In answer to question 3, I used the Java answer in Color Logic Algorithm.
Upvotes: 1
Reputation: 300
To identify different LED colors from black background, I propose the following:
First, Using OpenCV's cvtColor function convert your RGB into HSV color space. Here HSV stands for Hue(such as red,green,yellow, blue etc.), Saturation(how saturated the color is), Value (lightness). After conversion for each RGB value you will have HSV value. Like RGB HSV has three channels H, S and V.
Second, since you are interested in the LED's color, please analyze only the hue component to decide LED's Color. For example, you can threshold the Hue channel and decide which part of the image contains hue from lets say 10 to 25 and so on ... Plot/print the thresholded image to check your code.
Upvotes: 0
Reputation: 1889
I like electronics, so a simple Light dependant resistor would do that without any code :).
Upvotes: 0