OpenCV——马赛克

具体的算法可以参考:

PS 滤镜 马赛克

// define head function
#ifndef PS_ALGORITHM_H_INCLUDED
#define PS_ALGORITHM_H_INCLUDED

#include 
#include 
#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 

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(h,w)));

        }
    }

    Image_out=Image_out/255.0;

    Show_Image(Image_out, "out");

    imwrite("out.jpg", Image_out*255);

    waitKey();
    cout<<"All is well."<
#include 

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);

}


原图 



效果图


转载于:https://www.cnblogs.com/muyuge/p/6152350.html

你可能感兴趣的:(OpenCV——马赛克)