Opencv— — kaleidoscope Filter
// define head function
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED
#include <iostream>
#include <string>
#include "cv.h"
#include "highgui.h"
#include "cxmat.hpp"
#include "cxcore.hpp"
#include "math.h"
using namespace std;
using namespace cv;
void Show_Image(Mat&, const string &);
#endif // PS_ALGORITHM_H_INCLUDED
/*
generate the circle transform
*/
#include "PS_Algorithm.h"
#include <time.h>
using namespace std;
using namespace cv;
#define pi 3.1415926
float Triangle(float x);
int main()
{
string Img_name("4.jpg");
Mat Img;
Img=imread(Img_name);
Mat Img_out(Img.size(), CV_8UC3);
int width=Img.cols;
int height=Img.rows;
float angle = pi/4;
float angle2=pi/4;
float centreX = 0.5;
float centreY = 0.5;
float sides = 10;
float icentreX=width*centreX;
float icentreY=height*centreY;
float radius=150;
float dx,dy,new_x,new_y;
float p,q,x1,y1;
float c, r, theta, temp_theta, radius_c;
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
dx=x-icentreX;
dy=y-icentreY;
theta=atan2(dy, dx)-angle-angle2;
r=sqrt(dy*dy+dx*dx);
temp_theta=theta/pi*sides*0.5;
theta=Triangle(temp_theta);
if (radius)
{
c=cos(theta);
radius_c=radius/c;
r=radius_c * Triangle(r/radius_c);
}
theta=theta+angle;
new_x=r * cos(theta)+icentreX;
new_y=r * sin(theta)+icentreY;
if(new_x<0) new_x=0;
if(new_x>=width-1) new_x=width-2;
if(new_y<0) new_y=0;
if(new_y>=height-1) new_y=height-2;
// if (new_x<0) continue;
// if (new_x>=width-1) continue;
// if (new_y>=height-1) continue;
// if (new_y<0) continue;
x1=(int)new_x;
y1=(int)new_y;
p=new_x-x1;
q=new_y-y1;
for (int k=0; k<3; k++)
{
Img_out.at<Vec3b>(y, x)[k]=(1-p)*(1-q)*Img.at<Vec3b>(y1, x1)[k]+
(p)*(1-q)*Img.at<Vec3b>(y1,x1+1)[k]+
(1-p)*(q)*Img.at<Vec3b>(y1+1,x1)[k]+
(p)*(q)*Img.at<Vec3b>(y1+1,x1+1)[k];
}
}
}
Show_Image(Img_out, "out");
cout<<"All is well"<<endl;
// imwrite("Out.jpg", Img_out);
waitKey();
}
float Triangle(float x)
{
float temp_r=fmod(x, 1.0);
if (temp_r<0.5)
{
return 2*temp_r;
}
else
{
return 2*(1-temp_r);
}
}
// define the show image
#include "PS_Algorithm.h"
#include <iostream>
#include <string>
using namespace std;
using namespace cv;
void Show_Image(Mat& Image, const string& str)
{
namedWindow(str.c_str(),CV_WINDOW_AUTOSIZE);
imshow(str.c_str(), Image);
}
图像效果可以参考:
http://blog.csdn.net/matrix_space/article/details/46789783
Opencv— — kaleidoscope Filter的更多相关文章
- Opencv— — Circle Filter
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- Opencv— — Pinch Filter
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- Opencv— — Twirl Filter
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- 【Python】PIL模块
Python自建库,在爬虫等基础应用中更加简单好记,做整理以备自查. 目录 Image模块 open类.Save类.format类.Mode类.convert类.Size类.Info类.new类.Co ...
- django 操作数据库--orm(object relation mapping)---models
思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...
- 解析opencv中Box Filter的实现并提出进一步加速的方案(源码共享)。
说明:本文所有算法的涉及到的优化均指在PC上进行的,对于其他构架是否合适未知,请自行试验. Box Filter,最经典的一种领域操作,在无数的场合中都有着广泛的应用,作为一个很基础的函数,其性能的好 ...
- 卡尔曼滤波—Simple Kalman Filter for 2D tracking with OpenCV
之前有关卡尔曼滤波的例子都比较简单,只能用于简单的理解卡尔曼滤波的基本步骤.现在让我们来看看卡尔曼滤波在实际中到底能做些什么吧.这里有一个使用卡尔曼滤波在窗口内跟踪鼠标移动的例子,原作者主页:http ...
- OpenCV导向滤波(引导滤波)实现(Guided Filter)代码,以及使用颜色先验算法去雾
论文下载地址:http://research.microsoft.com/en-us/um/people/jiansun/papers/GuidedFilter_ECCV10.pdf 本文主要介绍导向 ...
- [OpenCV] Samples 14: kalman filter
Ref: http://blog.csdn.net/gdfsg/article/details/50904811 #include "opencv2/video/tracking.hpp&q ...
随机推荐
- Android动画系列 - PropertyAnim 详解
前言:上一篇文章传统View动画与Property动画基础及比较简单对Android动画系统的基础做了介绍,本篇文章将对PropertyAnimation进行全面深入的探讨,本篇文章可以分为两大块,从 ...
- 以面试官的角度看strcpy函数
一:笔试或者面试的总结 之 一 (1)在笔试或者面试中常常会被问道,strcpy memmove memcpy 函数的实现.有时也会问你STL 中string的 split 和 trim的实现.有的 ...
- poj 1651 Multiplication Puzzle【区间DP】
题目链接:http://poj.org/problem? id=1651 题意:初使ans=0,每次消去一个值,位置在pos(pos!=1 && pos !=n) 同一时候ans+=a ...
- 批量杀死mysql进程
http://www.chengyongxu.com/blog/%E6%89%B9%E9%87%8F%E6%9D%80%E6%AD%BBmysql%E8%BF%9B%E7%A8%8B/
- create a backdoor deb package
以下介绍怎样制作包括后门的deb安装包.以tree为例进行说明.利用apt-get下载安装包.--download-only表示仅仅下载不做其它处理. root@deb:~#apt-get downl ...
- c语言知识点总结-------静态区、堆、栈、常量区等
在C语言中地址占4个字节 1.编程语言发展 低级语言----->高级语言 机器语言 ---> 汇编---->高级语言(C语言.C++.JAVA等) 机器语言 :0101 0010 1 ...
- 第一个php小程序(学习)
</pre><pre name="code" class="php"><? php $b=array("name&quo ...
- maven的坑2
导入工程后,pom.xml文件中以下插件报错: <plugin> <groupId>com.jayway.maven.plugins.android.generation2&l ...
- gcc參数总结
/*gcc 命令总结*/ 补充下gcc的知识,免得被大自然说编译原理不行.. 1.-o 參数 參数说明: -o參数用来指定生成程序的名字 gcc test.c 会编译出一个名为a.out的程序 gcc ...
- babylon使用3dsmax导出的obj文件时模型偏暗
将模型的material的diffuseTexture设置为null即可