嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
图像立体匹配中的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;
}