コード例 #1
0
        /// <summary>
        /// 注册事件触发函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args">变量参数</param>
        public static void NewUserRegist(object sender, myEventArgs.RegistArgs args)
        {
            /****************************
            * 保存特征值时才区分性别
            * **************************/
            //下载图片到本地
            String url = String.Format("{0}/{1}_{2}.{3}",
                                       Url_DldImg, args.Regist.Id, args.Regist.Name, args.Regist.Extension);
            String pathImg = String.Format("{0}\\{1}_{2}.{3}",
                                           ImgRootPath_Regist, args.Regist.Id, args.Regist.Name, args.Regist.Extension);

            HttpUtil.downFile(url, pathImg);
            //判断性别(假设性别判断 100% 准确)
            try
            {
                ResultCode result = EngineActivate.ActivateEngine(APPID, APPKEY);
                if (result != ResultCode.SDK已激活)
                {
                    Console.WriteLine(result.ToString());
                    return;
                }
                IntPtr hengine = EngineFactory.GetEngineInstance(EngineFactory.Image,
                                                                 DetectionOrientPriority.ASF_OP_0_ONLY, 16); //检测角度指人脸在照片中的角度
                Bitmap img1 = new Bitmap(pathImg);

                var          face  = new FaceDetection(hengine, img1);
                var          r     = face.GetGender();
                LocalUserMod temp1 = new LocalUserMod();
                temp1.Name = args.Regist.Name;
                temp1.Num  = args.Regist.Id;
                //用Base64转码
                temp1.Freature = Convert.ToBase64String(face.getFaceFeature(img1));
                //销毁图片
                img1.Dispose();
                //提取特征值保存
                switch (r)
                {
                case "男":
                    XmlUtil.AddOneData(temp1, "Male");
                    break;

                case "女":
                    XmlUtil.AddOneData(temp1, "Female");
                    break;

                default:
                    Console.WriteLine("获取性别失败!用户:{0} , 学号:{1},注册时间:{2}",
                                      args.Regist.Name, args.Regist.Id, DateTime.Now.ToString());
                    return;
                }
                //提示用户注册
                Console.WriteLine("User registed: {0} at {1}", args.Regist.Name, DateTime.Now.ToString());
                //更新用户信息
                //令写一个函数
                getAllUserInfo();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Regist Error: {0}", ex.Message);
            }
            finally
            {
                EngineFactory.DisposeEngine();
            }
        }