资源简介
基于2D的左眼和右眼彩色图片,合成立体图片!
代码片段和文件信息
#include “DIBR.h“
void DIBR(IplImage *colorIplImage *depthIplImage *dibr_n)//generate right image and fill holes
{
IplImage *gray_b*gray_g*gray_r;
IplImage *dibr_b*dibr_g*dibr_r;
gray_b=cvCreateImage(cvGetSize(depth)IPL_DEPTH_8U1);
gray_g=cvCreateImage(cvGetSize(depth)IPL_DEPTH_8U1);
gray_r=cvCreateImage(cvGetSize(depth)IPL_DEPTH_8U1);
dibr_b=cvCreateImage(cvGetSize(depth)IPL_DEPTH_8U1);
cvSetZero(dibr_b);
dibr_g=cvCreateImage(cvGetSize(depth)IPL_DEPTH_8U1);
cvSetZero(dibr_g);
dibr_r=cvCreateImage(cvGetSize(depth)IPL_DEPTH_8U1);
cvSetZero(dibr_r);
cvSplit(colorgray_bgray_ggray_rNULL);
int table[256];
int knear = 0; // knear = 0 means everything is displayed behind the screen
int kfar = 128;
int xb = 6; // eye seperation distance 6cm
int D = 800; // view distance 3m
int Npix = 320; // standard definition display to reduce the parallax (maybe 720 better!!)
for (int i = 0; i < 256; i++)
{
double A = i * ( knear/64 + kfar/16 ) / 255;
double h = - xb * Npix * ( A-kfar/16) / D;
table[i] = (int)(h/2);
}
int S = 25; // depth=0 maxmium shift. !!If Npix changes this value will change!!
int step = depth->widthStep/sizeof(uchar);
uchar* datadepth = (uchar*)depth->imageData;
uchar* datagray_b = (uchar*)gray_b->imageData;
uchar* datagray_g = (uchar*)gray_g->imageData;
uchar* datagray_r = (uchar*)gray_r->imageData;
uchar* datadibr_b = (uchar*)dibr_b->imageData;
uchar* datadibr_g = (uchar*)dibr_g->imageData;
uchar* datadibr_r = (uchar*)dibr_r->imageData;
//generate right image from color image and associated depth
for (int i=0; iheight;i++)
{
for (int j=0; jwidth; j++)
{
int d = (int)(datadepth[i*step+j]);
int shift = table[d];
if (j+shift-S>=0)
{
datadibr_b[i*step+j+shift-S] = datagray_b[i*step+j];
}
}
}
for (int i=0; iheight;i++)
{
for (int j=0; jwidth; j++)
{
int d = (int)(datadepth[i*step+j]);
int shift = table[d];
if (j+shift-S>=0)
{
datadibr_g[i*step+j+shift-S] = datagray_g[i*step+j];
}
}
}
for (int i=0; iheight;i++)
{
for (int j=0; jwidth; j++)
{
int d = (int)(datadepth[i*step+j]);
int shift = table[d];
if (j+shift-S>=0)
{
datadibr_r[i*step+j+shift-S] = datagray_r[i*step+j];
}
}
}
cvMerge(dibr_bdibr_gdibr_rNULLdibr_n);
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 31070 2013-06-13 09:35 DIBR程序\depth00300.jpg
文件 32256 2013-06-13 10:09 DIBR程序\DIBR\Debug\DIBR.exe
文件 355336 2013-06-13 10:09 DIBR程序\DIBR\Debug\DIBR.ilk
文件 1141760 2013-06-13 10:09 DIBR程序\DIBR\Debug\DIBR.pdb
文件 1130 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\cl.command.1.tlog
文件 25692 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\CL.read.1.tlog
文件 610 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\CL.write.1.tlog
文件 406 2013-06-13 10:02 DIBR程序\DIBR\DIBR\Debug\DIBR.exe.em
文件 472 2013-06-13 10:02 DIBR程序\DIBR\DIBR\Debug\DIBR.exe.em
文件 381 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\DIBR.exe.intermediate.manifest
文件 46 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\DIBR.lastbuildstate
文件 2110 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\DIBR.log
文件 69847 2013-06-13 10:02 DIBR程序\DIBR\DIBR\Debug\DIBR.obj
文件 198 2013-06-13 10:02 DIBR程序\DIBR\DIBR\Debug\DIBR_manifest.rc
文件 2 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 2 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 2 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 2 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 2 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 2 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 1602 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 3438 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 556 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\li
文件 67610 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\main.obj
文件 324 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\mt.command.1.tlog
文件 290 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\mt.read.1.tlog
文件 222 2013-06-13 10:09 DIBR程序\DIBR\DIBR\Debug\mt.write.1.tlog
文件 414 2013-06-13 10:02 DIBR程序\DIBR\DIBR\Debug\rc.command.1.tlog
文件 194 2013-06-13 10:02 DIBR程序\DIBR\DIBR\Debug\rc.read.1.tlog
文件 202 2013-06-13 10:02 DIBR程序\DIBR\DIBR\Debug\rc.write.1.tlog
............此处省略30个文件信息
评论
共有 条评论