// 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 water wave effect */ #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; int wavelength = 20;
int amplitude = 30;
float phase = pi/4;
float centreX = 0.25;
float centreY = 0.5;
float radius = 0; 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,x0,y0;
float distance, distance2;
float amount; for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{ dx=x-icentreX;
dy=y-icentreY; distance2=dx*dx+dy*dy; if (distance2>radius2)
{
new_x=x;
new_y=y;
}
else
{
distance=sqrt(distance2);
amount=amplitude * sin(distance / wavelength * 2*pi - phase);
amount =amount* (radius-distance)/radius;
amount=amount*wavelength/(distance+0.0001); new_x =x + dx*amount;
new_y =y + dy*amount;
} 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"); // 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/46789113

Opencv— — water wave的更多相关文章

  1. PS 滤镜——水波 water wave

    %%%% Water wave %%%% 制作水波效果 clc; clear all; close all; addpath('E:\PhotoShop Algortihm\Image Process ...

  2. 滚动视差?CSS 不在话下

    何为滚动视差 视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验. 作为网页设计的热点趋势,越来越多的网站应用了这项技术. 通常 ...

  3. Unity Shader 入门精要学习 (冯乐乐 著)

    第1篇 基础篇 第1章 欢迎来到Shader的世界 第2章 渲染流水线 第3章 Unity Shader 基础 第4章 学习Shader所需的数学基础 第2篇 初级篇 第5章 开始Unity Shad ...

  4. 微信emoji的code

    const MAP = [        "\xc2\xa9" => 'COPYRIGHT SIGN',        "\xc2\xae" => ...

  5. 你所不知道的 CSS 阴影技巧与细节 滚动视差?CSS 不在话下 神奇的选择器 :focus-within 当角色转换为面试官之后 NPOI 教程 - 3.2 打印相关设置 前端XSS相关整理 委托入门案例

    你所不知道的 CSS 阴影技巧与细节   关于 CSS 阴影,之前已经有写过一篇,box-shadow 与 filter:drop-shadow 详解及奇技淫巧,介绍了一些关于 box-shadow  ...

  6. [转]滚动视差?CSS 不在话下/background attachment

      何为滚动视差 视差滚动(Parallax Scrolling)是指让多层背景以不同的速度移动,形成立体的运动效果,带来非常出色的视觉体验. 作为网页设计的热点趋势,越来越多的网站应用了这项技术. ...

  7. Unity Shader入门精要学习笔记 - 第15章 使用噪声

    转载自 冯乐乐的 <Unity Shader 入门精要> 消融效果 消融效果常见于游戏中的角色死亡.地图烧毁等效果.这这些效果中,消融往往从不同的区域开始,并向看似随机的方向扩张,最后整个 ...

  8. Project Euler 42 Coded triangle numbers

    题意:三角形数序列的第n项由公式tn = 1/2n(n+1)给出:因此前十个三角形数是: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, - 将一个单词的每个字母分别转化为其 ...

  9. OpenCV——PS滤镜之 波浪效果 wave

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

随机推荐

  1. 【CSS】获取元素的z-index值以及各种值的意义

    js可以获取其元素的z-index值: $("document").ready(function(){ var a = $('.row').css('z-index'); aler ...

  2. go 协程与主线程强占运行

    最近在学习了Go 语言 ,  正好学习到了 协程这一块 ,遇到了困惑的地方.这个是go语言官方文档 . 在我的理解当中是,协程只能在主线程释放时间片后才会经过系统调度来运行协程,其实正确的也确实是这样 ...

  3. Android 调用.so包时报错:No implementation found for native Lxxx, java.lang.UnsatisfiedLinkError: XXX时的解决办法(转)

    问题就是在调用自己同事写的.so包时,怎么也掉不通,程序一直报错退出,错误内容就是: 1 No implementation found for native Lxxx, 2 Java.lang.Un ...

  4. [反汇编练习] 160个CrackMe之030

    [反汇编练习] 160个CrackMe之030. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  5. tomcat7设置usernamepassword

    因为tomcat是绿色版.今天想在网页上管理项目,却发现没实username和password.打开tomcat-users.xml文件全都是凝视.如图: 将例如以下代码拷贝到tomcat-users ...

  6. Cookie学习笔记二:Cookie实例

    今天说说刚刚学到的两个Cookie的最经典应用:自己主动登录和购物车设置 一:自己主动登录 须要两个页面:login.jsp与index.jsp,login.jsp用来输出登录信息,index.jsp ...

  7. UVA 1541 - To Bet or Not To Bet(概率递推)

    UVA 1541 - To Bet or Not To Bet 题目链接 题意:这题题意真是神了- -.看半天,大概是玩一个游戏,開始在位置0.终点在位置m + 1,每次扔一个硬币,正面走一步,反面走 ...

  8. 使用Python与数据库交互

    # -*- coding: utf-8 -*- """ Created on Sun Nov 18 19:25:01 2018 @author: wangm " ...

  9. js event 的target 和currentTarget

    target  点击的实际tag currentTarget 绑定事件的target

  10. Coding/Github/Bitbucket 地址

    Coding:https://coding.net/u/OberonTony Github:https://github.com/Oberon-Tonya Bitbucket:https://bitb ...