生活随笔
收集整理的這篇文章主要介紹了
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);}
原圖?
效果圖
轉載于:https://www.cnblogs.com/muyuge/p/6152351.html
總結
以上是生活随笔為你收集整理的OpenCV——素描的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。