From 81486450f1437619a3ec5569db251d8cb26862fa Mon Sep 17 00:00:00 2001 From: 9hy Date: Wed, 15 May 2019 16:08:49 +0200 Subject: [PATCH] v2.2 --- Blur/Blur.csproj | 40 +-- Blur/Form2.cs | 66 +++- {XBF => Blur}/License-LGPL.txt | 0 Blur/packages.config | 5 + XBF/Analyzer.cs | 290 ++++++++++-------- {Blur => XBF}/Assets/deploy.prototxt | 0 .../haarcascade_frontalface_default.xml | 0 {Blur => XBF}/Assets/lbfmodel.yaml | 0 .../res10_300x300_ssd_iter_140000.caffemodel | Bin XBF/Properties/Resources.Designer.cs | 63 ++++ XBF/Properties/Resources.resx | 101 ++++++ XBF/Properties/Settings.Designer.cs | 26 ++ XBF/Properties/Settings.settings | 6 + XBF/XBF.csproj | 37 +-- XBF/app.config | 11 + XBF/blur.cs | 4 +- XBF/packages.config | 5 - 17 files changed, 468 insertions(+), 186 deletions(-) rename {XBF => Blur}/License-LGPL.txt (100%) create mode 100644 Blur/packages.config rename {Blur => XBF}/Assets/deploy.prototxt (100%) rename {Blur => XBF}/Assets/haarcascade_frontalface_default.xml (100%) rename {Blur => XBF}/Assets/lbfmodel.yaml (100%) rename {Blur => XBF}/Assets/res10_300x300_ssd_iter_140000.caffemodel (100%) create mode 100644 XBF/Properties/Resources.Designer.cs create mode 100644 XBF/Properties/Resources.resx create mode 100644 XBF/Properties/Settings.Designer.cs create mode 100644 XBF/Properties/Settings.settings create mode 100644 XBF/app.config delete mode 100644 XBF/packages.config diff --git a/Blur/Blur.csproj b/Blur/Blur.csproj index 7b361c9..d10d76f 100644 --- a/Blur/Blur.csproj +++ b/Blur/Blur.csproj @@ -37,6 +37,12 @@ true + + ..\packages\EMGU.CV.4.0.1.3373\lib\net35\Emgu.CV.UI.dll + + + ..\packages\EMGU.CV.4.0.1.3373\lib\net35\Emgu.CV.World.dll + @@ -48,6 +54,13 @@ + + False + ..\XBF\bin\Debug\XBF.dll + + + ..\packages\ZedGraph.5.1.7\lib\net35-Client\ZedGraph.dll + @@ -70,12 +83,7 @@ True Resources.resx - - Always - - - Always - + SettingsSingleFileGenerator Settings.Designer.cs @@ -85,23 +93,19 @@ Settings.settings True - - Always - - - Always - - - - - {530d1738-ec76-4575-83ae-af6d84537718} - XBF - + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/Blur/Form2.cs b/Blur/Form2.cs index c14f3af..d770945 100644 --- a/Blur/Form2.cs +++ b/Blur/Form2.cs @@ -13,7 +13,10 @@ using XBF; - +using Emgu.CV.Face; +using Emgu.CV; +using Emgu.CV.Structure; +using Emgu.CV.Util; namespace Blur { @@ -79,7 +82,7 @@ private void button1_Click(object sender, EventArgs e) // frame = (Bitmap)blurer.ClipToCircle(frame2.Bitmap, frame, new Point(face.X + face.Width / 2, face.Y + face.Height / 2), face.Width / 2, face); //} - Analyzer analyzer = new Analyzer(true, Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\res10_300x300_ssd_iter_140000.caffemodel", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\deploy.prototxt", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\lbfmodel.yaml"); + Analyzer analyzer = new Analyzer(true); //frame = analyzer.BlurFaceOval(imageFrame.Mat).ToImage().Bitmap; pictureBox1.Image = frame; } @@ -99,10 +102,26 @@ private void button2_Click(object sender, EventArgs e) Bitmap frame = (Bitmap)Image.FromFile(path); - Analyzer analyzer = new Analyzer(false, Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\res10_300x300_ssd_iter_140000.caffemodel", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\deploy.prototxt", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\lbfmodel.yaml"); + Analyzer analyzer = new Analyzer(false); + + List Faces = ((IAnalyzer)analyzer).getFaceRegions(Analyzer.ImageToByte(frame), analyzer.ssdProtoFile, analyzer.ssdFile); + PointF[][][] Landmarks_ = ((IAnalyzer)analyzer).getLandmarks(Analyzer.ImageToByte(frame), Faces, analyzer.facemarkFileName); + + //List landmarks = new List(Landmarks_.Length); + //foreach (PointF[][] lm in Landmarks_) + //{ + // landmarks.Add(new VectorOfVectorOfPointF(lm)); + //} + Image img = new Image(frame); + //for (int i = 0; i < landmarks[0].Size; i++) + //{ + // using (VectorOfPointF vpf = landmarks[0][i]) + // FaceInvoke.DrawFacemarks(img, vpf, new MCvScalar(255, 128, 0)); + //} - - pictureBox1.Image = analyzer.BlurFaceWithLandmark(frame, 20); + + + pictureBox1.Image = img.Bitmap; } } @@ -115,18 +134,33 @@ private void button3_Click(object sender, EventArgs e) Bitmap imageFrame = Image.FromFile(path) as Bitmap; - Analyzer analyzer = new Analyzer(false, Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\res10_300x300_ssd_iter_140000.caffemodel", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\deploy.prototxt", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\lbfmodel.yaml"); + + Analyzer analyzer = new Analyzer(false); - List Faces = analyzer.getFaceRegions(imageFrame, Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\deploy.prototxt", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\res10_300x300_ssd_iter_140000.caffemodel"); - PointF[][][] Landmarks = analyzer.getLandmarks(imageFrame, Faces, Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\lbfmodel.yaml"); + List Faces = ((IAnalyzer)analyzer).getFaceRegions(Analyzer.ImageToByte(imageFrame), analyzer.ssdProtoFile, analyzer.ssdFile); + PointF[][][] Landmarks = ((IAnalyzer)analyzer).getLandmarks(Analyzer.ImageToByte(imageFrame), Faces, analyzer.facemarkFileName); + + Bitmap Mask = ((IAnalyzer)analyzer).getOpMask(Analyzer.ImageToByte(imageFrame), Faces, Landmarks); + Bitmap Final = ((IAnalyzer)analyzer).BlurFaceWithLandmark(Analyzer.ImageToByte(imageFrame), 12, Faces, Landmarks, Mask); - Bitmap Mask = analyzer.getOpMask(imageFrame, Faces, Landmarks); - Bitmap Final = analyzer.BlurFaceWithLandmark(imageFrame, 12, Faces, Landmarks, Mask); + //List landmarks = new List(Landmarks.Length); + //foreach (PointF[][] lm in Landmarks) + //{ + // landmarks.Add(new VectorOfVectorOfPointF(lm)); + //} + Image img = new Image(Final); + //for(int j = 0; j < Faces.Count; j++) + //{ + // for (int i = 0; i < landmarks[j].Size; i++) + // { + // using (VectorOfPointF vpf = landmarks[j][i]) + // FaceInvoke.DrawFacemarks(img, vpf, new MCvScalar(255, 128, 0)); + // } + //} - - pictureBox1.Image = Final; + pictureBox1.Image = img.Bitmap; } } @@ -138,12 +172,12 @@ private void button4_Click(object sender, EventArgs e) string path = openFileDialog1.FileName; Bitmap imageFrame = Image.FromFile(path) as Bitmap; - Analyzer analyzer = new Analyzer(false, Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\res10_300x300_ssd_iter_140000.caffemodel", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\deploy.prototxt", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\lbfmodel.yaml"); + Analyzer analyzer = new Analyzer(false); - List Faces = analyzer.getFaceRegions(imageFrame, Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\deploy.prototxt", Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\res10_300x300_ssd_iter_140000.caffemodel"); - PointF[][][] Landmarks = analyzer.getLandmarks(imageFrame, Faces, Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\lbfmodel.yaml"); + List Faces = ((IAnalyzer)analyzer).getFaceRegions(Analyzer.ImageToByte(imageFrame), analyzer.ssdProtoFile, analyzer.ssdFile); + PointF[][][] Landmarks = ((IAnalyzer)analyzer).getLandmarks(Analyzer.ImageToByte(imageFrame), Faces, analyzer.facemarkFileName); - pictureBox1.Image = analyzer.getOpMask(imageFrame, Faces, Landmarks); + pictureBox1.Image = ((IAnalyzer)analyzer).getOpMask(Analyzer.ImageToByte(imageFrame), Faces, Landmarks); } } } diff --git a/XBF/License-LGPL.txt b/Blur/License-LGPL.txt similarity index 100% rename from XBF/License-LGPL.txt rename to Blur/License-LGPL.txt diff --git a/Blur/packages.config b/Blur/packages.config new file mode 100644 index 0000000..768ca69 --- /dev/null +++ b/Blur/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/XBF/Analyzer.cs b/XBF/Analyzer.cs index c1ac90a..720ec49 100644 --- a/XBF/Analyzer.cs +++ b/XBF/Analyzer.cs @@ -7,29 +7,15 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; +using System.IO; +using System.Linq; using System.Reflection; using System.Runtime.InteropServices; namespace XBF { - public class Analyzer + public interface IAnalyzer { - private bool DEBUG = false; - private blur blurer; - private String ssdFile; - private String ssdProtoFile; - private String facemarkFileName; - - public Analyzer(bool Debug = false, String ssdFile = null, String ssdProtoFile = null, String facemarkFileName = null) - { - - this.DEBUG = Debug; - this.ssdFile = ssdFile; - this.ssdProtoFile = ssdProtoFile; - this.facemarkFileName = facemarkFileName; - blurer = new blur(); - } - /// /// Get a list of rectangles of the faces. /// @@ -39,12 +25,109 @@ public Analyzer(bool Debug = false, String ssdFile = null, String ssdProtoFile = /// ssd File /// Dim /// Returns a list of rectangles - public List getFaceRegions(Bitmap img, String ssdProtoFile, String ssdFile, int imgDim = 300) + List getFaceRegions(byte[] img, byte[] ssdProtoFile, byte[] ssdFile); + + /// + /// Get a list of the landmarks of the faces. + /// + /// + /// Source image + /// List of tectangles of the faces. See + /// Facemark File + /// Return a list of arrays of points of each face. + PointF[][][] getLandmarks(byte[] image, List faceRegions, String facemarkFileName); + + /// + /// Get Blur Opacity mask + /// + /// Base Image + /// Faces Matrix + /// + /// + /// + /// + /// + Bitmap getOpMask(byte[] image, List faces, PointF[][][] landmarks_); + + /// + /// Blur faces inside the landmarks + /// + /// Source image + /// Returns the image with the faces blurred inside the landmarks of each face + Bitmap BlurFaceWithLandmark(byte[] image, int BlurSize, List faces, PointF[][][] landmarks_, Bitmap Mask); + + /// + /// Blur faces inside an oval of the rectangle + /// + /// Source image + /// If Faces are given then it not recalculates them + /// Returns the image with the faces blurred inside the rectangle cropped to an oval + Bitmap BlurFaceOval(byte[] image, List faces); + + } + public class Analyzer : IAnalyzer + { + private bool DEBUG = false; + private blur blurer; + public byte[] ssdFile; + public byte[] ssdProtoFile; + public String facemarkFileName; + + public Analyzer(bool Debug = false) { - Mat Mimg = new Image(img).Mat; + + var assembly = Assembly.GetExecutingAssembly(); + var resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("res10_300x300_ssd_iter_140000.caffemodel")); + + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + using (BinaryReader br = new BinaryReader(stream)) + { + ssdFile = br.ReadBytes((int)stream.Length); + } + + resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("deploy.prototxt")); + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + using (BinaryReader br = new BinaryReader(stream)) + { + ssdProtoFile = br.ReadBytes((int)stream.Length); + } + + + + this.DEBUG = Debug; + try + { + this.facemarkFileName = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets\lbfmodel.yaml"; + System.IO.Directory.CreateDirectory(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location) + @"\Assets"); + resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("lbfmodel.yaml")); + using (Stream stream = assembly.GetManifestResourceStream(resourceName)) + using (var fileStream = new FileStream(this.facemarkFileName, FileMode.OpenOrCreate, FileAccess.Write)) + { + stream.CopyTo(fileStream); + } + } + catch(Exception ex) + { + Console.WriteLine(ex.ToString()); + } + + + blurer = new blur(); + } + + public static byte[] ImageToByte(Image img) + { + return (byte[])(new ImageConverter()).ConvertTo(img, typeof(byte[])); + } + + List IAnalyzer.getFaceRegions(byte[] img, byte[] ssdProtoFile, byte[] ssdFile) + { + //Assembly.GetExecutingAssembly().GetManifestResourceInfo("").ResourceLocation.ToString(); + Bitmap image = (Bitmap)((new ImageConverter()).ConvertFrom(img)); + Mat Mimg = new Image(image).Mat; Emgu.CV.Dnn.Net net = DnnInvoke.ReadNetFromCaffe(ssdProtoFile, ssdFile); MCvScalar meanVal = new MCvScalar(104, 177, 123); - Mat inputBlob = DnnInvoke.BlobFromImage(Mimg, 1.0, new Size(imgDim, imgDim), meanVal, false, false); + Mat inputBlob = DnnInvoke.BlobFromImage(Mimg, 1.0, new Size(300, 300), meanVal, true, false); net.SetInput(inputBlob, "data"); Mat detection = net.Forward("detection_out"); @@ -52,7 +135,7 @@ public List getFaceRegions(Bitmap img, String ssdProtoFile, String ss List faceRegions = new List(); - int[] dim = detection.SizeOfDimemsion; + int[] dim = detection.SizeOfDimension; int step = dim[3] * sizeof(float); IntPtr start = detection.DataPointer; for (int i = 0; i < dim[2]; i++) @@ -75,17 +158,11 @@ public List getFaceRegions(Bitmap img, String ssdProtoFile, String ss } return faceRegions; } - - /// - /// Get a list of the landmarks of the faces. - /// - /// - /// Source image - /// List of tectangles of the faces. See - /// Facemark File - /// Return a list of arrays of points of each face. - public PointF[][][] getLandmarks(Bitmap img, List faceRegions, String facemarkFileName) + + PointF[][][] IAnalyzer.getLandmarks(byte[] image, List faceRegions, String facemarkFileName) { + Bitmap img = (Bitmap)((new ImageConverter()).ConvertFrom(image)); + Mat Mimg = new Image(img).Mat; List landmarks = new List(faceRegions.Count); for (int i = 0; i <= faceRegions.Count - 1; i++) @@ -117,71 +194,67 @@ public PointF[][][] getLandmarks(Bitmap img, List faceRegions, String return List2.ToArray(); } - /// - /// Blur faces inside an oval of the rectangle - /// - /// Source image - /// If Faces are given then it not recalculates them - /// Returns the image with the faces blurred inside the rectangle cropped to an oval - public Bitmap BlurFaceOval(Bitmap img, List faces = null, String ssdFile_ = null, String ssdProtoFile_ = null) + Bitmap IAnalyzer.getOpMask(byte[] image, List faces, PointF[][][] landmarks_) { - int imgDim = 300; + Bitmap img = (Bitmap)((new ImageConverter()).ConvertFrom(image)); MCvScalar meanVal = new MCvScalar(104, 177, 123); - String ssdFile = (ssdFile_ == null ? this.ssdFile : ssdFile_); - String ssdProtoFile = (ssdProtoFile_ == null ? this.ssdProtoFile : ssdProtoFile_); - List faceRegions = ((faces==null)?getFaceRegions(img, ssdProtoFile, ssdFile, imgDim):faces); - - int numFaces = faceRegions.Count; - for (int j = 0; j <= faceRegions.Count - 1; j++) + + List landmarks = new List(landmarks_.Length); + foreach (PointF[][] lm in landmarks_) { - if(DEBUG) - CvInvoke.Rectangle(new Image(img), faceRegions[j], new MCvScalar(0, 255, 0)); - Mat img2 = new Image(img).Mat; - //Blur Oval - img = new Image((Bitmap)blurer.BlurRectangle(img, faceRegions[j])).Bitmap; - - + landmarks.Add(new VectorOfVectorOfPointF(lm)); } - return img; - - } + Bitmap dstImage = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppArgb); + for (int j = 0; j <= faces.Count - 1; j++) + { + if (DEBUG) + CvInvoke.Rectangle(new Image(img), faces[j], new MCvScalar(0, 255, 0)); + if (DEBUG) + for (int i = 0; i < landmarks[j].Size; i++) + { + using (VectorOfPointF vpf = landmarks[j][i]) + try + { + FaceInvoke.DrawFacemarks(new Image(img), vpf, new MCvScalar(255, 0, 0)); + } + catch (Emgu.CV.Util.CvException ex) + { + Console.WriteLine(ex.ToString()); + } + } + PointF[] Facepoints = landmarks[j].ToArrayOfArray()[0]; + //if (DEBUG) + // CvInvoke.DrawContours(new Image(img), new VectorOfPointF(Facepoints), 2, new MCvScalar(255, 0, 0)); + dstImage = blurer.OpMask(dstImage, Facepoints, faces[j]); + } + return dstImage; - /// - /// Blur faces inside the landmarks - /// - /// Source image - /// Returns the image with the faces blurred inside the landmarks of each face - public Bitmap BlurFaceWithLandmark(Bitmap img, int BlurSize, List faces = null, PointF[][][] landmarks_ = null, Bitmap Mask = null, String ssdFile_ = null, String ssdProtoFile_ = null, String facemarkFileName_ = null) + } + + Bitmap IAnalyzer.BlurFaceWithLandmark(byte[] image, int BlurSize, List faces, PointF[][][] landmarks_, Bitmap Mask) { - - int imgDim = 300; + Bitmap img = (Bitmap)((new ImageConverter()).ConvertFrom(image)); MCvScalar meanVal = new MCvScalar(104, 177, 123); - String ssdFile = (ssdFile_ == null ? this.ssdFile : ssdFile_); - String ssdProtoFile = (ssdProtoFile_ == null ? this.ssdProtoFile : ssdProtoFile_); - String facemarkFileName = (facemarkFileName_ == null ? this.facemarkFileName : facemarkFileName_); - - List faceRegions = ((faces == null) ? getFaceRegions(img, ssdProtoFile, ssdFile, imgDim) : faces); - PointF[][][] landmarks__ = ((landmarks_ == null) ? getLandmarks(img, faceRegions, facemarkFileName) : landmarks_); - + List landmarks = new List(landmarks_.Length); - foreach (PointF[][] lm in landmarks__) + foreach (PointF[][] lm in landmarks_) { landmarks.Add(new VectorOfVectorOfPointF(lm)); } - for (int j = 0; j <= faceRegions.Count - 1; j++) + for (int j = 0; j <= faces.Count - 1; j++) { if(DEBUG) - CvInvoke.Rectangle(new Image(img), faceRegions[j], new MCvScalar(0, 255, 0)); + CvInvoke.Rectangle(new Image(img), faces[j], new MCvScalar(0, 255, 0)); if(DEBUG) - for (int i = 0; i < landmarks[i].Size; i++) + for (int i = 0; i < landmarks[j].Size; i++) { using (VectorOfPointF vpf = landmarks[j][i]) try { - FaceInvoke.DrawFacemarks(new Image(img), vpf, new MCvScalar(255, 0, 0)); + FaceInvoke.DrawFacemarks(new Image(img), vpf, new MCvScalar(255, 128, 0)); } catch (Emgu.CV.Util.CvException ex) { @@ -199,66 +272,33 @@ public Bitmap BlurFaceWithLandmark(Bitmap img, int BlurSize, List fac Console.WriteLine(ex.ToString()); } // Blur Path - img = new Image((Bitmap)blurer.BlurPath(img, BlurSize, Facepoints, faceRegions[j], Mask)).Bitmap; + img = new Image((Bitmap)blurer.BlurPath(img, BlurSize, Facepoints, faces[j], Mask)).Bitmap; } return img; } - /// - /// Get Blur Opacity mask - /// - /// Base Image - /// Faces Matrix - /// - /// - /// - /// - /// - - public Bitmap getOpMask(Bitmap img, List faces = null, PointF[][][] landmarks_ = null, String ssdFile_ = null, String ssdProtoFile_ = null, String facemarkFileName_ = null) + Bitmap IAnalyzer.BlurFaceOval(byte[] image, List faces) { - int imgDim = 300; + Bitmap img = (Bitmap)((new ImageConverter()).ConvertFrom(image)); + MCvScalar meanVal = new MCvScalar(104, 177, 123); - String ssdFile = (ssdFile_ == null ? this.ssdFile : ssdFile_); - String ssdProtoFile = (ssdProtoFile_ == null ? this.ssdProtoFile : ssdProtoFile_); - String facemarkFileName = (facemarkFileName_ == null ? this.facemarkFileName : facemarkFileName_); - - List faceRegions = ((faces == null) ? getFaceRegions(img, ssdProtoFile, ssdFile, imgDim) : faces); - PointF[][][] landmarks__ = ((landmarks_ == null) ? getLandmarks(img, faceRegions, facemarkFileName) : landmarks_); - - List landmarks = new List(landmarks_.Length); - foreach (PointF[][] lm in landmarks__) - { - landmarks.Add(new VectorOfVectorOfPointF(lm)); - } - - Bitmap dstImage = new Bitmap(img.Width, img.Height, PixelFormat.Format32bppArgb); - for (int j = 0; j <= faceRegions.Count - 1; j++) + + + int numFaces = faces.Count; + for (int j = 0; j <= faces.Count - 1; j++) { - if (DEBUG) - CvInvoke.Rectangle(new Image(img), faceRegions[j], new MCvScalar(0, 255, 0)); - if (DEBUG) - for (int i = 0; i < landmarks[i].Size; i++) - { - using (VectorOfPointF vpf = landmarks[j][i]) - try - { - FaceInvoke.DrawFacemarks(new Image(img), vpf, new MCvScalar(255, 0, 0)); - } - catch (Emgu.CV.Util.CvException ex) - { - Console.WriteLine(ex.ToString()); - } - } - PointF[] Facepoints = landmarks[j].ToArrayOfArray()[0]; - if (DEBUG) - CvInvoke.DrawContours(new Image(img), new VectorOfPointF(Facepoints), 2, new MCvScalar(255, 0, 0)); - dstImage = blurer.OpMask(dstImage, Facepoints, faceRegions[j]); + if(DEBUG) + CvInvoke.Rectangle(new Image(img), faces[j], new MCvScalar(0, 255, 0)); + Mat img2 = new Image(img).Mat; + //Blur Oval + img = new Image((Bitmap)blurer.BlurRectangle(img, faces[j])).Bitmap; + + } - return dstImage; + return img; } - + } } diff --git a/Blur/Assets/deploy.prototxt b/XBF/Assets/deploy.prototxt similarity index 100% rename from Blur/Assets/deploy.prototxt rename to XBF/Assets/deploy.prototxt diff --git a/Blur/Assets/haarcascade_frontalface_default.xml b/XBF/Assets/haarcascade_frontalface_default.xml similarity index 100% rename from Blur/Assets/haarcascade_frontalface_default.xml rename to XBF/Assets/haarcascade_frontalface_default.xml diff --git a/Blur/Assets/lbfmodel.yaml b/XBF/Assets/lbfmodel.yaml similarity index 100% rename from Blur/Assets/lbfmodel.yaml rename to XBF/Assets/lbfmodel.yaml diff --git a/Blur/Assets/res10_300x300_ssd_iter_140000.caffemodel b/XBF/Assets/res10_300x300_ssd_iter_140000.caffemodel similarity index 100% rename from Blur/Assets/res10_300x300_ssd_iter_140000.caffemodel rename to XBF/Assets/res10_300x300_ssd_iter_140000.caffemodel diff --git a/XBF/Properties/Resources.Designer.cs b/XBF/Properties/Resources.Designer.cs new file mode 100644 index 0000000..2a789eb --- /dev/null +++ b/XBF/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace XBF.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XBF.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/XBF/Properties/Resources.resx b/XBF/Properties/Resources.resx new file mode 100644 index 0000000..4fdb1b6 --- /dev/null +++ b/XBF/Properties/Resources.resx @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 1.3 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/XBF/Properties/Settings.Designer.cs b/XBF/Properties/Settings.Designer.cs new file mode 100644 index 0000000..7e3adec --- /dev/null +++ b/XBF/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace XBF.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/XBF/Properties/Settings.settings b/XBF/Properties/Settings.settings new file mode 100644 index 0000000..049245f --- /dev/null +++ b/XBF/Properties/Settings.settings @@ -0,0 +1,6 @@ + + + + + + diff --git a/XBF/XBF.csproj b/XBF/XBF.csproj index b617222..7b27a5e 100644 --- a/XBF/XBF.csproj +++ b/XBF/XBF.csproj @@ -38,12 +38,6 @@ icon.ico - - ..\packages\EMGU.CV.3.4.3.3016\lib\net35\Emgu.CV.UI.dll - - - ..\packages\EMGU.CV.3.4.3.3016\lib\net35\Emgu.CV.World.dll - @@ -53,10 +47,6 @@ - - ..\packages\ZedGraph.5.1.7\lib\net35-Client\ZedGraph.dll - True - @@ -64,25 +54,30 @@ + + True + True + Resources.resx + + - - - + + Designer + + + + - + + ResXFileCodeGenerator + Resources.Designer.cs + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - \ No newline at end of file diff --git a/XBF/app.config b/XBF/app.config new file mode 100644 index 0000000..4e74e78 --- /dev/null +++ b/XBF/app.config @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/XBF/blur.cs b/XBF/blur.cs index 698f17a..40ae7b4 100644 --- a/XBF/blur.cs +++ b/XBF/blur.cs @@ -13,6 +13,8 @@ namespace XBF { class blur { + + public Image ClipToCircle(Image srcImage, Image blurImage, PointF center, float radius, Rectangle box) { Image dstImage = new Bitmap(srcImage.Width, srcImage.Height, srcImage.PixelFormat); @@ -60,7 +62,7 @@ public Image BlurPath(Image srcImage, int blursize, PointF[] path, Rectangle fac using (Graphics g = Graphics.FromImage(dstImage)) { g.SmoothingMode = SmoothingMode.AntiAlias; - g.DrawImage(srcImage, 0, 0); + g.DrawImage(srcImage, 0, 0, srcImage.Width, srcImage.Height); if (Mask == null) { GraphicsPath gPath = new GraphicsPath(); diff --git a/XBF/packages.config b/XBF/packages.config deleted file mode 100644 index afc79c2..0000000 --- a/XBF/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file