protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            mPreview        = FindViewById <CameraSourcePreview>(Resource.Id.preview);
            mGraphicOverlay = FindViewById <GraphicOverlay>(Resource.Id.faceOverlay);

            if (savedInstanceState != null)
            {
                mIsFrontFacing = savedInstanceState.GetBoolean("IsFrontFacing");
            }

            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == Permission.Granted)
            {
                createCameraSource();
            }
            else
            {
                RequestCameraPermission();
            }

            // Create your application here
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            mPreview        = FindViewById <CameraSourcePreview>(Resource.Id.preview);
            mGraphicOverlay = FindViewById <GraphicOverlay>(Resource.Id.faceOverlay);

            var detector = new FaceDetector.Builder(Application.Context).Build();

            detector.SetProcessor(
                new MultiProcessor.Builder(new GraphicFaceTrackerFactory(mGraphicOverlay)).Build());

            if (!detector.IsOperational)
            {
                // Note: The first time that an app using face API is installed on a device, GMS will
                // download a native library to the device in order to do detection.  Usually this
                // completes before the app is run for the first time.  But if that download has not yet
                // completed, then the above call will not detect any faces.
                //
                // isOperational() can be used to check if the required native library is currently
                // available.  The detector will automatically become operational once the library
                // download completes on device.
                Android.Util.Log.Warn(TAG, "Face detector dependencies are not yet available.");
            }

            mCameraSource = new CameraSource.Builder(Application.Context, detector)
                            .SetRequestedPreviewSize(640, 480)
                            .SetFacing(CameraFacing.Back)
                            .SetRequestedFps(30.0f)
                            .Build();
        }
Exemplo n.º 3
0
        /**
         * Starts or restarts the camera source, if it exists.  If the camera source doesn't exist yet
         * (e.g., because onResume was called before the camera source was created), this will be called
         * again when the camera source is created.
         */
        private void StartCameraSource()
        {
            try
            {
                CameraSourcePreview.Start(MCameraSource, MGraphicOverlay);
            }
            catch (Exception e)
            {
                Android.Util.Log.Error(TAG, "Unable to start camera source.", e);
                MCameraSource.Release();
                MGraphicOverlay = null;
//                Crashlytics.Crashlytics.LogException(Java.Lang.Throwable.FromException(e));
            }
        }
Exemplo n.º 4
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.FaceIdentify);

            this.cameraPreview  = this.FindViewById <CameraSourcePreview>(Resource.Id.preview);
            this.graphicOverlay = this.FindViewById <GraphicOverlay>(Resource.Id.faceOverlay);

            var button = (ImageButton)this.FindViewById(Resource.Id.flipButton);

            button.Click += (sender, args) =>
            {
                this.isFrontFacing = !this.isFrontFacing;

                if (this.cameraSource != null)
                {
                    this.cameraSource.Release();
                    this.cameraSource = null;
                }

                this.CreateCameraSource();
                this.StartCameraSource();
            };

            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == Permission.Granted)
            {
                this.CreateCameraSource();
                LiveCamHelper.Init();
                LiveCamHelper.GreetingsCallback     = (s) => { this.RunOnUiThread(() => Greetings = s); };
                LiveCamHelper.FacesDetectedCallback = result => { this.RunOnUiThread(() => CognitiveFacesResult = result); };

                this.faceService = new FaceService();
                await this.faceService.Initialize();

                //using (var stream = File.OpenRead("/data/user/0/CognitiveDemo.Droid/files/CognitivveFrame.png"))
                //{
                //    await this.faceService.IdentityFace(stream);
                //}
            }
            else
            {
                this.RequestCameraPermission();
            }
        }
Exemplo n.º 5
0
        protected override void OnLayout(bool changed, int l, int t, int r, int b)
        {
            base.OnLayout(changed, l, t, r, b);

            if (MainLayout != null)
            {
                var width  = r - l;
                var height = b - t;
                var msw    = MeasureSpec.MakeMeasureSpec(width, MeasureSpecMode.Exactly);
                var msh    = MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly);

                MainLayout.Measure(msw, msh);
                MainLayout.Layout(0, 0, width, height);

                CameraSourcePreview.Layout(0, 0, width, height);

                //ControlsBox.Layout(0, 0, width, );
            }
            base.OnLayout(changed, l, t, r, b);
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.face_recognition);

            BTArduino = new BlueToothConnectionPortable();

            mPreview        = FindViewById <CameraSourcePreview>(Resource.Id.preview);
            mGraphicOverlay = FindViewById <GraphicOverlay>(Resource.Id.faceOverlay);

            if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == Permission.Granted)
            {
                CreateCameraSource();
                LiveCamHelper.Init();
                LiveCamHelper.GreetingsCallback = (s) => { RunOnUiThread(() => GreetingsText = s); };
                //Task.Run(() => LiveCamHelper.RegisterFaces());
            }
            else
            {
                RequestCameraPermission();
            }
        }
Exemplo n.º 7
0
 public Scanner(CameraSourcePreview preview, GraphicOverlay graphicOverlay, Context applicationContext)
 {
     _preview            = preview;
     _graphicOverlay     = graphicOverlay;
     _applicationContext = applicationContext;
 }