You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.6 KiB
76 lines
2.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using FRT.Models;
|
|
using FaceRecognitionDotNet;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using System.IO;
|
|
|
|
namespace FRT.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly IHostingEnvironment _env;
|
|
private FaceRecognition _FaceRecognition;
|
|
|
|
public HomeController(IHostingEnvironment env)
|
|
{
|
|
this._env = env;
|
|
}
|
|
|
|
public IActionResult Index(string s, string t, int f = 1)
|
|
{
|
|
var result = 0;
|
|
DateTime start;
|
|
DateTime end;
|
|
this._FaceRecognition = FaceRecognition.Create(Path.Combine(this._env.WebRootPath, "face"));
|
|
//
|
|
using (var image1 = FaceRecognition.LoadImageFile(Path.Combine(this._env.WebRootPath, "TestImages", $"{s}.jpg")))
|
|
{
|
|
using (var image2 = FaceRecognition.LoadImageFile(Path.Combine(this._env.WebRootPath, "TestImages", $"{t}.jpg")))
|
|
{
|
|
var endodings1 = this._FaceRecognition.FaceEncodings(image1).ToArray();
|
|
var endodings2 = this._FaceRecognition.FaceEncodings(image2).ToArray();
|
|
start = DateTime.Now;
|
|
foreach (var encoding in endodings1)
|
|
{
|
|
for (int i = 0; i < f; i++)
|
|
{
|
|
foreach (var compareFace in FaceRecognition.CompareFaces(endodings2, encoding, 0.6))
|
|
{
|
|
result += compareFace ? 1 : 0;
|
|
}
|
|
}
|
|
}
|
|
end = DateTime.Now;
|
|
foreach (var encoding in endodings1)
|
|
{
|
|
encoding.Dispose();
|
|
}
|
|
foreach (var encoding in endodings2)
|
|
{
|
|
encoding.Dispose();
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
this._FaceRecognition.Dispose();
|
|
return Content((end - start).TotalSeconds + " : " + result.ToString());
|
|
}
|
|
|
|
public IActionResult Privacy()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
public IActionResult Error()
|
|
{
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
}
|
|
}
|
|
} |