Beispiel #1
0
        private List <MarkFaceInfor> ExtractFaceData(Mat mat, Arcsoft_Face_Action arcsoft)
        {
            if (mat != null)
            {
                Image     image     = mat.ToBitmap();
                ImageInfo imageInfo = new ImageInfo();
                imageInfo = ImageHelper.ReadBMPFromImage(image, imageInfo);
                List <MarkFaceInfor> markFaceInfors = new List <MarkFaceInfor>();

                if (imageInfo.imgData != IntPtr.Zero)
                {
                    var engine = arcsoft.GetEngine(arcsoft.FaceEnginePoor);
                    while (engine == IntPtr.Zero)
                    {
                        Task.Delay(10).Wait();
                        engine = arcsoft.GetEngine(arcsoft.FaceEnginePoor);
                    }
                    markFaceInfors = Arcsoft_Face_Action.DetectMultipleFaceAllInformation(engine, imageInfo, true);
                    arcsoft.PutEngine(arcsoft.FaceEnginePoor, engine);
                }
                else
                {
                    markFaceInfors = null;
                }
                image.Dispose();
                Marshal.FreeHGlobal(imageInfo.imgData);
                return(markFaceInfors);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        private void InitializeEngine(IConfiguration conf)
        {
            IConfiguration config = conf;

            _appID      = config["AppID"];
            _faceKey    = config["AppKey"];
            _engineNums = int.Parse(config["EngineNums"]);

            _enginePool = new Arcsoft_Face_Action(_appID, _faceKey);
            _enginePool.Arcsoft_EnginePool(_engineNums, 0, 0);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            //配置grpc
            services.AddGrpc();

            //添加虹软“引擎池”服务
            Arcsoft_Face_Action enginePool = new Arcsoft_Face_Action(appID, faceKey);

            enginePool.Arcsoft_EnginePool(faceEngineNums, 0, 0);
            services.AddArcSoftFaceService(enginePool);
        }
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            //取配置参数
            appID          = Configuration.GetSection("AppSettings:AppId").Value;
            faceKey        = Configuration.GetSection("AppSettings:FaceKey").Value;
            faceEngineNums = 0;
            int.TryParse(Configuration.GetSection("AppSettings:FaceEngineNum").Value, out faceEngineNums);
            arcsoft_Face_Action = new Arcsoft_Face_Action(appID, faceKey);
        }
 public static IServiceCollection AddArcSoftFaceService(this IServiceCollection services, Arcsoft_Face_Action enginePool)
 {
     services.AddSingleton <IEnginePoor, Arcsoft_Face_Action>(x => enginePool);
     return(services);
 }
Beispiel #6
0
        public override async Task RecongnizationByFace(IAsyncStreamReader <FaceRequest> requestStream, IServerStreamWriter <FaceReply> responseStream, ServerCallContext context)
        {
            var       faceQueue    = new Queue <Google.Protobuf.ByteString>();
            IntPtr    featurePoint = IntPtr.Zero;
            IntPtr    engine       = FaceProcess.GetEngine(FaceProcess.FaceEnginePoor);
            FaceReply faceReply    = new FaceReply();

            /*
             * //开始取数据
             * while (await requestStream.MoveNext())
             * {
             *  faceQueue.Enqueue(requestStream.Current.FaceFeature);
             * }
             * //开始业务处理
             * while (faceQueue.TryDequeue(out var feature))
             * {
             *  //识别业务
             *  byte[] featureByte = feature.ToByteArray();
             *  featurePoint = Arcsoft_Face_Action.PutFeatureByteIntoFeatureIntPtr(featureByte);
             *  float maxScore = 0f;
             *
             *  while (engine == IntPtr.Zero)
             *  {
             *      Task.Delay(10).Wait();
             *      engine = FaceProcess.GetEngine(FaceProcess.IDEnginePoor);
             *  }
             *  foreach (var f in StaticDataForTestUse.dbFaceInfor)
             *  {
             *      float result = 0;
             *      int compareStatus = Arcsoft_Face_3_0.ASFFaceFeatureCompare(engine, featurePoint, f.Key, ref result, 1);
             *      if (compareStatus == 0)
             *      {
             *          if (result >= maxScore)
             *          {
             *              maxScore = result;
             *          }
             *          if (result >= _faceMix && result>= maxScore)
             *          {
             *              faceReply.PersonName = f.Value;
             *              faceReply.ConfidenceLevel = result;
             *          }
             *      }
             *      else
             *      {
             *          faceReply.PersonName = $"对比异常 error code={compareStatus}";
             *          faceReply.ConfidenceLevel = result;
             *      }
             *  }
             *  if (maxScore < _faceMix)
             *  {
             *      faceReply.PersonName = $"未找到匹配者";
             *      faceReply.ConfidenceLevel = maxScore;
             *  }
             *  Marshal.FreeHGlobal(featurePoint);
             *  FaceProcess.PutEngine(FaceProcess.FaceEnginePoor, engine);
             *  await responseStream.WriteAsync(faceReply) ;
             * }
             */
            while (await requestStream.MoveNext())
            {
                //识别业务
                byte[] featureByte = requestStream.Current.FaceFeature.ToByteArray();
                if (featureByte.Length != 1032)
                {
                    continue;
                }
                featurePoint = Arcsoft_Face_Action.PutFeatureByteIntoFeatureIntPtr(featureByte);
                float maxScore = 0f;

                while (engine == IntPtr.Zero)
                {
                    Task.Delay(10).Wait();
                    engine = FaceProcess.GetEngine(FaceProcess.IDEnginePoor);
                }
                foreach (var f in StaticDataForTestUse.dbFaceInfor)
                {
                    float result        = 0;
                    int   compareStatus = Arcsoft_Face_3_0.ASFFaceFeatureCompare(engine, featurePoint, f.Key, ref result, 1);
                    if (compareStatus == 0)
                    {
                        if (result >= maxScore)
                        {
                            maxScore = result;
                        }
                        if (result >= _faceMix && result >= maxScore)
                        {
                            faceReply.PersonName      = f.Value;
                            faceReply.ConfidenceLevel = result;
                        }
                    }
                    else
                    {
                        faceReply.PersonName      = $"对比异常 error code={compareStatus}";
                        faceReply.ConfidenceLevel = result;
                    }
                }
                if (maxScore < _faceMix)
                {
                    faceReply.PersonName      = $"未找到匹配者";
                    faceReply.ConfidenceLevel = maxScore;
                }
                Marshal.FreeHGlobal(featurePoint);
                await responseStream.WriteAsync(faceReply);
            }
            FaceProcess.PutEngine(FaceProcess.FaceEnginePoor, engine);
        }