示例#1
0
        private void CreateFaceAnalyzer()
        {
            // Create a face analyzer. You can create an analyzer using the provided customized face detection parameter
            ML3DFaceAnalyzerSetting setting = new ML3DFaceAnalyzerSetting.Factory()
                                              // Fast detection of continuous video frames.
                                              // MLFaceAnalyzerSetting.TypePrecision: indicating the precision preference mode.
                                              // This mode will detect more faces and be more precise in detecting key points and contours, but will run slower.
                                              // MLFaceAnalyzerSetting.TypeSpeed: representing a preference for speed.
                                              // This will detect fewer faces and be less precise in detecting key points and contours, but will run faster.
                                              // .SetPerformanceType(MLFaceAnalyzerSetting.TypeSpeed)
                                              .SetPerformanceType(ML3DFaceAnalyzerSetting.TypeSpeed)
                                              .SetTracingAllowed(true)
                                              .Create();

            this.analyzer = MLAnalyzerFactory.Instance.Get3DFaceAnalyzer(setting);
            this.analyzer.SetTransactor(this);
        }
示例#2
0
        private async void Analyze()
        {
            // Create a face analyzer. You can create an analyzer using the provided customized face detection parameter
            ML3DFaceAnalyzerSetting setting = new ML3DFaceAnalyzerSetting.Factory()
                                              // Fast detection of continuous video frames.
                                              // MLFaceAnalyzerSetting.TypePrecision: indicating the precision preference mode.
                                              // This mode will detect more faces and be more precise in detecting key points and contours, but will run slower.
                                              // MLFaceAnalyzerSetting.TypeSpeed: representing a preference for speed.
                                              // This will detect fewer faces and be less precise in detecting key points and contours, but will run faster.
                                              .SetPerformanceType(MLFaceAnalyzerSetting.TypePrecision)
                                              .SetTracingAllowed(false)
                                              .Create();

            this.analyzer = MLAnalyzerFactory.Instance.Get3DFaceAnalyzer(setting);
            // Create an MLFrame by using the bitmap. Recommended image size: large than 320*320, less than 1920*1920.
            Bitmap  bitmap = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.face_image);
            MLFrame frame  = MLFrame.FromBitmap(bitmap);
            // Call the AnalyseFrameAsync method to perform face detection
            Task <IList <ML3DFace> > task = this.analyzer.AnalyseFrameAsync(frame);

            try
            {
                await task;

                if (task.IsCompleted && task.Result != null)
                {
                    //Analyze success
                    var faces = task.Result;
                    if (faces.Count > 0)
                    {
                        this.DisplaySuccess(faces.ElementAt(0));
                    }
                }
                else
                {
                    //Analyze failed
                    this.DisplayFailure();
                }
            }
            catch (Exception e)
            {
                //Operation failed
                Log.Error(Tag, e.Message);
            }
        }