[英]How can I best detect different LED colours using an Android phone's camera and OpenCV?
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. 我试图在Android手机上使用OpenCV来识别和区分LED的颜色与黑色背景,但我目前正在努力。 My investigations to date point to two separate issues: 我迄今为止的调查指出了两个不同的问题:
Consequently I have three questions: 因此,我有三个问题:
Thanks 谢谢
I like electronics, so a simple Light dependant resistor would do that without any code :). 我喜欢电子产品,因此一个简单的光源相关电阻器可以在没有任何代码的情
To identify different LED colors from black background, I propose the following: 为了从黑色背景中识别不同的LED颜色,我提出以下建议:
First, Using OpenCV's cvtColor function convert your RGB into HSV color space. 首先,使用OpenCV的cvtColor函数将RGB转换为HSV颜色空间。 Here HSV stands for Hue(such as red,green,yellow, blue etc.), Saturation(how saturated the color is), Value (lightness). 这里HSV代表Hue(例如红色,绿色,黄色,蓝色等),饱和度(颜色是多么饱和),值(亮度)。 After conversion for each RGB value you will have HSV value. 转换每个RGB值后,您将获得HSV值。 Like RGB HSV has three channels H, S and V. 像RGB HSV有三个通道H,S和V.
Second, since you are interested in the LED's color, please analyze only the hue component to decide LED's Color. 其次,由于您对LED的颜色感兴趣,请仅分析色调组件以确定LED的颜色。 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. 例如,您可以对Hue通道进行阈值处理,并确定图像的哪个部分包含色调,例如10到25,依此类推......绘制/打印阈值图像以检查代码。
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: 我对问题1的回答(意思是我不需要回答问题2)是使用OpenCV Tutorial 3代码(Camera Control)(参见OpenCV4Android样本 )并修改颜色效果方法以允许设置白平衡:
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 . 在回答问题3时,我在Color Logic Algorithm中使用了Java答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.