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