在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例图形和图像处理 → zncc的CPU和openCL代码实现

zncc的CPU和openCL代码实现

图形和图像处理

下载此实例
  • 开发语言:C/C++
  • 实例大小:17.82M
  • 下载次数:13
  • 浏览次数:174
  • 发布时间:2020-06-01
  • 实例类别:图形和图像处理
  • 发 布 人:majest
  • 文件格式:.zip
  • 所需积分:2
 相关标签: OpenCL CPU ZNCC GPU

实例介绍

【实例简介】

图像立体匹配中的ZNCC算法,使用CPU和openCL GPU加速实现,典型用法。

【实例截图】

【核心代码】

uint8_t* zncc(const uint8_t* left, const uint8_t* right, uint32_t w, uint32_t h, int32_t bsx, int32_t bsy, int32_t mind, int32_t maxd)
{
    /* Disparity map computation */
    int32_t imsize = w*h; // Size of the image
    int32_t bsize = bsx*bsy; // Block size

    uint8_t* dmap = (uint8_t*) malloc(imsize); // Memory allocation for the disparity map
    int32_t i, j; // Indices for rows and colums respectively
    int32_t i_b, j_b; // Indices within the block
    int32_t ind_l, ind_r; // Indices of block values within the whole image
    int32_t d; // Disparity value
    float cl, cr; // centered values of a pixel in the left and right images;
    
    float lbmean, rbmean; // Blocks means for left and right images
    float lbstd, rbstd; // Left block std, Right block std
    float current_score; // Current ZNCC value
    
    int32_t best_d;
    float best_score;
    
    for (i = 0; i < h; i ) {
        for (j = 0; j < w; j ) {
            // Searching for the best d for the current pixel
            best_d = maxd;
            best_score = -1;
            for (d = mind; d <= maxd; d ) {
                // Calculating the blocks' means
                lbmean = 0;
                rbmean = 0;
                for (i_b = -bsy/2; i_b < bsy/2; i_b ) {
                    for (j_b = -bsx/2; j_b < bsx/2; j_b ) {
                        // Borders checking
                        if (!(i i_b >= 0) || !(i i_b < h) || !(j j_b >= 0) || !(j j_b < w) || !(j j_b-d  >= 0) || !(j j_b-d < w)) {
                                continue;
                        }
                        // Calculatiing indices of the block within the whole image
                        ind_l = (i i_b)*w (j j_b);
                        ind_r = (i i_b)*w (j j_b-d);
                        // Updating the blocks' means
                        lbmean = left[ind_l];
                        rbmean = right[ind_r];
                    }
                }
                lbmean /= bsize;
                rbmean /= bsize;
                
                // Calculating ZNCC for given value of d
                lbstd = 0;
                rbstd = 0;
                current_score = 0;
                
                // Calculating the nomentaor and the standard deviations for the denominator
                for (i_b = -bsy/2; i_b < bsy/2; i_b ) {
                    for (j_b = -bsx/2; j_b < bsx/2; j_b ) {
                        // Borders checking
                        if (!(i i_b >= 0) || !(i i_b < h) || !(j j_b >= 0) || !(j j_b < w) || !(j j_b-d  >= 0) || !(j j_b-d < w)) {
                                continue;
                        }
                        // Calculatiing indices of the block within the whole image
                        ind_l = (i i_b)*w (j j_b);
                        ind_r = (i i_b)*w (j j_b-d);
                            
                        cl = left[ind_l] - lbmean;
                        cr = right[ind_r] - rbmean;
                        lbstd = cl*cl;
                        rbstd = cr*cr;
                        current_score = cl*cr;
                    }
                }
                // Normalizing the denominator
                current_score /= sqrt(lbstd)*sqrt(rbstd);
                // Selecting the best disparity
                if (current_score > best_score) {
                    best_score = current_score;
                    best_d = d;
                }
            }
            dmap[i*w j] = (uint8_t) abs(best_d); // Considering both Left to Right and Right to left disparities
        } 
    }
    
    return dmap;
}

标签: OpenCL CPU ZNCC GPU

实例下载地址

zncc的CPU和openCL代码实现

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警