0

我正在将 YUV 转换为 RGB 并且它工作正常。现在,我想检测指定颜色的一定范围内的所有点,比如所有的红色点。并相应地显示所有红点并将其他所有内容渲染为黑白。

检测红点的最佳方法是什么?

这是我的片段着色器 -

代码

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);
        }

);

更新:

使用 OpenGLES 2.0

4

0 回答 0