OpenCV——旋转模糊 (二)
2015-08-25 15:54
357 查看
// 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); }
原图
效果图
相关文章推荐
- 【linux】ubuntu 下tomcat安装
- arm-linux-gcc的下载与安装配置
- DropDownListView下拉刷新和上拉加载和没有更多
- 在ubuntu上搭建tomcat
- openstack kilo 配置dvr
- Spark修炼之道(基础篇)——Linux大数据开发基础:第五节:vi、vim编辑器(一)
- 记录与linux的每次邂逅__小白关于mysql脚本安装事前事后的一点感想
- Hadoop入门简介
- linux服务器必要的两个系统设置
- Linux的文件系统
- 运维工单--服务器申请工单
- Opencv用鼠标绘制填充多边形
- openssl生成RSA格式,并转为pkcs8格式
- Opencv用鼠标绘制线段
- 我的openwrt学习笔记(十):开发小贴士_vmware虚拟机窗口大小设置
- OpenGL
- linux---动静态库编译及使用
- 各类数据库字符串连接网站
- Opencv用鼠标画圆
- 迅为4412开发板Linux驱动教程之GPIO的初始化