参考来源:

学习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. SAS学习经验总结分享:篇四—SQL过程

    SQL过程 SQL过程是实现对数据集或关系数据库的表进行操作的过程,对数据集或关系数据库的表进行查询.修改.创建表.删除数据.插入数据和更新数据等功能.提现了SAS对大型数据库管理系统通用的SQL语言 ...

  2. SVN 服务端、客户端安装及配置、导入导出项目

    http://blog.csdn.net/xcy13638760/article/details/12994923 http://www.cnblogs.com/armyfai/p/3985660.h ...

  3. linux使用crontab实现PHP执行定时任务(转)

    前几天写过一篇文章,利用单纯的php实现定时执行任务,但是效率不佳,对于linux来说用crontab实现更加合理. 首先说说cron,它是一个linux下的定时执行工具.根用户以外的用户可以使用 c ...

  4. oracle恢复已经删除的数据

    insert into tablerestore select * from tablerestore as of timestamp to_Date('2014-8-8 15:00:00','yyy ...

  5. 如何理解API,API 是如何工作的

    大神博客:https://blog.csdn.net/cumtdeyurenjie/article/details/80211896

  6. CDH使用Solr实现HBase二级索引

      一.为什么要使用Solr做二级索引二.实时查询方案三.部署流程3.1 安装HBase.Solr3.2 增加HBase复制功能3.3创建相应的 SolrCloud 集合3.4 创建 Lily HBa ...

  7. 九度OJ 1080:进制转换 (进制转换)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4583 解决:1076 题目描述: 将M进制的数X转换为N进制的数输出. 输入: 输入的第一行包括两个整数:M和N(2<=M,N< ...

  8. 偏函数应用 pfa

  9. cocos2d-js v3.1的坑

    前几天因为要用到cc.pool,所以就换了v3.1版本,结果连生成apk的出错(cocos code ide), log显示为:error: relocation overflow in R_ARM_ ...

  10. 我的Java开发学习之旅------>使用Working Setst将Eclipse中的项目分类使项目一目了然

    今天发现Eclipse中若有太多的项目,杂七杂八的,看起来会非常的痛苦.今天请教公司的前辈学会了一个方法,在Eclipse中,当项目比较多的时候,我们可以用WorkingSet将这些项目分类,把相关连 ...