Ejemplo n.º 1
0
        public void Init(CameraSurfaceView view)
        {
            mTextureView = view;

            // fill ORIENTATIONS list
            ORIENTATIONS.Append((int)SurfaceOrientation.Rotation0, 90);
            ORIENTATIONS.Append((int)SurfaceOrientation.Rotation90, 0);
            ORIENTATIONS.Append((int)SurfaceOrientation.Rotation180, 270);
            ORIENTATIONS.Append((int)SurfaceOrientation.Rotation270, 180);

            switch (MainActivity.SavedDataStore.SelectedResolution)
            {
            case Classes.SaveData.CaptureResolution.Res480p:
                MAX_PREVIEW_WIDTH  = 720;
                MAX_PREVIEW_HEIGHT = 480;
                break;

            case Classes.SaveData.CaptureResolution.Res720p:
                MAX_PREVIEW_WIDTH  = 1280;
                MAX_PREVIEW_HEIGHT = 720;
                break;

            case Classes.SaveData.CaptureResolution.Res1080p:
                MAX_PREVIEW_WIDTH  = 1920;
                MAX_PREVIEW_HEIGHT = 1080;
                break;

            case Classes.SaveData.CaptureResolution.Res2160p:
                MAX_PREVIEW_WIDTH  = 3840;
                MAX_PREVIEW_HEIGHT = 2160;
                break;
            }

            StartBackgroundThread();
        }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            LoadModelLabels();

            var manager = (CameraManager)this.GetSystemService(Context.CameraService);

            var numCameras = manager.GetCameraIdList().Length;

            if (numCameras == 0)
            {
                s.MessageBox(this, "Erro", "Infelizmente o MotoDetector não funcionará no seu dispositivo, " +
                             "pois ele não suporta a API Camera2.", null);
            }

            var cameraIDs = new List <string>();

            for (var i = 0; i < numCameras; i++)
            {
                var cameraId        = manager.GetCameraIdList()[i];
                var characteristics = manager.GetCameraCharacteristics(cameraId);

                // We don't use a front facing camera in this sample.
                var facing = (Integer)characteristics.Get(CameraCharacteristics.LensFacing);
                if (facing != null && facing == (Integer.ValueOf((int)LensFacing.Front)))
                {
                }
                else
                {
                    cameraIDs.Add(cameraId);
                }
            }

            NumberOfCameras = cameraIDs.Count;

            SavedDataStore = SaveData.Load();

            if (SavedDataStore == null)
            {
                SavedDataStore = new SaveData();
            }

            if (SavedDataStore.Camera == "")
            {
                SavedDataStore.Camera = cameraIDs[0];
            }

            context = this;

            MotosList = Motos.Get();

            AppCenter.Start("6ef03cf3-90e1-4478-a070-4446c0e3e78c", typeof(Analytics), typeof(Crashes));

            this.RequestWindowFeature(WindowFeatures.NoTitle);

            this.Window.AddFlags(WindowManagerFlags.Fullscreen);
            this.Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            SetContentView(Resource.Layout.mainwindow);

            cameraSurface            = new CameraSurfaceView(this);
            canvasView               = new SKCanvasView(this);
            canvasView.PaintSurface += Canvas_PaintSurface;

            var mainView = this.FindViewById <FrameLayout>(Resource.Id.frameLayoutMain);

            mainView.AddView(canvasView);
            mainView.AddView(cameraSurface);

            var mainLayout = this.FindViewById <LinearLayout>(Resource.Id.linearLayoutMain);

            mainLayout.BringToFront();
            canvasView.BringToFront();

            var proc = System.Diagnostics.Process.GetCurrentProcess();

            var rb1 = this.FindViewById <RadioButton>(Resource.Id.radioButton1);
            var rb2 = this.FindViewById <RadioButton>(Resource.Id.radioButton2);
            var rb3 = this.FindViewById <RadioButton>(Resource.Id.radioButton3);
            var rb4 = this.FindViewById <RadioButton>(Resource.Id.radioButton4);

            if (NumberOfCameras == 1)
            {
                rb2.Enabled = false;
                rb3.Enabled = false;
                rb4.Enabled = false;
            }
            else if (NumberOfCameras == 2)
            {
                rb3.Enabled = false;
                rb4.Enabled = false;
            }
            else if (NumberOfCameras == 3)
            {
                rb4.Enabled = false;
            }

            switch (cameraIDs.IndexOf(SavedDataStore.Camera))
            {
            case 0:
                rb1.Selected = true;
                break;

            case 1:
                rb2.Selected = true;
                break;

            case 2:
                rb3.Selected = true;
                break;

            case 3:
                rb4.Selected = true;
                break;
            }

            var rg = this.FindViewById <RadioGroup>(Resource.Id.radioGroup1);

            rg.CheckedChange += (s, e) =>
            {
                if (rb1.Id.Equals(e.CheckedId))
                {
                    SavedDataStore.Camera = cameraIDs[0];
                }
                else if (rb2.Id.Equals(e.CheckedId))
                {
                    SavedDataStore.Camera = cameraIDs[1];
                }
                else if (rb3.Id.Equals(e.CheckedId))
                {
                    SavedDataStore.Camera = cameraIDs[2];
                }
                else
                {
                    SavedDataStore.Camera = cameraIDs[3];
                }
                SavedDataStore.Save();
                ConfigureCapture();
            };

            var btnInfo = this.FindViewById <ImageButton>(Resource.Id.btnInfo);

            btnInfo.Click += (sender, e) =>
            {
                DisplayMotoDetails();
            };

            var btnSettings = this.FindViewById <ImageButton>(Resource.Id.imageButtonSettings);

            btnSettings.Click += (sender, e) =>
            {
                DisplaySettingsView();
            };

            var imgwarning = MainActivity.context.FindViewById <ImageButton>(Resource.Id.imageButtonWarning);

            imgwarning.Visibility = ViewStates.Gone;

            imgwarning.Click += (sender, e) =>
            {
                this.RunOnUiThread(() =>
                {
                    imgwarning.Visibility = ViewStates.Gone; var layout = MainActivity.context.FindViewById <LinearLayout>(Resource.Id.linearLayoutLabelPanel);
                    layout.SetBackgroundColor(Android.Graphics.Color.ParseColor("#bc000000"));
                    var txtView = MainActivity.context.FindViewById <TextView>(Resource.Id.txtObjID);
                    txtView.SetTextColor(Android.Graphics.Color.White);
                });
            };

            var zoomslider = MainActivity.context.FindViewById <SeekBar>(Resource.Id.seekBarZoom);

            zoomslider.ProgressChanged += (s, e) =>
            {
                var   characteristics = manager.GetCameraCharacteristics(SavedDataStore.Camera);
                float maxZoom         = (float)characteristics.Get(CameraCharacteristics.ScalerAvailableMaxDigitalZoom);
                float currentZoom     = 1.0f;
                if (zoomslider.Progress >= 100)
                {
                    currentZoom = maxZoom;
                }
                else
                {
                    currentZoom = (float)zoomslider.Progress / 100.0f * maxZoom;
                }
                var  controller = cameraSurface.cameraAnalyzer.cameraController;
                Rect m          = (Rect)characteristics.Get(CameraCharacteristics.SensorInfoActiveArraySize);
                var  w          = (m.Right - m.Left) / 2.5;
                var  h          = (m.Bottom - m.Top) / 2.5;
                var  factor     = currentZoom / maxZoom;
                Rect m1         = new Rect((int)(m.Left + w * factor), (int)(m.Top + h * factor), (int)(m.Right - w * factor), (int)(m.Bottom - h * factor));
                controller.mPreviewRequestBuilder.Set(CaptureRequest.ScalerCropRegion, m1);
                controller.mCameraCaptureSessionCallback.OnConfigured(controller.mCaptureSession);
            };

            var zoomexposure = MainActivity.context.FindViewById <SeekBar>(Resource.Id.seekBarExposure);

            zoomexposure.ProgressChanged += (s, e) =>
            {
                var   characteristics = manager.GetCameraCharacteristics(SavedDataStore.Camera);
                float value           = (float)zoomexposure.Progress;
                var   range1          = (Android.Util.Range)characteristics.Get(CameraCharacteristics.ControlAeCompensationRange);
                int   minExposure     = (int)range1.Lower;
                int   maxExposure     = (int)range1.Upper;
                if (minExposure == 0 && maxExposure == 0)
                {
                    Toast.MakeText(this, "A lente selecionada não suporta Compensação da Exposição.", ToastLength.Long).Show();
                    return;
                }
                int adjustedvalue = (int)(value * ((float)maxExposure - (float)minExposure) / 200.0f);
                var controller    = cameraSurface.cameraAnalyzer.cameraController;
                controller.mPreviewRequestBuilder.Set(CaptureRequest.ControlAeExposureCompensation, adjustedvalue);
                controller.mCameraCaptureSessionCallback.OnConfigured(controller.mCaptureSession);
            };

            var sw = new Stopwatch();

            sw.Start();

            var tim = new Timer();

            tim.Interval = 1000;

            tim.Elapsed += (s, e) =>
            {
                var cpu = (proc.TotalProcessorTime.TotalMilliseconds / sw.ElapsedMilliseconds) * 100;
                var mem = proc.WorkingSet64 / 1024 / 1024;
                this.RunOnUiThread(() =>
                {
                    var txtCPU  = this.FindViewById <TextView>(Resource.Id.textViewCPU);
                    var txtMEM  = this.FindViewById <TextView>(Resource.Id.textViewMEM);
                    var txtFPS  = this.FindViewById <TextView>(Resource.Id.textViewFPS);
                    var txtAFPS = this.FindViewById <TextView>(Resource.Id.textViewAFPS);
                    txtCPU.SetTextColor(Color.White);
                    if (cpu < 40)
                    {
                        txtCPU.SetTextColor(Color.Green);
                    }
                    if (cpu > 40)
                    {
                        txtCPU.SetTextColor(Color.Yellow);
                    }
                    if (cpu > 80)
                    {
                        txtCPU.SetTextColor(Color.Red);
                    }
                    txtCPU.Text  = cpu.ToString("N2") + "%";
                    txtMEM.Text  = mem.ToString() + " MB";
                    txtAFPS.Text = PlateAndMotoStats.ProcessingFps.ToString("N0") + " (DET) / " + PlateAndMotoStats.CameraFps.ToString("N0") + " (CAPT) FPS";
                    txtFPS.Text  = RESID + " / " + FPS + " FPS";
                });
            };

            tim.Start();
        }