具体的算法可以参考:

PS 滤镜 马赛克

// 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" using namespace std;
using namespace cv; void Show_Image(Mat&, const string &); #endif // PS_ALGORITHM_H_INCLUDED /*
This program will generate
"Mosaic" effect. */ #include "PS_Algorithm.h"
#include <time.h> using namespace std;
using namespace cv; int main(void)
{
string Img_name("4.jpg");
Mat Image_in;
Image_in=imread(Img_name);
// Show_Image(Image_in, Img_name); Mat Image_out(Image_in.size(), CV_32FC3);
Image_in.convertTo(Image_out, CV_32FC3); int P_size=9;
float k1, k2; int n_row;
int n_col; float m, n; int h,w; n_row=Image_in.rows;
n_col=Image_in.cols; Mat sub_mat; srand( (unsigned)time(NULL) ); for (int i=P_size; i<Image_in.rows-P_size-1; i=i+P_size)
{
for (int j=P_size; j<Image_in.cols-1-P_size; j=j+P_size)
{
k1=(double)((rand() % 100))/100.0-0.5;
k2=(double)((rand() % 100))/100.0-0.5; m=(k1*(P_size*2-1));
n=(k2*(P_size*2-1)); h=(int)(i+m)% n_row;
w=(int)(j+n)% n_col; sub_mat=Image_out.operator()(Range(i-P_size,i+P_size), Range(j-P_size,j+P_size)); sub_mat.setTo(Scalar(Image_in.at<Vec3b>(h,w))); }
} Image_out=Image_out/255.0; Show_Image(Image_out, "out"); imwrite("out.jpg", Image_out*255); waitKey();
cout<<"All is well."<<endl; } // 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); }

原图

效果图

最新文章

  1. jira操作
  2. sklearn学习笔记1
  3. webpack入门指南(转载)
  4. android 入门-基础了解
  5. 录制简单的自动化测试工具SlikMobile初体验
  6. 使用代码创建AutoLayout约束
  7. 30道四则运算&lt;2&gt;
  8. secureCRT中文字符乱码
  9. Entity Framework关联实体的三种加载方法
  10. Lightbox 图片展示插件
  11. JAVA设计模式总结之六大设计原则
  12. JAVA第十次作业
  13. SQL Server进阶(十一)存储过程
  14. linux 权限管理
  15. ThreadPoolExecutor 入参 corePoolSize 和 maximumPoolSize 的联系
  16. Python—装饰器详解
  17. L236
  18. 好的API设计
  19. Spring管理过滤器:org.springframework.web.filter.DelegatingFilterProxy
  20. hdu 2121 Ice_cream’s world II

热门文章

  1. J-Robot,能走、能跳舞的机器人
  2. FORM执行查询的各种方法
  3. 侧滑面板(对viewGroup的自定义)
  4. (一二三)基于GCD的dispatch_once实现单例设计
  5. C++对象模型的那些事儿之四:拷贝构造函数
  6. 精通CSS+DIV网页样式与布局--CSS文字效果
  7. java方法重写和super关键字
  8. [Linux]vbox 虚拟机添加新磁盘
  9. 摆脱命令行,Ubuntu下配置Android开发环境
  10. 【一天一道LeetCode】#97. Interleaving String