資源簡(jiǎn)介
實(shí)現(xiàn)360度全景圖像的拼接融合,在vs2010下,只需更換圖片,即可實(shí)現(xiàn)拼接,代碼簡(jiǎn)潔易懂。

代碼片段和文件信息
#include?
#include?
#include?
unsigned?char?imgOrg[256][256];
unsigned?char?imgSph[256][256];
unsigned?char?imgRot[256][256];
const?double?Pi?=?3.1415926;
void?Sphere_Effect(double?p_x?double?p_y?double?rds);
void?Rotate_Effect(double?p_x?double?p_y?double?rds?double?theta);
unsigned?char?Insertion_Bilinear(double?x?double?y);
void?main(void)
{
double?p_xp_yrdstheta;
int?ij;
FILE?*pic?=?fopen(“LENA_origin.raw““rb“);
for(i=0;i<256;i++)
for(j=0;j<256;j++)
imgOrg[i][j]=fgetc(pic);
fclose(pic);
printf(“Please?input?the?center?of?the?circle:?\n“);
scanf(“%lf?%lf“&p_x&p_y);
printf(“and?the?radius:?“);
scanf(“%lf“?&rds);
Sphere_Effect(p_xp_yrds);
printf(“Please?input?the?center?of?the?circle:?\n“);
scanf(“%lf?%lf“&p_x&p_y);
printf(“and?the?radius:?“);
scanf(“%lf“?&rds);
printf(“and?the?theta(in?rad):?“);
scanf(“%lf“?&theta);
Rotate_Effect(p_xp_yrdstheta);
pic?=?fopen(“LENA_sphere.raw““wb“);
for(i=0;i<256;i++)
for(j=0;j<256;j++)
fputc(imgSph[i][j]pic);
fclose(pic);
pic?=?fopen(“LENA_rotate.raw““wb“);
for(i=0;i<256;i++)
for(j=0;j<256;j++)
fputc(imgRot[i][j]pic);
fclose(pic);
return;
}
void?Sphere_Effect(double?p_x?double?p_y?double?rds)
{
int?ij;
double?thetadist;
for(i=0;i<256;i++)
for(j=0;j<256;j++)
{
dist?=?sqrt(?pow(j-p_x2)+pow(i-p_y2)?);
if(?dist?>?rds?||?dist?==?0)
imgSph[i][j]=imgOrg[i][j];
else
{
/**Whole?hemisphere**/
// theta=asin(?dist?/?rds?);
// imgSph[i][j]=Insertion_Bilinear(?p_x+(j-p_x)*theta*rds*2/Pi/dist?p_y+(i-p_y)*theta*rds*2/Pi/dist?);
/**Partial?hemisphere?with?value?Pi/3?**/
theta=atan(?dist?/?rds?/?tan(Pi/6));
imgSph[i][j]=Insertion_Bilinear(?p_x+(j-p_x)*theta*rds*3/Pi/dist?p_y+(i-p_y)*theta*rds*3/Pi/dist?);
}
}
printf(“Sphere?is?finished!?\n“);
return;
}
void?Rotate_Effect(double?p_x?double?p_y?double?rds?double?theta)
{
int?ij;
double?deltadist;
for(i=0;i<256;i++)
for(j=0;j<256;j++)
{
dist?=?sqrt(?pow(j-p_x2)+pow(i-p_y2)?);
if(?dist?>?rds?||?dist?==?0)
imgRot[i][j]=imgOrg[i][j];
else
{
delta?=?theta*(rds-dist)/rds;
if(i?>?p_y)
imgRot[i][j]=Insertion_Bilinear(?p_x+dist*cos(?acos(?(j-p_x)/dist?)+delta?)??p_y+dist*sin(?acos(?(j-p_x)/dist)+delta?)?);
else?
imgRot[i][j]=Insertion_Bilinear(?p_x+dist*cos(?2*Pi-acos(?(j-p_x)/dist?)+delta?)??p_y+dist*sin(?2*Pi-acos(?(j-p_x)/dist)+delta?)?);
}
}
printf(“Rotate?is?finished!?\n“);
}
unsigned?char?Insertion_Bilinear(double?x?double?y)
{
int?isrtValue;
int?x_base?=?(int)x;
int?y_base?=?(int)y;
isrtValue?=?(int)(?imgOrg[y_base][x_base]*(x_base+1-x)*(y_base+1-y)+imgOrg[y_base+1][x_base]*(x_base+1-x)*(y-y_base)+imgOrg[y_base][x_base+1]*(x-x_base)*(y_base+1-y)+imgOrg[y_base+1][x_base+1]*(x-x_base)*(y-y_base)?);
return?(unsigned?char)isrtValue;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????2974??2009-11-13?15:37??main.cpp
-----------?---------??----------?-----??----
?????????????????2974????????????????????1
評(píng)論
共有 條評(píng)論