private void startCameraSource()
 {
     try
     {
         textRecognizer = new TextRecognizer.Builder(this).Build();
         if (!textRecognizer.IsOperational)
         {
             System.Diagnostics.Debug.WriteLine("Detector dependencies not loaded yet");
         }
         else
         {
             mCameraSource = new CameraSource.Builder(this, textRecognizer)
                             .SetFacing(CameraFacing.Back)
                             .SetRequestedPreviewSize(1280, 1024)
                             .SetAutoFocusEnabled(true)
                             .SetRequestedFps(2.0f)
                             .Build();
             mCameraView.Holder.AddCallback(this);
             textRecognizer.SetProcessor(this);
             if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == Android.Content.PM.Permission.Granted)
             {
                 mCameraSource.Start(mCameraView.Holder);
             }
             else
             {
                 ActivityCompat.RequestPermissions(this,
                                                   new String[] { Manifest.Permission.Camera },
                                                   requestPermissionID);
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
Exemple #2
0
 public void CrearTextRecognizer()
 {
     textRecognizer = new TextRecognizer.Builder(ApplicationContext).Build();
     if (!textRecognizer.IsOperational)
     {
         Log.Error("Aviso:", "Detector no disponible!");
     }
     else
     {
         // Caracteristicas del CameraSource
         cameraSource = new CameraSource.Builder(ApplicationContext, textRecognizer)
                        .SetFacing(CameraFacing.Back)        //Camara seleccionada
                        .SetRequestedPreviewSize(1920, 1080) //Tamaño de la vista previa en uso por la camara
                        .SetRequestedFps(2.0f)               //Velocidad de fotogramas (En fotogramas por segundo)
                        .SetAutoFocusEnabled(true)           //Autoenfoque
                        .Build();
         cameraView.Holder.AddCallback(this);                //Recibe informacion del SurfaceView.
         textRecognizer.SetProcessor(this);                  //Estable Iprocessor para el textRecognizer.
     }
 }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            surfaceView   = FindViewById <SurfaceView>(Resource.Id.surface_view);
            textView      = FindViewById <TextView>(Resource.Id.txt_view);
            capture       = FindViewById <ImageView>(Resource.Id.imageView2);
            mainLayout    = FindViewById <LinearLayout>(Resource.Id.mainmenulayout);
            captureLayout = FindViewById <LinearLayout>(Resource.Id.capturemenulayout);
            back          = FindViewById <ImageView>(Resource.Id.imageView4);
            speak         = FindViewById <ImageView>(Resource.Id.imageView5);
            translate     = FindViewById <ImageView>(Resource.Id.imageView6);
            settings      = FindViewById <ImageView>(Resource.Id.imageView3);
            gallery       = FindViewById <ImageView>(Resource.Id.imageView1);
            selectedimage = FindViewById <ImageView>(Resource.Id.imageView7);



            capture.Click += (sender, e) =>
            {
                cameraSource.Stop();

                mainLayout.Visibility         = ViewStates.Gone;
                captureLayout.Visibility      = ViewStates.Visible;
                textView.FocusableInTouchMode = true;
            };
            back.Click += (sender, e) =>
            {
                captureLayout.Visibility = ViewStates.Gone;
                selectedimage.Visibility = ViewStates.Gone;
                mainLayout.Visibility    = ViewStates.Visible;
                surfaceView.Visibility   = ViewStates.Visible;
                cameraSource.Start(surfaceView.Holder);
            };

            gallery.Click += (sender, e) =>
            {
                cameraSource.Stop();
                Intent galleryIntent = new Intent();
                galleryIntent.SetType("image/*");
                galleryIntent.SetAction(Intent.ActionGetContent);
                StartActivityForResult(Intent.CreateChooser(galleryIntent, "select"), PickImageID);
            };


            textRecognizer = new TextRecognizer.Builder(ApplicationContext).Build();
            if (!textRecognizer.IsOperational)
            {
                //todo:exception
            }
            else
            {
                cameraSource = new CameraSource.Builder(ApplicationContext, textRecognizer)
                               .SetFacing(CameraFacing.Back)
                               .SetRequestedPreviewSize(1280, 1024)
                               .SetRequestedFps(2.0f)
                               .SetAutoFocusEnabled(true)
                               .Build();

                surfaceView.Holder.AddCallback(this);
                textRecognizer.SetProcessor(this);
            }
        }