protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.FaceTracker); mPreview = FindViewById <CameraSourcePreview> (Resource.Id.preview); mGraphicOverlay = FindViewById <GraphicOverlay> (Resource.Id.faceOverlay); var detector = new Android.Gms.Vision.Faces.FaceDetector.Builder(Application.Context).Build(); detector.SetProcessor( new Android.Gms.Vision.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 Android.Gms.Vision.CameraSource.Builder(Application.Context, detector) .SetRequestedPreviewSize(640, 480) .SetFacing(Android.Gms.Vision.CameraFacing.Back) .SetRequestedFps(30.0f) .Build(); }
//============================================================================================== // Camera Source Preview //============================================================================================== /** * 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. */ void StartCameraSource() { try { mPreview.Start(mCameraSource, mGraphicOverlay); } catch (Exception e) { Android.Util.Log.Error(TAG, "Unable to start camera source.", e); mCameraSource.Release(); mCameraSource = null; } }
public QRSurfaceView(Context context) : base(context) { //https://firebase.google.com/docs/ml-kit/android/read-barcodes //FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap); if (detector == null) { detector = new Android.Gms.Vision.Barcodes.BarcodeDetector .Builder(Application.Context).SetBarcodeFormats(Android.Gms.Vision.Barcodes.BarcodeFormat.QrCode) .Build(); if (!detector.IsOperational) { System.Diagnostics.Debug.WriteLine("android barcode detector is not operational"); return; } if (cameraSource == null) { cameraSource = new Android.Gms.Vision.CameraSource.Builder(Application.Context, detector).Build(); } } }