コード例 #1
0
        public DroidCameraPreview(Context context, CameraOptions option) : base(context)
        {
            CameraOption = option;

            var path       = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            var nativePath = Context.GetExternalFilesDir(Android.OS.Environment.DirectoryDocuments);

            // Camera Setup
            File                      = new Java.IO.File(path, "pic.jpg");
            CaptureCallback           = new CameraCaptureListener(this);
            mOnImageAvailableListener = new ImageAvailableListener(this);
            mStateCallback            = new CameraStateListener(this);
            mSurfaceTextureListener   = new Camera2BasicSurfaceTextureListener(this);

            mTextureView = new Camera2Basic.AutoFitTextureView(context);
            AddView(mTextureView);

            // 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);

            State = CameraState.Stopped;
        }
コード例 #2
0
        public DroidCameraPreview(Context context, CameraOptions option) : base(context)
        {
            CameraOption = option;

            // Camera Setup
            File                      = new Java.IO.File(Context.GetExternalFilesDir(null), "pic.jpg");
            CaptureCallback           = new CameraCaptureListener(this);
            mOnImageAvailableListener = new ImageAvailableListener(this, File);
            mStateCallback            = new CameraStateListener(this);
            mSurfaceTextureListener   = new Camera2BasicSurfaceTextureListener(this);

            mTextureView = new Camera2Basic.AutoFitTextureView(context);
            AddView(mTextureView);

            // 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);
        }
コード例 #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            AppPreference appPreference = new AppPreference();

            CvInvoke.UseOpenCL = false;  //appPreference.UseOpenCL;
            string oclDeviceName = appPreference.OpenClDeviceName;

            if (!string.IsNullOrEmpty(oclDeviceName))
            {
                CvInvoke.OclSetDefaultDevice(oclDeviceName);
                Log.Error(TAG, "\t\t --OclSetDefaultDevice: " + oclDeviceName);
            }

            mFile = new Java.IO.File(GetExternalFilesDir(null), "derp.jpg");

            ISharedPreferences preference = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);
            string             appVersion = PackageManager.GetPackageInfo(PackageName, Android.Content.PM.PackageInfoFlags.Activities).VersionName;

            if (!preference.Contains("cascade-data-version") || !preference.GetString("cascade-data-version", null).Equals(appVersion) ||
                !(preference.Contains("cascade-eye-data-path") || preference.Contains("cascade-face-data-path")))
            {
                AndroidFileAsset.OverwriteMethod overwriteMethod = AndroidFileAsset.OverwriteMethod.AlwaysOverwrite;

                FileInfo eyeFile  = AndroidFileAsset.WritePermanantFileAsset(this, "haarcascade_eye.xml", "cascade", overwriteMethod);
                FileInfo faceFile = AndroidFileAsset.WritePermanantFileAsset(this, "haarcascade_frontalface_alt_tree.xml", "cascade", overwriteMethod);

                Log.Error(TAG, "\t\t --eyeFile.FullName: " + eyeFile.FullName);
                Log.Error(TAG, "\t\t --faceFile.FullName: " + faceFile.FullName);

                //save tesseract data path
                ISharedPreferencesEditor editor = preference.Edit();
                editor.PutString("cascade-data-version", appVersion);
                editor.PutString("cascade-eye-data-path", eyeFile.FullName);
                editor.PutString("cascade-face-data-path", faceFile.FullName);
                editor.Commit();
            }

            eyeXml  = preference.GetString("cascade-eye-data-path", null);
            faceXml = preference.GetString("cascade-face-data-path", null);

            Log.Error(TAG, "\t\t --eyeXml: " + eyeXml);
            Log.Error(TAG, "\t\t --faceXml: " + faceXml);

            //face = new CascadeClassifier(faceXml);
            //eye = new CascadeClassifier(eyeXml);

            // Hide the window title and go fullscreen.
            RequestWindowFeature(WindowFeatures.NoTitle);
            Window.AddFlags(WindowManagerFlags.Fullscreen);

            SetContentView(Resource.Layout.take_photo_surface_view);
            mTextureView     = (AutoFitTextureView)FindViewById(Resource.Id.CameraView);
            mTransparentView = (SurfaceView)FindViewById(Resource.Id.TransparentView);

            mTransparentView.SetZOrderOnTop(true);
            mTransparentView.BringToFront();

            mTransparentView.Holder.SetFormat(Android.Graphics.Format.Transparent);
            mTransparentView.Holder.AddCallback(this);

            var manager = GetSystemService(Context.WindowService).JavaCast <IWindowManager>();
            var size    = new Android.Graphics.Point();

            manager.DefaultDisplay.GetSize(size);

            screenX = size.X / 2;
            screenY = size.Y / 2;

            L = screenX - 200;
            T = screenY - 200;
            R = screenX + 200;
            B = screenY + 200;

            mStateCallback = new CameraStateListener()
            {
                owner = this
            };
            mSurfaceTextureListener   = new Camera2BasicSurfaceTextureListener(this);
            mOnImageAvailableListener = new ImageAvailableListener()
            {
                Owner = this
            };

            // 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);
        }