参考来源:

学习OpenCV:滤镜系列(5)——径向模糊:缩放&旋转

// 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 /*
This program will generate
spin blur effect */ #include "PS_Algorithm.h"
#include <time.h> using namespace std;
using namespace cv; int main()
{
string Img_name("4.jpg");
Mat Img_in;
Img_in=imread(Img_name);
Show_Image(Img_in, Img_name); Mat Img_out(Img_in.size(), CV_32FC3);
Img_in.convertTo(Img_out, CV_32FC3); int width=Img_in.cols;
int height=Img_in.rows; float R;
float angle; Point Center(width/2, height/2);
float t1, t2, t3;
int new_x, new_y; int Num=30; for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
t1=0; t2=0; t3=0;
R=sqrt((y-Center.y)*(y-Center.y)+(x-Center.x)*(x-Center.x));
angle=atan2((float)(y-Center.y), (float)(x-Center.x));
for (int mm=0; mm<Num; mm++)
{
angle=angle+0.01; new_x=R*cos(angle)+Center.x;
new_y=R*sin(angle)+Center.y; if(new_x<0) new_x=0;
if(new_x>width-1) new_x=width-1;
if(new_y<0) new_y=0;
if(new_y>height-1)new_y=height-1; t1=t1+Img_in.at<Vec3b>(new_y, new_x)[0];
t2=t2+Img_in.at<Vec3b>(new_y, new_x)[1];
t3=t3+Img_in.at<Vec3b>(new_y, new_x)[2]; } Img_out.at<Vec3f>(y, x)[0]=t1/Num;
Img_out.at<Vec3f>(y, x)[1]=t2/Num;
Img_out.at<Vec3f>(y, x)[2]=t3/Num; }
} Img_out=Img_out/255.0;
Show_Image(Img_out, "out"); imwrite("Out.jpg", Img_out*255); 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); }

原图

效果图

OpenCV——旋转模糊的更多相关文章

  1. OpenCV——旋转模糊 (二)

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

  2. PS 滤镜——旋转模糊

    这里给出灰度图像的模糊算法,彩色图像只要分别对三个通道做模糊即可. %%  spin blur % 旋转模糊 clc; clear all; close all; I=imread('4.jpg'); ...

  3. SpinBlur - 旋转模糊

    [SpinBlur - 旋转模糊] Using the Spin Blur effect, you can rotate and blur the image around one or more p ...

  4. Python: PS 滤镜--旋转模糊

    本文用 Python 实现 PS 滤镜中的旋转模糊,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/392 ...

  5. opencv 简单模糊和高斯模糊 cvSmooth

    cv::Mat 是C++版OpenCV的新结构. cvSmooth() 是老版 C API. 没有把C接口与C + + 结合. 建议你们也可以花一些时间看一下介绍. 同样,你如果查看opencv/mo ...

  6. opencv之模糊处理

    初学OpenCV的开发者很容易被OpenCV中各种滤波方法所困扰,不知道到底该用哪里一个来做滤波.表面原因看起来是因为OpenCV中各种滤波方式实在是太多太杂, 其背后原因是对各种滤波方法的应用场景认 ...

  7. OPENCV 旋转图像算法-汇总

      void ImgRotate(cv::Mat imgIn, float theta, cv::Mat& imgOut) { int oldWidth = imgIn.cols; int o ...

  8. opencv 双边模糊,膨胀腐蚀 开 闭操作

    #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; int main(int argc, ...

  9. opencv知识积累

    1.OpenCV 3计算机视觉:Python语言实现 https://github.com/techfort/pycv 2.OpenCV3编程入门 opencv 均值模糊:一般用来处理图像的随机噪声 ...

随机推荐

  1. .net发布网站步骤

    本文章分为三个部分: web网站发布.IIS6 安装方法.ASP.NET v4.0 安装方法 一.web网站发布 1.打开 Visual Studio 2013 编译环境 2.在其解决方案上右击弹出重 ...

  2. H5网页判断手机横屏或是竖屏

    我们做出来的H5页面在手机端浏览的时候,用户很有可能会产生更换横竖屏的操作,这时如果我们能够判断出横竖屏,就可以更好的优化我们的网页,进而拥有更好的用户体验度.下面是判断横竖屏的代码: window. ...

  3. 浅谈iOS中MVVM的架构设计与团队协作【转载】

    今天写这篇文章是想达到抛砖引玉的作用,想与大家交流一下思想,相互学习,博文中有不足之处还望大家批评指正.本篇文章的内容沿袭以往博客的风格,也是以干货为主,偶尔扯扯咸蛋(哈哈~不好好工作又开始发表博客啦 ...

  4. hibernate 配置文件无自动提示

    在编辑 *.hbm.xml 文件时,myeclipse 带有自动提示功能,但 eclipse 是没有自动提示功能的.需要自己手工加上:           1.打开项目中任意一个 *.hbm.xml ...

  5. HDFS源码分析之数据块及副本状态BlockUCState、ReplicaState

    关于数据块.副本的介绍,请参考文章<HDFS源码分析之数据块Block.副本Replica>. 一.数据块状态BlockUCState 数据块状态用枚举类BlockUCState来表示,代 ...

  6. 深度解析 | 秒懂AI+智慧手机实践

    阅读数:17 ​​​随着人工智能的概念越来越深入人心,智慧化生活和对应的智慧化终端体验也吸引越来越多的目光.可以想见,人工智能会深刻改变终端产业,但目前也面临各种挑战和问题.此前,在南京软件大会上,华 ...

  7. nginx配置1:借助Nginx搭建反向代理服务器与缓存静态文件

    修改配置文件nginx.conf (1)进程数与每个进程的最大连接数: •nginx进程数,建议设置为等于CPU总核心数 •单个进程最大连接数,那么该服务器的最大连接数=连接数*进程数 (2)Ngin ...

  8. 有状态的EJB对象和无状态的EJB对象

    一,定义有状态Bean和无状态Bean 有状态Bean: @Stateful @Remote public class StatefulEjbBean implements StatefulEjb{ ...

  9. Unity3D自定义编辑器简单实例

    MenuItem:在标题栏自定义菜单.需要在Editor文件夹内创建脚本,无需挂载.但是注意其下的函数必须为静态函数. using UnityEngine; using UnityEditor; pu ...

  10. 微信小程序TabBar的使用

    一.TabBar使用步骤 1.创建所需要的界面和所需要的图片: 2.配置文件: 我们找到项目根目录中的配置文件 app.json 加入如下配置信息 "tabBar": { &quo ...