opencv--Sketch

Source: Internet
Author: User


The specific algorithm principle can refer to:

PS Filter, sketch algorithm


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 would ge Nerate "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::d ivide (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 are 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);}




Original



opencv--Sketch

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.