Skip to content

Commit

Permalink
Library Update
Browse files Browse the repository at this point in the history
  • Loading branch information
9hy committed Mar 9, 2019
1 parent cc5a9e9 commit 2f9982d
Show file tree
Hide file tree
Showing 11 changed files with 983 additions and 300 deletions.
14 changes: 14 additions & 0 deletions Blur OpenCv.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.438
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blur", "Blur\Blur.csproj", "{2D54F7BD-B9DF-420D-8B2F-15443C95099D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XBF", "XBF\XBF.csproj", "{530D1738-EC76-4575-83AE-AF6D84537718}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,18 @@ Global
{2D54F7BD-B9DF-420D-8B2F-15443C95099D}.Release|x64.Build.0 = Release|Any CPU
{2D54F7BD-B9DF-420D-8B2F-15443C95099D}.Release|x86.ActiveCfg = Release|Any CPU
{2D54F7BD-B9DF-420D-8B2F-15443C95099D}.Release|x86.Build.0 = Release|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Debug|Any CPU.Build.0 = Debug|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Debug|x64.ActiveCfg = Debug|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Debug|x64.Build.0 = Debug|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Debug|x86.ActiveCfg = Debug|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Debug|x86.Build.0 = Debug|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Release|Any CPU.ActiveCfg = Release|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Release|Any CPU.Build.0 = Release|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Release|x64.ActiveCfg = Release|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Release|x64.Build.0 = Release|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Release|x86.ActiveCfg = Release|Any CPU
{530D1738-EC76-4575-83AE-AF6D84537718}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
143 changes: 0 additions & 143 deletions Blur OpenCv/Blur OpenCv.vcxproj

This file was deleted.

33 changes: 0 additions & 33 deletions Blur OpenCv/Blur OpenCv.vcxproj.filters

This file was deleted.

124 changes: 0 additions & 124 deletions Blur OpenCv/test.cpp

This file was deleted.

53 changes: 53 additions & 0 deletions XBF/Analyzer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using Emgu.CV.Dnn;
using Emgu.CV.Face;
using Emgu.CV.Structure;
using Emgu.CV.Util;
namespace XBF
{
public class Analyzer
{
public List<Rectangle> getFaceRegions(Mat img, String ssdProtoFile, String ssdFile, int imgDim = 300)
{
Emgu.CV.Dnn.Net net = DnnInvoke.ReadNetFromCaffe(ssdProtoFile, ssdFile);
MCvScalar meanVal = new MCvScalar(104, 177, 123);
Mat inputBlob = DnnInvoke.BlobFromImage(img, 1.0, new Size(imgDim, imgDim), meanVal, false, false);
net.SetInput(inputBlob, "data");
Mat detection = net.Forward("detection_out");

float confidenceThreshold = 0.5f;

List<Rectangle> faceRegions = new List<Rectangle>();

int[] dim = detection.SizeOfDimemsion;
int step = dim[3] * sizeof(float);
IntPtr start = detection.DataPointer;
for (int i = 0; i < dim[2]; i++)
{
float[] values = new float[dim[3]];
Marshal.Copy(new IntPtr(start.ToInt64() + step * i), values, 0, dim[3]);
float confident = values[2];

if (confident > confidenceThreshold)
{
float xLeftBottom = values[3] * img.Cols;
float yLeftBottom = values[4] * img.Rows;
float xRightTop = values[5] * img.Cols;
float yRightTop = values[6] * img.Rows;
RectangleF objectRegion = new RectangleF(xLeftBottom, yLeftBottom, xRightTop - xLeftBottom, yRightTop - yLeftBottom);
Rectangle faceRegion = Rectangle.Round(objectRegion);
faceRegions.Add(faceRegion);

}
}
return faceRegions;
}
}
}
Loading

0 comments on commit 2f9982d

Please sign in to comment.