// 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 pinch distortion */ #include "PS_Algorithm.h"
#include <time.h> using namespace std;
using namespace cv; #define pi 3.1415926 int main()
{
string Img_name("4.jpg");
Mat Img;
Img=imread(Img_name); Mat Img_out(Img.size(), CV_8UC3);
Img.copyTo(Img_out); int width=Img.cols;
int height=Img.rows; float angle = pi/2;
float centreX = 0.5;
float centreY = 0.5;
float radius = 200;
float amount=0.5; if (radius==0) radius=std::min(width, height)/2; float icentreX=width*centreX;
float icentreY=height*centreY;
float radius2=radius*radius; float dx,dy,new_x,new_y;
float p,q,x1,y1;
float distance;
float a,d,t,s,c,e; for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{ dx=x-icentreX;
dy=y-icentreY; distance=dx*dx+dy*dy; if (distance>radius2 || distance==0)
{
new_x=x;
new_y=y;
}
else
{
d = sqrt( distance / radius2 );
t = pow(sin( pi*0.5 * d ),-amount); dx =dx* t;
dy =dy* t; e = 1 - d;
a = angle * e * e; s = sin( a );
c = cos( a ); new_x = icentreX + c*dx - s*dy;
new_y = icentreY + s*dx + c*dy;
} 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; 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();
} // 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/46789421

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

  1. Opencv— — kaleidoscope Filter

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

  2. Opencv— — Circle 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. 图像滤镜艺术---挤压(Pinch)滤镜

    原文:图像滤镜艺术---挤压(Pinch)滤镜 Pinch滤镜 Pinch滤镜是通过坐标变换来实现以某个点(cenX,cenY)为中心,某个半径R内图像向其挤压变形的效果.实现这个滤镜的算法很多,主要 ...

  5. 图像滤镜艺术---球面(Spherize)滤镜

    原文:图像滤镜艺术---球面(Spherize)滤镜 球面(Spherize)滤镜 球面滤镜是通过极坐标变换实现图像的球面特效. 代码如下:         //         ///        ...

  6. 【Python】PIL模块

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

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

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

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

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

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

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

随机推荐

  1. 深入理解Activity启动流程(三)–Activity启动的详细流程2

    本文原创作者:Cloud Chou. 欢迎转载,请注明出处和本文链接 本系列博客将详细阐述Activity的启动流程,这些博客基于Cm 10.1源码研究. 深入理解Activity启动流程(一)--A ...

  2. 45个非常有用的Oracle查询语句(转自开源中国社区)

    日期/时间 相关查询 获取当前月份的第一天 运行这个命令能快速返回当前月份的第一天.你可以用任何的日期值替换 “SYSDATE”来指定查询的日期. SELECT TRUNC (SYSDATE, 'MO ...

  3. [c++菜鸟]《Accelerate C++》习题解答

    第0章 0-0 编译并运行Hello, world! 程序. #include <iostream> using namespace std; int main() { cout < ...

  4. Android 组件之Service解析

    原创文章,转载请注明 http://blog.csdn.net/leejizhou/article/details/50866875 李济洲的博客 Service是Android四大组件之中的一个.S ...

  5. 如何下载合适自己系统环境的Xdebug

      访问https://xdebug.org     在浏览器输入http://localhost/?phpinfo=1 (前提已经安装了wamp环境) Ctrl+a 全选 ,复制 粘贴到刚才的网站的 ...

  6. odoo高级物流应用:跨厂区生产

    业务情景 半成品在分厂生产,然后再在总厂组装 半成品所需的原材料存储在分厂的仓库 总厂需要的原材料储存在总厂的仓库 公用的原材料储存在总厂的仓库     解决方案 使用仓库间的供应 设置合适的Rout ...

  7. python(33)- 模块与包

    一 模块 1 什么是模块? 一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 2 为何要使用模块? 如果你退出python解释器然后重新进入,那么你之前定义的函 ...

  8. OpenCV for Python 学习笔记 一

    本人的学习笔记主要记录的是学习opencv-python-tutorials这本书中的笔记 今天晚上简单学习OpenCV for Python如何绘图,主要用了这几个函数(这几个函数可在:http:/ ...

  9. Topcoder SRM625 题解

    给出一个字符串求是palindrome和anagram的比率是多少. 知识点: 1 DBL_MAX 64位double的最长数大概是1.7E308,非常大非常大,比long long大上不知多少倍.故 ...

  10. Active Directory的DirectoryEntry与DirectorySearcher初识及Filter语法

    前言 增删改查,我想查询是最先要说的一个了.本章主要记录使用.NET Framework进行对域控服务器对象的查询操作,介绍DirectoryEntry与DirectorySearcher(搜索器)及 ...