OpenCV——旋转模糊 (二)
// 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;
int n_point=1;
float angle=30;
float w=angle*3.1415926/180;
float w_2=w*w;
int Num=3;
int Num2=Num*Num;
Point Center(width/2, height/2);
float t1, t2, t3;
int x1, y1;
int x2, y2;
int new_x, new_y;
for (int y=0; y<height; y++)
{
for (int x=0; x<width; x++)
{
n_point=1;
x1=x-Center.x;
y1=Center.y-y;
t1=Img_in.at<Vec3b>(y, x)[0];
t2=Img_in.at<Vec3b>(y, x)[1];
t3=Img_in.at<Vec3b>(y, x)[2];
x2=x1; y2=y1;
for (int mm=0; mm<Num; mm++)
{
x1=x2;
y1=y2;
// anticlockwise
x2=x1-w*y1/Num-w_2*x1/Num2;
y2=y1+w*x1/Num-w_2*y1/Num2;
// clockwise
//x2=x1+w*y1/Num-w_2*x1/Num2;
//y2=y1-w*x1/Num-w_2*y1/Num2;
new_x=x2+Center.x;
new_y=Center.y-y2;
if (new_x>0 && new_x<width-1 && new_y>0 && 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];
n_point++;
}
}
Img_out.at<Vec3f>(y, x)[0]=t1/n_point;
Img_out.at<Vec3f>(y, x)[1]=t2/n_point;
Img_out.at<Vec3f>(y, x)[2]=t3/n_point;
}
}
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——旋转模糊 (二)的更多相关文章
- OpenCV——旋转模糊
参考来源: 学习OpenCV:滤镜系列(5)--径向模糊:缩放&旋转 // define head function #ifndef PS_ALGORITHM_H_INCLUDED #defi ...
- OpenCV探索之路(二十四)图像拼接和图像融合技术
图像拼接在实际的应用场景很广,比如无人机航拍,遥感图像等等,图像拼接是进一步做图像理解基础步骤,拼接效果的好坏直接影响接下来的工作,所以一个好的图像拼接算法非常重要. 再举一个身边的例子吧,你用你的手 ...
- PS 滤镜——旋转模糊
这里给出灰度图像的模糊算法,彩色图像只要分别对三个通道做模糊即可. %% spin blur % 旋转模糊 clc; clear all; close all; I=imread('4.jpg'); ...
- opencv 增强现实(二):特征点匹配
import cv2 as cv import numpy as np # def draw_keypoints(img, keypoints): # for kp in keypoints: # x ...
- 图片人脸检测——OpenCV版(二)
图片人脸检测 人脸检测使用到的技术是OpenCV,上一节已经介绍了OpenCV的环境安装,点击查看. 往期目录 视频人脸检测——Dlib版(六)OpenCV添加中文(五)图片人脸检测——Dlib版(四 ...
- SpinBlur - 旋转模糊
[SpinBlur - 旋转模糊] Using the Spin Blur effect, you can rotate and blur the image around one or more p ...
- Python: PS 滤镜--旋转模糊
本文用 Python 实现 PS 滤镜中的旋转模糊,具体的算法原理和效果可以参考之前的博客: http://blog.csdn.net/matrix_space/article/details/392 ...
- opencv 简单模糊和高斯模糊 cvSmooth
cv::Mat 是C++版OpenCV的新结构. cvSmooth() 是老版 C API. 没有把C接口与C + + 结合. 建议你们也可以花一些时间看一下介绍. 同样,你如果查看opencv/mo ...
- OpenCV探索之路(二十三):特征检测和特征匹配方法汇总
一幅图像中总存在着其独特的像素点,这些点我们可以认为就是这幅图像的特征,成为特征点.计算机视觉领域中的很重要的图像特征匹配就是一特征点为基础而进行的,所以,如何定义和找出一幅图像中的特征点就非常重要. ...
随机推荐
- Unity3D研究院之在开始学习拓展编辑器
Unity拥有非常丰富的拓展编辑器接口,如果是在网上下载过别人写的插件,你会发现为什么它的监测面板视图和普通的不一样?其实是他通过代码自己绘制的监测面板,这篇博文MOMO带大家来学习编辑器.如下图所示 ...
- Netty实战
一.Netty异步和事件驱动1.Java网络编程回顾socket.accept 阻塞socket.setsockopt /非阻塞2.NIO异步非阻塞a).nio 非阻塞的关键时使用选择器(java.n ...
- Redis加锁与解锁
Redis加锁 customerM = BaseMemCached.setMLock(customerId); /** * 个人账户表加锁 **/ public static CustomerM se ...
- mysql 不同库不同表字段数据复制
需求:把一个表某个字段内容复制到另一张表的某个字段. 实现sql语句1: UPDATE file_manager_folder f1 LEFT OUTER JOIN file_manager_fold ...
- iOS 线程管理的学习记录
本文转载至 http://www.2cto.com/kf/201312/265451.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 ...
- 关于使用Tomcat服务器出现413错误的解决办法(Request Entity Too Large)
解决的办法: 修改tomcat的配置文件C:/MinyooCMS/tomcat/conf/server.xml(或者安装在D盘文件路径是D: /MinyooCMS/tomcat/conf/server ...
- 使用Socket通信实现FTP客户端程序
FTP 客户端如 FlashFXP,File Zilla 被广泛应用,原理上都是用底层的 Socket 来实现.FTP 客户端与服务器端进行数据交换必须建立两个套接字,一个作为命令通道,一个作为数据通 ...
- csv文件的格式
csv, comma separated values csv是一种纯文本文件. csv文件由任意数目的记录构成,记录间以换行符分割,每条记录由字段构成,字段间以逗号作为分隔符. 如果字段中有逗号,那 ...
- spring mvc 基本原理
在web.xml配置spring mvc入口servlet: <servlet> <servlet-name>mvc-dispatcher</servlet-name&g ...
- Latex: Expression under summation on multiple lines
Purpose Describe the sum symbol like this: zebk=1Nk∑i∈Rkj∈W(i)∩Rkmax(fi−fj) Solution code z_{ebk}=\f ...