public ProcessedCameraPreview(Activity activity, bool cameraPreviewCallbackWithBuffer)
         : base(activity)
      {
         _cameraPreviewCallbackWithBuffer = cameraPreviewCallbackWithBuffer;

         _paint = new Paint();
         _paint.SetStyle(Paint.Style.Stroke);
         _paint.SetARGB(255, 255, 0, 0);
         _paint.TextSize = 25;

         using (Image<Bgr, Byte> img = new Image<Bgr, byte>(4, 8))
         {
         }
         _watch = Stopwatch.StartNew();
         _bgrBuffers = new ImageBufferFactory<Image<Bgr, byte>>( size => new Image<Bgr, Byte>(size) );
      }
Beispiel #2
0
 protected override void DisposeObject()
 {
    if (_bgrBuffers != null)
    {
       _bgrBuffers.Dispose();
       _bgrBuffers = null;
    }
    if (_grayBuffers != null)
    {
       _grayBuffers.Dispose();
       _grayBuffers = null;
    }
    if (_bgrSingleBuffers != null)
    {
       _bgrSingleBuffers.Dispose();
       _bgrSingleBuffers = null;
    }
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            RequestWindowFeature(WindowFeatures.NoTitle);
            bool cameraPreviewCallbackWithBuffer = false;

            SetContentView(Resource.Layout.CameraPreviewLayout);

            _bgrBuffers           = new ImageBufferFactory <Mat>(size => new Mat(size.Height, size.Width, DepthType.Cv8U, 3));
            _previewBitmapBuffers = new ImageBufferFactory <Android.Graphics.Bitmap>(s => Android.Graphics.Bitmap.CreateBitmap(s.Width, s.Height, Android.Graphics.Bitmap.Config.Rgb565));

            _topLayer = new ProcessedCameraPreview(this, cameraPreviewCallbackWithBuffer);
            _topLayer.PictureTaken += this.PictureTaken;
            _topLayer.ImagePreview += this.ImagePreview;

            _preview = new CameraPreview(this, _topLayer, cameraPreviewCallbackWithBuffer);

            RelativeLayout mainLayout = FindViewById <RelativeLayout>(Resource.Id.CameraPreiewRelativeLayout);

            mainLayout.AddView(_preview, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));
            mainLayout.AddView(_topLayer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent));

#if GL_VIEW
            _topLayer.SetZOrderOnTop(true);
#endif
            RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;

            ImageButton switchCameraButton = FindViewById <ImageButton>(Resource.Id.CameraPreviewSwitchCameraImageButton);
            if (Camera.NumberOfCameras <= 1)
            {
                switchCameraButton.Visibility = ViewStates.Invisible;
            }
            else
            {
                switchCameraButton.BringToFront();
            }
            switchCameraButton.Click += delegate
            {
                _preview.SwitchCamera();
            };

            ImageButton captureImageButton = FindViewById <ImageButton>(Resource.Id.CameraPreviewCaptureImageButton);
            captureImageButton.Click += delegate
            {
                Camera camera = _preview.Camera;

                if (camera != null)
                {
                    Camera.Parameters p = camera.GetParameters();
                    p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
                    //p.PictureFormat = Android.Graphics.ImageFormatType.Rgb565;
                    camera.SetParameters(p);
                    camera.TakePicture(null, null, _topLayer);
                }
            };

            _lastCapturedImageButton        = FindViewById <ImageButton>(Resource.Id.capturedImageButton);
            _lastCapturedImageButton.Click += delegate
            {
                if (_lastSavedImageFile != null)
                {
                    Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.FromFile(new Java.IO.File(_lastSavedImageFile.FullName)));
                    intent.SetType("image/jpeg");
                    StartActivity(intent);
                }
            };
            _lastCapturedImageButton.BringToFront();

            _previewButtons           = new ImageButton[4];
            _previewFilters           = new ImageFilter[4];
            _previewButtons[0]        = FindViewById <ImageButton>(Resource.Id.previewImageButton);
            _previewFilters[0]        = null;
            _previewButtons[0].Click += delegate
            {
                if (_imageFilter != null)
                {
                    _imageFilter.Dispose();
                    _imageFilter = null;
                }
            };
            _previewButtons[1] = FindViewById <ImageButton>(Resource.Id.cannyImageButton);
            _previewFilters[1] = new CannyFilter(100, 60, 3);

            _previewButtons[2] = FindViewById <ImageButton>(Resource.Id.colorMapImageButton);
            _previewFilters[2] = new ColorMapFilter(Emgu.CV.CvEnum.ColorMapType.Autumn);

            //_previewFilters[3] = new ColorMapFilter(Emgu.CV.CvEnum.ColorMapType.Summer);
            //_previewFilters[3] = null;
            _previewButtons[3] = FindViewById <ImageButton>(Resource.Id.distorImageButton);
            _previewFilters[3] = new DistorFilter(0.5, 0.5, -1.5);

            for (int i = 1; i < _previewButtons.Length; ++i)
            {
                ImageFilter f = _previewFilters[i];
                _previewButtons[i].Click += delegate
                {
                    if (_imageFilter != null)
                    {
                        _imageFilter.Dispose();
                    }
                    _imageFilter = f.Clone() as ImageFilter;
                };
            }
        }
      protected override void OnCreate(Bundle bundle)
      {
         base.OnCreate(bundle);
         RequestWindowFeature(WindowFeatures.NoTitle);
         bool cameraPreviewCallbackWithBuffer = false;
         SetContentView(Resource.Layout.CameraPreviewLayout);

         _bgrBuffers = new ImageBufferFactory<Mat>(size => new Mat(size.Height, size.Width, DepthType.Cv8U, 3));
         _previewBitmapBuffers = new ImageBufferFactory<Android.Graphics.Bitmap>(s => Android.Graphics.Bitmap.CreateBitmap(s.Width, s.Height, Android.Graphics.Bitmap.Config.Rgb565));

         _topLayer = new ProcessedCameraPreview(this, cameraPreviewCallbackWithBuffer);
         _topLayer.PictureTaken += this.PictureTaken;
         _topLayer.ImagePreview += this.ImagePreview;
         
         _preview = new CameraPreview(this, _topLayer, cameraPreviewCallbackWithBuffer);

         RelativeLayout mainLayout = FindViewById<RelativeLayout>(Resource.Id.CameraPreiewRelativeLayout);
         
         mainLayout.AddView(_preview, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));
         mainLayout.AddView(_topLayer, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent));

#if GL_VIEW
         _topLayer.SetZOrderOnTop(true);
#endif
         RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;

         ImageButton switchCameraButton = FindViewById<ImageButton>(Resource.Id.CameraPreviewSwitchCameraImageButton);
         if (Camera.NumberOfCameras <= 1)
            switchCameraButton.Visibility = ViewStates.Invisible;
         else
         {
            switchCameraButton.BringToFront();
         }
         switchCameraButton.Click += delegate
         {
            _preview.SwitchCamera();
         };

         ImageButton captureImageButton = FindViewById<ImageButton>(Resource.Id.CameraPreviewCaptureImageButton);
         captureImageButton.Click += delegate
         {
            Camera camera = _preview.Camera;

            if (camera != null)
            {
               Camera.Parameters p = camera.GetParameters();
               p.PictureFormat = Android.Graphics.ImageFormatType.Jpeg;
               //p.PictureFormat = Android.Graphics.ImageFormatType.Rgb565;
               camera.SetParameters(p);
               camera.TakePicture(null, null, _topLayer);
            }
         };

         _lastCapturedImageButton = FindViewById<ImageButton>(Resource.Id.capturedImageButton);
         _lastCapturedImageButton.Click += delegate
         {
            if (_lastSavedImageFile != null)
            {
               Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.FromFile(new Java.IO.File(_lastSavedImageFile.FullName)));
               intent.SetType("image/jpeg");
               StartActivity(intent);
            }
         };
         _lastCapturedImageButton.BringToFront();

         _previewButtons = new ImageButton[4];
         _previewFilters = new ImageFilter[4];
         _previewButtons[0] = FindViewById<ImageButton>(Resource.Id.previewImageButton);
         _previewFilters[0] = null;
         _previewButtons[0].Click += delegate
         {
            if (_imageFilter != null)
            {
               _imageFilter.Dispose();
               _imageFilter = null;
            }
         };
         _previewButtons[1] = FindViewById<ImageButton>(Resource.Id.cannyImageButton);
         _previewFilters[1] = new CannyFilter(100, 60, 3);

         _previewButtons[2] = FindViewById<ImageButton>(Resource.Id.colorMapImageButton);
         _previewFilters[2] = new ColorMapFilter(Emgu.CV.CvEnum.ColorMapType.Autumn);
         
         //_previewFilters[3] = new ColorMapFilter(Emgu.CV.CvEnum.ColorMapType.Summer);
         //_previewFilters[3] = null;
         _previewButtons[3] = FindViewById<ImageButton>(Resource.Id.distorImageButton);
         _previewFilters[3] =  new DistorFilter(0.5, 0.5, -1.5);

         for (int i = 1; i < _previewButtons.Length; ++i)
         {
            ImageFilter f = _previewFilters[i];
            _previewButtons[i].Click += delegate
            {
               if (_imageFilter != null)
                  _imageFilter.Dispose();
               _imageFilter = f.Clone() as ImageFilter;
            };
         }
      }
Beispiel #5
0
 public Mat GetBufferGray(Size size, int index)
 {
    if (_grayBuffers == null)
       _grayBuffers = new ImageBufferFactory<Mat>( s => new Mat(s.Height, s.Width, DepthType.Cv8U, 1));
    return _grayBuffers.GetBuffer(size, index);
 }
Beispiel #6
0
 public Mat GetBufferBgrSingle(Size size, int index)
 {
    if (_bgrSingleBuffers == null)
       _bgrSingleBuffers = new ImageBufferFactory<Mat>(s => new Mat(s.Height, s.Width, DepthType.Cv8U, 3));
    return _bgrSingleBuffers.GetBuffer(size, index);
 }