全景图像展开

来源:互联网 发布:ubuntu谷歌拼音输入法 编辑:程序博客网 时间:2024/06/05 04:17
  1. #include <fstream.h>  
  2. #include <math.h>  
  3. #include <cv.h>  
  4. #include <highgui.h>   
  5. #define PI 3.1415926  
  6.   
  7.    
  8.   
  9. int inner_Radius = 50;   //全景图像的内径  
  10. int outer_Radius = 100;  //全景图像的外径  
  11. int x_dot = 177;         //全景图像的圆心X坐标  
  12. int y_dot = 130;         //全景图像的圆心y坐标  
  13.   
  14. int Width = int(2 * PI * outer_Radius);   //展开图像的宽  
  15. int Height = outer_Radius - inner_Radius; //展开图像的高  
  16.   
  17.    
  18.  //获取角度
  19. double GetAngle(int i_ExpandWidth,int i_ExpandHeight)  
  20. {  
  21.  double dw_Angle = (double)i_ExpandWidth/(double)outer_Radius ;  
  22.  return dw_Angle;  
  23. }  
  24.   
  25. int GetRadius(int i_ExpandWidth,int i_ExpandHeight)  
  26. {  
  27.  return i_ExpandHeight ;  
  28. }  
  29.   
  30. CvPoint FindPoint(double dw_Angle,int i_Radius)  
  31. {  
  32.  double x,y;  
  33.  i_Radius += inner_Radius;  
  34.  x = i_Radius * cos(dw_Angle) + x_dot;  
  35.  y = i_Radius * sin(dw_Angle) + y_dot;  
  36.  CvPoint pt = {(int)x,(int)y};  
  37.   
  38.  return pt;  
  39. }  
  40.   
  41. uchar* GetRGB(int x,int y,IplImage* src)  
  42. {  
  43.  uchar* temp_src=&((uchar*)(src->imageData + src->widthStep * y))[x * 3];  //读取图片像素值
  44.  return temp_src;  
  45. }  
  46.   
  47.   
  48. void main()  
  49. {  
  50.  int i,j;  
  51.  double dw_Angle;  
  52.  int i_Radius;  
  53.  CvPoint pt;  
  54.  IplImage* src,* dst;  
  55.  src = cvLoadImage("src.bmp");  
  56.  dst = cvCreateImage(cvSize(Width,Height),8,3);  
  57.  dst->origin = 0;  //dst初始位置赋值为0
  58.  cvZero(dst);  
  59.  for(i = 0 ; i < Width ; i++)  
  60.   for(j = 0 ; j < Height ; j++)      
  61.   {  
  62.    dw_Angle = GetAngle(i,j);  
  63.    i_Radius = GetRadius(i,j);  
  64.    pt = FindPoint( dw_Angle, i_Radius);  
  65.    uchar* temp_src = GetRGB( pt.x,pt.y,src);  
  66.    ((uchar*)(dst->imageData + dst->widthStep * j))[i * 3] = temp_src[0];  
  67.    ((uchar*)(dst->imageData + dst->widthStep * j))[i * 3 + 1] = temp_src[1];  
  68.    ((uchar*)(dst->imageData + dst->widthStep * j))[i * 3 + 2] = temp_src[2];    
  69.   }  
  70.   
  71.  cvSaveImage("dst.bmp", dst);  
  72.  cvNamedWindow( "Image src view", 1 );  
  73.  cvNamedWindow( "Image dst view", 1 );  
  74.  cvShowImage( "Image src view", src );  
  75.  cvShowImage( "Image dst view", dst );  
  76.  cvWaitKey(0);  
  77.  cvDestroyWindow( "Image src view" );  
  78.  cvDestroyWindow( "Image dst view" );  
  79.  cvReleaseImage( &src );  
  80.  cvReleaseImage( &dst );  
  81. }  
原创粉丝点击