Example #1
0
        private void findView()
        {
            textureViewOne = (TextureView)FindViewById(Resource.Id.texture_view_one);
            textureViewOne.SetOpaque(false);
            textureView = (TextureView)FindViewById(Resource.Id.texture_view);
            textureView.SetOpaque(false);
            surface_one          = (SurfaceView)FindViewById(Resource.Id.surface_one);
            surface_two          = (SurfaceView)FindViewById(Resource.Id.surface_two);
            tipTv                = (TextView)FindViewById(Resource.Id.tip_tv);
            detectDurationTv     = (TextView)FindViewById(Resource.Id.detect_duration_tv);
            rgbLivenssDurationTv = (TextView)FindViewById(Resource.Id.rgb_liveness_duration_tv);
            rgbLivenessScoreTv   = (TextView)FindViewById(Resource.Id.rgb_liveness_score_tv);
            irLivenssDurationTv  = (TextView)FindViewById(Resource.Id.ir_liveness_duration_tv);
            irLivenessScoreTv    = (TextView)FindViewById(Resource.Id.ir_liveness_score_tv);

            detectDurationTv     = (TextView)FindViewById(Resource.Id.detect_duration_tv);
            rgbLivenssDurationTv = (TextView)FindViewById(Resource.Id.rgb_liveness_duration_tv);
            rgbLivenessScoreTv   = (TextView)FindViewById(Resource.Id.rgb_liveness_score_tv);
            irLivenssDurationTv  = (TextView)FindViewById(Resource.Id.ir_liveness_duration_tv);
            irLivenessScoreTv    = (TextView)FindViewById(Resource.Id.ir_liveness_score_tv);
            tvAttr = (TextView)FindViewById(Resource.Id.action_bar_root);//待修改

            mCameraNum = Android.Hardware.Camera.NumberOfCameras;

            testIv = (ImageView)FindViewById(Resource.Id.test_iv);

            if (mCameraNum != 2)
            {
                Toast.MakeText(this, "未检测到2个摄像头", ToastLength.Long).Show();
                return;
            }
            else
            {
                SurfaceView[] surfaViews = new SurfaceView[mCameraNum];
                mPreview    = new Preview[mCameraNum];
                mCamera     = new Android.Hardware.Camera[mCameraNum];
                mPreview[0] = new Preview(this, surface_one);
                mPreview[1] = new Preview(this, surface_two);
            }


            //        for (int i = 0; i < mCameraNum; i++) {
            //            surfaViews[i] = new SurfaceView(this);
            //            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
            //                    LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
            //            // lp.setMargins(10, 10, 10, 10);
            //            surfaViews[i].setLayoutParams(lp);
            //            ((LinearLayout) FindViewById(Resource.Id.camera_layout)).addView(surfaViews[i]);
            //
            //            mPreview[i] = new Preview(this, surfaViews[i]);
            //            mPreview[i].setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            //            ((RelativeLayout) FindViewById(Resource.Id.layout)).addView(mPreview[i]);
            //        }
        }
        private void init()
        {
            Intent intent = getIntent();

            if (intent != null)
            {
                groupId = intent.GetStringExtra("group_id");
            }

            faceDetectManager = new FaceDetectManager(this);
            // 从系统相机获取图片帧。
            CameraImageSource cameraImageSource = new CameraImageSource(this);

            // 图片越小检测速度越快,闸机场景640 * 480 可以满足需求。实际预览值可能和该值不同。和相机所支持的预览尺寸有关。
            // 可以通过 camera.getParameters().getSupportedPreviewSizes()查看支持列表。
            cameraImageSource.getCameraControl().setPreferredPreviewSize(1280, 720);
            // cameraImageSource.getCameraControl().setPreferredPreviewSize(640, 480);

            // 设置最小人脸,该值越小,检测距离越远,该值越大,检测性能越好。范围为80-200
            FaceSDKManager.getInstance().getFaceDetector().MinFaceSize = (100);
            // FaceSDKManager.getInstance().getFaceDetector().setNumberOfThreads(4);
            // 设置预览
            cameraImageSource.setPreviewView(previewView);
            // 设置图片源
            faceDetectManager.setImageSource(cameraImageSource);
            // 设置人脸过滤角度,角度越小,人脸越正,比对时分数越高
            faceDetectManager.getFaceFilter().setAngle(20);

            textureView.SetOpaque(false);
            // 不需要屏幕自动变黑。
            textureView.setKeepScreenOn(true);

            bool isPortrait = Resources.Configuration.Orientation == Android.Content.Res.Orientation.Portrait;

            if (isPortrait)
            {
                previewView.setScaleType(ScaleType.FIT_WIDTH);
                // 相机坚屏模式
                cameraImageSource.getCameraControl().setDisplayOrientation(CameraView.ORIENTATION_PORTRAIT);
            }
            else
            {
                previewView.setScaleType(ScaleType.FIT_HEIGHT);
                // 相机横屏模式
                cameraImageSource.getCameraControl().setDisplayOrientation(CameraView.ORIENTATION_HORIZONTAL);
            }

            setCameraType(cameraImageSource);
        }
Example #3
0
        private void init()
        {
            faceDetectManager = new FaceDetectManager(this);
            // 从系统相机获取图片帧。
            CameraImageSource cameraImageSource = new CameraImageSource(this);

            // 图片越小检测速度越快,闸机场景640 * 480 可以满足需求。实际预览值可能和该值不同。和相机所支持的预览尺寸有关。
            // 可以通过 camera.getParameters().getSupportedPreviewSizes()查看支持列表。
            cameraImageSource.getCameraControl().setPreferredPreviewSize(1280, 720);

            // 设置最小人脸,该值越小,检测距离越远,该值越大,检测性能越好。范围为80-200

            previewView.setMirrored(false);
            // 设置预览
            cameraImageSource.setPreviewView(previewView);
            // 设置图片源
            faceDetectManager.setImageSource(cameraImageSource);
            faceDetectManager.setUseDetect(true);
            textureView.SetOpaque(false);

            // 不需要屏幕自动变黑。
            textureView.KeepScreenOn = true;
            bool isPortrait = Resources.Configuration.Orientation == Android.Content.Res.Orientation.Portrait;

            if (isPortrait)
            {
                previewView.setScaleType(ScaleType.FIT_WIDTH);
                // 相机坚屏模式
                cameraImageSource.getCameraControl().setDisplayOrientation(0);
            }
            else
            {
                previewView.setScaleType(ScaleType.FIT_HEIGHT);
                // 相机横屏模式
                cameraImageSource.getCameraControl().setDisplayOrientation(1);
            }

            setCameraType(cameraImageSource);
        }
Example #4
0
        protected override void OnResume()
        {
            base.OnResume();
            if (mCameraNum != 2)
            {
                Toast.MakeText(this, "未检测到2个摄像头", ToastLength.Long).Show();
                return;
            }
            else
            {
                try
                {
                    mCamera[0] = Android.Hardware.Camera.Open(0);
                    mCamera[1] = Android.Hardware.Camera.Open(1);
                    mPreview[0].setCamera(mCamera[0], PREFER_WIDTH, PERFER_HEIGH);
                    mPreview[1].setCamera(mCamera[1], PREFER_WIDTH, PERFER_HEIGH);
                    //    mCamera[0].setPreviewCallback(new Camera.PreviewCallback() {
                    //    @Override
                    //    public void onPreviewFrame(byte[] data, Camera camera)
                    //    {
                    //        if (rgbOrIrConfirm)
                    //        {
                    //            choiceRgbOrIrType(0, data);
                    //        }
                    //        else if (camemra1DataMean == 0)
                    //        {
                    //            rgbOrIr(0, data);
                    //        }
                    //    }
                    //});
                    //    mCamera[1].setPreviewCallback(new Camera.PreviewCallback() {
                    //        @Override
                    //        public void onPreviewFrame(byte[] data, Camera camera)
                    //    {
                    //        if (rgbOrIrConfirm)
                    //        {
                    //            choiceRgbOrIrType(1, data);
                    //        }
                    //        else if (camemra2DataMean == 0)
                    //        {
                    //            rgbOrIr(1, data);
                    //        }

                    //    }
                    //});
                }
                catch (RuntimeException e)
                {
                    Log.Error(TAG, e.Message);
                }
            }

            if (textureView != null)
            {
                textureView.SetOpaque(false);
            }
            if (textureViewOne != null)
            {
                textureViewOne.SetOpaque(false);
            }
        }