您好,登錄后才能下訂單哦!
這篇文章主要為大家詳細介紹了使用OpenCV怎么將彩色照片轉換成素描卡通照片,文中示例代碼介紹的非常詳細,具有一定的參考價值,發現的小伙伴們可以參考一下:
具體內容如下
#include"stdafx.h" //#include<cv.h> //#include<highgui.h> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/core/core.hpp> using namespace cv; using namespace std; int main() { Mat src,smallImg,tmp,bigImg,gray,edges,masks,dst; const int MEDIAN_BLUR_FILTER_SIZE = 7; const int LAPLACIAN_FILTER_SIZE = 5; const int EDGES_THRESHOLD = 80; int repetitions = 7; // Repetitions for strong cartoon effect. src = imread("pic.jpg"); Size size = src.size(); Size smallSize; smallSize.width = size.width/2; smallSize.height = size.height/2; smallImg = Mat(smallSize, CV_8UC3); tmp = Mat(smallSize, CV_8UC3); dst= Mat(size,CV_8UC3); cvtColor(src,gray,CV_BGR2GRAY); medianBlur(gray,gray,MEDIAN_BLUR_FILTER_SIZE); Laplacian(gray, edges, CV_8U,LAPLACIAN_FILTER_SIZE); threshold(edges, masks,EDGES_THRESHOLD,255, THRESH_BINARY_INV); imshow("sketch:)", masks); waitKey(10); resize(src, smallImg, smallSize, 0,0, INTER_LINEAR); for (int i=0; i<repetitions; i++) { int ksize = 9; // Filter size. Has a large effect on speed. double sigmaColor = 9; // Filter color strength. double sigmaSpace = 7; // Spatial strength. Affects speed. bilateralFilter(smallImg, tmp, ksize, sigmaColor, sigmaSpace); bilateralFilter(tmp, smallImg, ksize, sigmaColor, sigmaSpace); } resize(smallImg, bigImg, size, 0,0, INTER_LINEAR); bigImg.copyTo(dst,masks); imshow("cartoon :)", dst); waitKey(0); return 0; }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。