全景:全景图像展开算法opencv代码

#include <fstream.h>
#include <math.h>
#include <cv.h>
#include <highgui.h> 
#define PI 3.1415926

 

int inner_Radius = 50;   //全景图像的内径
int outer_Radius = 100;  //全景图像的外径
int x_dot = 177;         //全景图像的圆心X坐标
int y_dot = 130;         //全景图像的圆心X坐标

int Width = int(2 * PI * outer_Radius);   //展开图像的宽
int Height = outer_Radius - inner_Radius; //展开图像的高

 

double GetAngle(int i_ExpandWidth,int i_ExpandHeight)
{
 double dw_Angle = (double)i_ExpandWidth/(double)outer_Radius ;
 return dw_Angle;
}

int GetRadius(int i_ExpandWidth,int i_ExpandHeight)
{
 return i_ExpandHeight ;
}

CvPoint FindPoint(double dw_Angle,int i_Radius)
{
 double x,y;
 i_Radius += inner_Radius;
 x = i_Radius * cos(dw_Angle) + x_dot;
 y = i_Radius * sin(dw_Angle) + y_dot;
 CvPoint pt = {(int)x,(int)y};

 return pt;
}

uchar* GetRGB(int x,int y,IplImage* src)
{
 uchar* temp_src=&((uchar*)(src->imageData + src->widthStep * y))[x * 3];
 return temp_src;
}


void main()
{
 int i,j;
 double dw_Angle;
 int i_Radius;
 CvPoint pt;
 IplImage* src,* dst;
 src = cvLoadImage("src.bmp");
 dst = cvCreateImage(cvSize(Width,Height),8,3);
 dst->origin = 0;
 cvZero(dst);
 for(i = 0 ; i < Width ; i++)
  for(j = 0 ; j < Height ; j++)    
  {
   dw_Angle = GetAngle(i,j);
   i_Radius = GetRadius(i,j);
   pt = FindPoint( dw_Angle, i_Radius);
   uchar* temp_src = GetRGB( pt.x,pt.y,src);
   ((uchar*)(dst->imageData + dst->widthStep * j))[i * 3] = temp_src[0];
   ((uchar*)(dst->imageData + dst->widthStep * j))[i * 3 + 1] = temp_src[1];
   ((uchar*)(dst->imageData + dst->widthStep * j))[i * 3 + 2] = temp_src[2];  
  }

 cvSaveImage("dst.bmp", dst);
 cvNamedWindow( "Image src view", 1 );
 cvNamedWindow( "Image dst view", 1 );
 cvShowImage( "Image src view", src );
 cvShowImage( "Image dst view", dst );
 cvWaitKey(0);
 cvDestroyWindow( "Image src view" );
 cvDestroyWindow( "Image dst view" );
 cvReleaseImage( &src );
 cvReleaseImage( &dst );
}


---------------------------------

转自:http://blog.sina.com.cn/s/blog_4fb72d4e01000d16.html



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值