zoukankan      html  css  js  c++  java
  • OpenCV——素描


    具体的算法原理可以参考:

    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
     "Sketch" 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);
    
        Mat I(Image_in.size(), CV_32FC1);
    
        cv::cvtColor(Image_out, I, CV_BGR2GRAY);
        I=I/255.0;
        // Show_Image(I, "gray");
    
        Mat I_invert;
        I_invert=-I+1.0;
        // Show_Image(I_invert, "Inv");
    
        Mat I_gau;
        GaussianBlur(I_invert, I_gau, Size(25,25), 0, 0);
        //Show_Image(I_gau, "gau1");
    
        float delta=0.01;
        I_gau=-I_gau+1.0+delta;
        //Show_Image(I_gau, "gau");
    
        Mat I_dst;
        cv::divide(I, I_gau, I_dst);
        I_dst=I_dst;
        Show_Image(I_dst, "dst");
    
        Mat b(Image_in.size(), CV_32FC1);
        Mat g(Image_in.size(), CV_32FC1);
        Mat r(Image_in.size(), CV_32FC1);
    
        Mat rgb[]={b,g,r};
    
        float alpha=0.75;
    
        r=alpha*I_dst+(1-alpha)*200.0/255.0;
        g=alpha*I_dst+(1-alpha)*205.0/255.0;
        b=alpha*I_dst+(1-alpha)*105.0/255.0;
    
        cv::merge(rgb, 3, Image_out);
    
        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);
    
    }
    




    原图 


    效果图


  • 相关阅读:
    Exploits Likely Leveraged by Russia’s APT28 in Highly-Targeted Attack
    WAF绕过的一些总结和思考
    PHP SAFE MODE BYPASS
    RAS算法原理
    如何绕过WAF
    360手机助手关于签名校验的分析
    cat 命令详解
    面向对象简介
    APK签名及简单反编译
    面向对象之基本概念 封装、单多继承
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152351.html
Copyright © 2011-2022 走看看