83 lines
2.7 KiB
C#
83 lines
2.7 KiB
C#
|
|
using BLL;
|
|||
|
|
using SgManager.AI;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Drawing;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Web.Services;
|
|||
|
|
using System.Web.UI;
|
|||
|
|
|
|||
|
|
|
|||
|
|
namespace FineUIPro.Web.WeldMat.UsingSentMat
|
|||
|
|
{
|
|||
|
|
public partial class FaceRecognition : PageBase
|
|||
|
|
{
|
|||
|
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
[WebMethod]
|
|||
|
|
public static string UploadData(string data)
|
|||
|
|
{
|
|||
|
|
byte[] imageBytes = Convert.FromBase64String(data.Substring("data:image/jpeg;base64,".Length));
|
|||
|
|
string filePath = "/FileUpLoad/FaceRecognition/" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".jpeg";
|
|||
|
|
if (!Directory.Exists(BLL.Funs.RootPath + "/FileUpLoad/FaceRecognition/"))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(BLL.Funs.RootPath + "/FileUpLoad/FaceRecognition/");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 使用MemoryStream将字节数组转换为图片
|
|||
|
|
using (var ms = new MemoryStream(imageBytes, 0, imageBytes.Length))
|
|||
|
|
{
|
|||
|
|
System.Drawing.Image mImage = System.Drawing.Image.FromStream(ms);
|
|||
|
|
|
|||
|
|
// 使用Bitmap类从MemoryStream创建图片
|
|||
|
|
using (Bitmap image = new Bitmap(mImage))
|
|||
|
|
{
|
|||
|
|
// 保存图片到文件
|
|||
|
|
image.Save(BLL.Funs.RootPath + filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var kqFace = (List<SgManager.AI.faceResult>)SgManager.AI.FaceClass.SearchFileFace(BLL.Funs.RootPath + filePath);
|
|||
|
|
if (kqFace == null || kqFace.Count == 0)
|
|||
|
|
{
|
|||
|
|
return "识别失败";
|
|||
|
|
}
|
|||
|
|
else if (kqFace[0].errMess != "SUCCESS")
|
|||
|
|
{
|
|||
|
|
return "识别失败;" + kqFace[0].errMess;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
string idCard = kqFace[0].user_id;
|
|||
|
|
var welder = Funs.DB.HJGL_BS_Welder.FirstOrDefault(x =>x.IdentityCard == idCard);
|
|||
|
|
if (welder != null)
|
|||
|
|
{
|
|||
|
|
return welder.WED_Code;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return "识别失败;身份证号"+ idCard+"未找到焊工";
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
return "识别失败";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|