1. // define head function
  2. #ifndef PS_ALGORITHM_H_INCLUDED
  3. #define PS_ALGORITHM_H_INCLUDED
  4. #include <iostream>
  5. #include <string>
  6. #include "cv.h"
  7. #include "highgui.h"
  8. #include "cxmat.hpp"
  9. #include "cxcore.hpp"
  10. #include "math.h"
  11. using namespace std;
  12. using namespace cv;
  13. void Show_Image(Mat&, const string &);
  14. #endif // PS_ALGORITHM_H_INCLUDED
  15. /*
  16. generate the circle transform
  17. */
  18. #include "PS_Algorithm.h"
  19. #include <time.h>
  20. using namespace std;
  21. using namespace cv;
  22. #define pi 3.1415926
  23. float Triangle(float x);
  24. int main()
  25. {
  26. string Img_name("4.jpg");
  27. Mat Img;
  28. Img=imread(Img_name);
  29. Mat Img_out(Img.size(), CV_8UC3);
  30. int width=Img.cols;
  31. int height=Img.rows;
  32. float angle = pi/4;
  33. float angle2=pi/4;
  34. float centreX = 0.5;
  35. float centreY = 0.5;
  36. float sides = 10;
  37. float icentreX=width*centreX;
  38. float icentreY=height*centreY;
  39. float radius=150;
  40. float dx,dy,new_x,new_y;
  41. float p,q,x1,y1;
  42. float c, r, theta, temp_theta, radius_c;
  43. for (int y=0; y<height; y++)
  44. {
  45. for (int x=0; x<width; x++)
  46. {
  47. dx=x-icentreX;
  48. dy=y-icentreY;
  49. theta=atan2(dy, dx)-angle-angle2;
  50. r=sqrt(dy*dy+dx*dx);
  51. temp_theta=theta/pi*sides*0.5;
  52. theta=Triangle(temp_theta);
  53. if (radius)
  54. {
  55. c=cos(theta);
  56. radius_c=radius/c;
  57. r=radius_c * Triangle(r/radius_c);
  58. }
  59. theta=theta+angle;
  60. new_x=r * cos(theta)+icentreX;
  61. new_y=r * sin(theta)+icentreY;
  62. if(new_x<0) new_x=0;
  63. if(new_x>=width-1) new_x=width-2;
  64. if(new_y<0) new_y=0;
  65. if(new_y>=height-1) new_y=height-2;
  66. // if (new_x<0) continue;
  67. // if (new_x>=width-1) continue;
  68. // if (new_y>=height-1) continue;
  69. // if (new_y<0) continue;
  70. x1=(int)new_x;
  71. y1=(int)new_y;
  72. p=new_x-x1;
  73. q=new_y-y1;
  74. for (int k=0; k<3; k++)
  75. {
  76. Img_out.at<Vec3b>(y, x)[k]=(1-p)*(1-q)*Img.at<Vec3b>(y1, x1)[k]+
  77. (p)*(1-q)*Img.at<Vec3b>(y1,x1+1)[k]+
  78. (1-p)*(q)*Img.at<Vec3b>(y1+1,x1)[k]+
  79. (p)*(q)*Img.at<Vec3b>(y1+1,x1+1)[k];
  80. }
  81. }
  82. }
  83. Show_Image(Img_out, "out");
  84. cout<<"All is well"<<endl;
  85. // imwrite("Out.jpg", Img_out);
  86. waitKey();
  87. }
  88. float Triangle(float x)
  89. {
  90. float temp_r=fmod(x, 1.0);
  91. if (temp_r<0.5)
  92. {
  93. return 2*temp_r;
  94. }
  95. else
  96. {
  97. return 2*(1-temp_r);
  98. }
  99. }
  100. // define the show image
  101. #include "PS_Algorithm.h"
  102. #include <iostream>
  103. #include <string>
  104. using namespace std;
  105. using namespace cv;
  106. void Show_Image(Mat& Image, const string& str)
  107. {
  108. namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);
  109. imshow(str.c_str(), Image);
  110. }

图像效果可以参考:

http://blog.csdn.net/matrix_space/article/details/46789783

Opencv— — kaleidoscope Filter的更多相关文章

  1. Opencv— — Circle Filter

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  2. Opencv— — Pinch Filter

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  3. Opencv— — Twirl Filter

    // define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...

  4. 【Python】PIL模块

    Python自建库,在爬虫等基础应用中更加简单好记,做整理以备自查. 目录 Image模块 open类.Save类.format类.Mode类.convert类.Size类.Info类.new类.Co ...

  5. django 操作数据库--orm(object relation mapping)---models

    思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...

  6. 解析opencv中Box Filter的实现并提出进一步加速的方案(源码共享)。

    说明:本文所有算法的涉及到的优化均指在PC上进行的,对于其他构架是否合适未知,请自行试验. Box Filter,最经典的一种领域操作,在无数的场合中都有着广泛的应用,作为一个很基础的函数,其性能的好 ...

  7. 卡尔曼滤波—Simple Kalman Filter for 2D tracking with OpenCV

    之前有关卡尔曼滤波的例子都比较简单,只能用于简单的理解卡尔曼滤波的基本步骤.现在让我们来看看卡尔曼滤波在实际中到底能做些什么吧.这里有一个使用卡尔曼滤波在窗口内跟踪鼠标移动的例子,原作者主页:http ...

  8. OpenCV导向滤波(引导滤波)实现(Guided Filter)代码,以及使用颜色先验算法去雾

    论文下载地址:http://research.microsoft.com/en-us/um/people/jiansun/papers/GuidedFilter_ECCV10.pdf 本文主要介绍导向 ...

  9. [OpenCV] Samples 14: kalman filter

    Ref: http://blog.csdn.net/gdfsg/article/details/50904811 #include "opencv2/video/tracking.hpp&q ...

随机推荐

  1. 【转】css浮动元素的知识

    原文: http://www.cnblogs.com/xuyao100/p/8940958.html ------------------------------------------------- ...

  2. 控制显示input隐藏和查看密码

    通过更改input的password和text类型即可实现 //点击函数,获取dom,判断更改属性. show(){ let input=document.getElementById("i ...

  3. ubuntu boot空间不足

    在安装 Ubuntu的时候 , 给/boot文件目录分配空间的时候,是100M,/boot可以单独分成一个区,也可以不单独分,在/(根目录)下也会自动为其创建一个boot目录.顺便提一下,Linux分 ...

  4. CSS3中的动画效果-------Day72

    还记得么,在前面也曾实现过"仅仅用css让div动起来",还记得当时是怎么实现的么,是的,transition,针对的也比較局限,仅仅有旋转角度啊,长宽啊之类的,所以说,与其说是动 ...

  5. Qt5的插件机制(6)--开发Qt插件时几个重要的宏

    怎样开发Qt插件,能够在Qt Assistant 中搜索"Qt Plugins"或"How to Create Qt Plugins",看看那篇manual中的 ...

  6. How to reset your password in Ubuntu

    There are many reasons you might want to reset a password: Someone gave you a computer with Ubuntu i ...

  7. socketserver模块的使用

    import socketserver class MyTCPhandler(socketserver.BaseRequestHandler): def handle(self): # print(s ...

  8. uboot 命令

    1.清除前一次的编译结果: make distclean 2.配置makefile:选择开发板 make  smdk6410_config 3.编译 make 注意::编译时,打开的文档文件,目录都要 ...

  9. openwrt 修改 banner

    http://www.network-science.de/ascii/ rectangles 风格

  10. 计算IMEI号的校验位

    计算IMEI号的校验位 移动设备国际识别码(IMEI:International Mobile Equipment Identification Number)是差别移动设备的标志,具有唯一性,贴在手 ...