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探索之路(二十三):特征检测和特征匹配方法汇总
一幅图像中总存在着其独特的像素点,这些点我们可以认为就是这幅图像的特征,成为特征点.计算机视觉领域中的很重要的图像特征匹配就是一特征点为基础而进行的,所以,如何定义和找出一幅图像中的特征点就非常重要. ...
随机推荐
- Linux守护进程简单介绍和实例具体解释
Linux守护进程简单介绍和实例具体解释 简单介绍 守护进程(Daemon)是执行在后台的一种特殊进程.它独立于控制终端而且周期性地执行某种任务或等待处理某些发生的事件.守护进程是一种非常实用的进程. ...
- 关于IIS上Yii2的Url路由美化
Yii2默认的路由是酱紫的 http://.../admin/web/index.php?r=site/login 心中理想的美化Url应该这样 http://.../admin/web/site/ ...
- 百度地图API简介
百度地图API简介 在此申明不是我写的,用的是别人的,仅限自己学习 百度地图移动版API(Android)是一套基于Android设备的应用程序接口,通过该接口,可以轻松的访问百度服务和数据,构建功能 ...
- lua面向对象铺垫
Account = { balance = , withdraw = function(self, v) self.balance = self.balance - v end } --:操作符隐藏了 ...
- Pollard-Rho大整数拆分模板
随机拆分,简直机智. 关于过程可以看http://wenku.baidu.com/link?url=JPlP8watmyGVDdjgiLpcytC0lazh4Leg3s53WIx1_Pp_Y6DJTC ...
- 关于logback
1 logback是一个日志框架 2 logback的构成 LogBack被分为3个组件,logback-core, logback-classic 和 logback-access. 其中logba ...
- iOS Load方法 和 initialize方法的比较
一.load方法特点: 1. 当类被引用进程序的时候会执行这个函数 2.一个类的load方法不用写明[super load],父类就会收到调用,并且在子类之前. 3.Category的load也会收到 ...
- L2 范数 L1 范数 出租车范数
https://en.wikipedia.org/wiki/Norm_(mathematics) http://cs231n.github.io/classification/
- JavaScript点击事件-一个按钮触发另一个按钮
<input type="button" value="Click" id="C" onclick="Go();" ...
- Javaweb--- EL表达式 JSTL标准标签库
一.EL表达式(expression language): 语法 ${...} jsp中page指令有一个属性叫isELIgnored, 用来标记此页面是否忽略EL表达式, 默认为false 举个例 ...