I am converting YUV to RGB and its working fine. Now, I want to detect all points within a certain range of a specified color, such as all red points. And accordingly display all red points and render everything else Black and White.
Which is the best way to detect the red points?
Here, is my fragment shader -
CODE
const char *Shaders::yuvtorgb = MULTI_LINE_STRING(
varying mediump vec2 v_yTexCoord;
varying mediump vec4 v_effectTexCoord;
uniform sampler2D yTexture;
uniform sampler2D uvTexture;
// YUV to RGB decoder working fine.
mediump vec3 yuvDecode(mediump vec2 texCoord)
{
// Get y
mediump float y = texture2D(yTexture, texCoord).r;
y -= 0.0627;
y *= 1.164;
// Get uv
mediump vec2 uv = texture2D(uvTexture, texCoord).ra;
uv -= 0.5;
// Convert to rgb
mediump vec3 rgb;
rgb = vec3(y);
rgb += vec3( 1.596 * uv.x, - 0.813 * uv.x - 0.391 * uv.y, 2.018 * uv.y);
return rgb;
}
//Detects red color and outputs B&W image but with red points
mediump vec3 detectColor(mediump vec3 rgbColor)
{
mediump vec3 redTexture = vec3(rgbColor);
mediump float r = redTexture.r;
mediump float g = redTexture.g;
mediump float b = redTexture.b;
if (// Detect red color) {
//if primary color is red
//leave as it is
} else {
//primary color is not red
//apply B&W image.
mediump float y = texture2D(yTexture, v_yTexCoord.xy).r;
y -= 0.0627;
y *= 1.164;
redTexture = vec3(y);
}
return redTexture;
}
void main()
{
mediump vec3 rgb = yuvDecode(v_yTexCoord.xy);
rgb = detectColor(rgb);
gl_FragColor = vec4(rgb, 1.0);
}
);
Update:
Using OpenGLES 2.0