首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GPU加速Harris角检测

GPU加速Harris角检测
EN

Stack Overflow用户
提问于 2015-12-10 11:23:09
回答 1查看 850关注 0票数 2

我正在尝试使用GLSL来实现哈里斯角检测。但它不能正常工作(我猜)。首先,它并不能检测到所有的角点,它可以检测到很多不是角点的点,另一个大问题是,它的阈值对于每幅图像都是非常具体的。也许哈里斯探测器也是正常的?

所有的帮助都是感激的。

阴影通行证:

第一:标准通过。

第二:我把图像转换成灰度图像。

第三: Sobel滤波图像,通过x,y梯度强度和xy强度乘积。

代码语言:javascript
复制
    uniform sampler2D texture;
    varying vec2 vUV;

    void main() {

        vec2 uv = vUV;
        // Offset used to get access to neighbours
        float w = 1.0/800.0;
        float h = 1.0/600.0;

        vec3 temp;
        vec3 sum = vec3(0.0);
        // Sobel - Edge Detection
        // y gradient
        vec3 texel0 = texture2D(texture, uv + vec2(-w, h)).xyz;
        vec3 texel1 = texture2D(texture, uv + vec2(-w, 0)).xyz;
        vec3 texel2 = texture2D(texture, uv + vec2(-w, -h)).xyz;

        vec3 texel6 = texture2D(texture, uv + vec2(w, h)).xyz;
        vec3 texel7 = texture2D(texture, uv + vec2(w, 0)).xyz;
        vec3 texel8 = texture2D(texture, uv + vec2(w, -h)).xyz;

        vec3 vertEdge = 1.0 * texel0 + (2.0*texel1) + 1.0 * texel2 -
                        (1.0 * texel6 + (2.0*texel7) + 1.0 * texel8);
        // x gradient
        vec3 texe0 = texture2D(texture, uv + vec2(-w,h)).xyz;
        vec3 texe1 = texture2D(texture, uv + vec2(0, h)).xyz;
        vec3 texe2 = texture2D(texture, uv + vec2(w, h)).xyz;

        vec3 texe6 = texture2D(texture, uv + vec2(-w,-h)).xyz;
        vec3 texe7 = texture2D(texture, uv + vec2(0,-h)).xyz;
        vec3 texe8 = texture2D(texture, uv + vec2(w,-h)).xyz;

        vec3 horizEdge = 1.0 * texe0 + (2.0*texe1) + 1.0 * texe2 -
                        (1.0 * texe6 + (2.0*texe7) + 1.0 * texe8);

        // Gradient intensity values
        float iy = (vertEdge.r + vertEdge.g + vertEdge.b) /3.0;
        float ix = (horizEdge.r + horizEdge.g + horizEdge.b)  /3.0;
        // Absolute to get negative values
        iy = abs(iy);
        ix = abs(ix);
        float gradProcduct = ix * iy;


        gl_FragColor = vec4(ix,iy,gradProcduct, 0.0);

并不是最好看的代码--只是希望它现在能工作,

第4和第5步:标准高斯模糊

第六部分:计算Harris反应。如果是一个角,我用洋红画那个像素。

代码语言:javascript
复制
        void main() {

        vec2 uv = vUV;
        float w = 1.0/800.0;
        float h = 1.0/600.0;

        float threshold = 0.05;

        vec4 gradientInfo = texture2D(texture, uv);

        /**************    Harris Reponse   **********************
         R is calculated as R = det(M)- K(Trace(M)) which leads to
         R = Ix^2*Ix^y - Ixy^2-K(ix^2+iy^2)^2
         Ix = X-gradient intesity 
         Iy = Y-gradient intesity 
         Ixy = product of the X- and Y-gradient intensities
         *********************************************************/
        float R =       pow(gradientInfo.r,2.0)*pow(gradientInfo.g,2.0)
                    -   pow(gradientInfo.b,2.0)
                    -   threshold * pow((pow(gradientInfo.r,2.0)+pow(gradientInfo.g,2.0)),2.0);
        vec4 test;
        //if(R > 0.000000000005)
        if(R > 0.0000000000750){
                // Extremley small values, ugly soloution for now to be able to use R in maxSupress
             test  = vec4(1.0, 0.0, 1.0, R*1000000000.0);
        }
        else
            test = vec4(vec3(gradientInfo.xyz),0.0);


        gl_FragColor = vec4( test);
    }

结果

简单正方形上的结果

对于具有相同R和阈值的更复杂图形的结果

以及响应检查的结果是多个1000。似乎没什么用。

下面是最大抑制的代码。(){

代码语言:javascript
复制
        vec2 uv = vUV;
        float vOffset = 1.0/800.0;
        float hOffset = 1.0/600.0;
        vec4 neighbourPixels[9];

        vec3 result;
        int check = 0;
        vec3 previous = texture2D(texture2, uv).xyz;
        vec4 current = texture2D(texture, uv);
        float temp = current.a;
        vec4 neighbourArray[25];

        if(current.a > 0.0){

            for(int i = -2; i<3;i++){
                for(int j = -2; j<3;j++){
                    if(temp < texture2D(texture, vUV.xy+vec2(i,j)*vec2(vOffset,hOffset)).a ){
                            //result = vec3(1.0,0.0,1.0);
                            check = 1;
                            break;
                    }    
                }
                if(check==1){
                    break;
                }       
            }   
            if(check==1){
                result = vec3(1.0,0.0,0.0);
            }
            else{
                result = vec3(0.0,1.0,1.0);  
            }

        }
        else{
            result = previous.xyz;
        }

        gl_FragColor = vec4( result, 0.0);
    }
EN

回答 1

Stack Overflow用户

发布于 2015-12-11 20:29:38

你需要在哈里斯的反应中寻找局部极大值,而不仅仅是阈值。使用3x3或5x5框扩展响应,然后查找像素是否原始响应和扩展版本是否相等。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34200634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档