本代码已经弃用--
可直接使用OPENCV或animegan2 onnx AI模型进行人脸漫画化
opencv:
public static async Task<Mat> smooth(Mat sourceMat, double lambda = 2e-2, double kappa = 2.0) { Mat output = new Mat();//sourceMat.Width,sourceMat.Height,MatType.CV_8UC4 sourceMat = sourceMat.CvtColor(ColorConversionCodes.BGRA2BGR, 3); await Task.Run(() => { OpenCvSharp.XImgProc.CvXImgProc.L0Smooth(sourceMat, output, lambda, kappa); }); return output; }↑↑↑↑↑↑↑↑需要使用OpenCVSharp nuget插件
附加代码:
public async Task<BitmapImage> Mat2Bitmap(Mat mat) { var bi = new BitmapImage(); await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async ()=>{ byte[] bytes = mat.ToBytes(); using (var ms = new InMemoryRandomAccessStream()) { await ms.WriteAsync(bytes.AsBuffer()); ms.Seek(0); await bi.SetSourceAsync(ms); } }); return bi; } public async void ShowImage(Windows.UI.Xaml.Controls.Image image, Mat mat) { image.Source = await Mat2Bitmap(mat); }
本文参考:
https://blog.csdn.net/bluecol/article/details/48750561
http://www.cse.cuhk.edu.hk/~leojia/projects/L0smoothing/
主要是是香港中文大学所做的工作,我将Matlab代码转换为C#,制作成为插件。
其中matlab很多函数都通过Mathnet实现,参考:
https://www.songshizhao.com/blog/blogPage/1383.html
我已经在我自己的图片app中使用。win10电脑可下载体验。地址
Here are some effects:
“这么好的库实在是各位UWP程序猿行走江湖,奋力码砖之必备良库”。
“那么……在哪里才能搞得到呢?”。
“啊!这位仁兄运气真好,小弟正好放到github上开源,仁兄只要访问https://github.com/songshizhao/Analysis-Image-Pixel就可以了,另外别忘了Star/Fork哦”