コード例 #1
0
        public void start()
        {
            base.start();
            Bitmap bitmap = getImageThumbnail(filePath, 960, 960);
            int    degree = getExifOrientation(filePath);

            if (degree == 90 || degree == 180 || degree == 270)
            {
                Matrix matrix = new Matrix();
                matrix.PostRotate(degree);
                bitmap = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);
            }

            // 文件转化为int[] argb
            int[] argb = new int[bitmap.Width * bitmap.Height];
            bitmap.GetPixels(argb, 0, bitmap.Width, 0, 0, bitmap.Width, bitmap.Height);
            FaceSDKManager.getInstance().getFaceDetector().clearTrackedFaces();

            ImageFrame frame = new ImageFrame();

            frame.setArgb(argb);
            frame.setWidth(bitmap.Width);
            frame.setHeight(bitmap.Height);

            foreach (OnFrameAvailableListener listener in getListeners())
            {
                listener.onFrameAvailable(frame);
            }

            FaceSDKManager.getInstance().getFaceDetector().clearTrackedFaces();
        }
コード例 #2
0
ファイル: MainActivity.cs プロジェクト: yulongjiang1997/app
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            imageMatchBtn       = (Button)FindViewById(Resource.Id.image_match_image_btn);
            videoMatchImageBtn  = (Button)FindViewById(Resource.Id.video_match_image_btn);
            videoIdentifyBtn    = (Button)FindViewById(Resource.Id.video_identify_faces_btn);
            userGroupManagerBtn = (Button)FindViewById(Resource.Id.user_groud_manager_btn);
            livenessSettingBtn  = (Button)FindViewById(Resource.Id.liveness_setting_btn);
            deviceActivateBtn   = (Button)FindViewById(Resource.Id.device_activate_btn);
            rgbIrBtn            = (Button)FindViewById(Resource.Id.rgb_ir_btn);
            btAttrTrack         = (Button)FindViewById(Resource.Id.bt_attr_track);
            btMultiThread       = (Button)FindViewById(Resource.Id.bt_multiThread);
            featureSettingBtn   = (Button)FindViewById(Resource.Id.feature_setting_btn);

            imageMatchBtn.SetOnClickListener(this);
            videoMatchImageBtn.SetOnClickListener(this);
            videoIdentifyBtn.SetOnClickListener(this);
            userGroupManagerBtn.SetOnClickListener(this);
            livenessSettingBtn.SetOnClickListener(this);
            deviceActivateBtn.SetOnClickListener(this);
            deviceActivateBtn.SetOnClickListener(this);
            rgbIrBtn.SetOnClickListener(this);
            btAttrTrack.SetOnClickListener(this);
            btMultiThread.SetOnClickListener(this);
            featureSettingBtn.SetOnClickListener(this);


            PreferencesUtil.initPrefs(this);
            // 使用人脸1:n时使用
            DBManager.getInstance().init(this);
            livnessTypeTip();
            //        FaceEnvironment faceEnvironment = new FaceEnvironment();
            //        // 模糊度范围 (0-1) 推荐小于0.7
            //        faceEnvironment.setBlurrinessThreshold(FaceEnvironment.VALUE_BLURNESS);
            //        // 光照范围 (0-1) 推荐大于40
            //        faceEnvironment.setIlluminationThreshold(FaceEnvironment.VALUE_BLURNESS);
            //        // 人脸yaw,pitch,row 角度,范围(-45,45),推荐-15-15
            //        faceEnvironment.setPitch(FaceEnvironment.VALUE_HEAD_PITCH);
            //        faceEnvironment.setRoll(FaceEnvironment.VALUE_HEAD_ROLL);
            //        faceEnvironment.setYaw(FaceEnvironment.VALUE_HEAD_YAW);
            //        // 最小检测人脸(在图片人脸能够被检测到最小值)80-200, 越小越耗性能,推荐120-200
            //        faceEnvironment.setMinFaceSize(FaceEnvironment.VALUE_MIN_FACE_SIZE);
            //        // 人脸置信度(0-1)推荐大于0.6
            //        faceEnvironment.setNotFaceThreshold(FaceEnvironment.VALUE_NOT_FACE_THRESHOLD);
            //        // 人脸遮挡范围 (0-1) 推荐小于0.5
            //        faceEnvironment.setOcclulationThreshold(FaceEnvironment.VALUE_OCCLUSION);
            //        // 是否进行质量检测,开启会降低性能
            //        faceEnvironment.setCheckQuality(false);
            //        FaceSDKManager.getInstance().getFaceDetector().setFaceEnvironment(faceEnvironment);
            FaceSDKManager.init(this);
            FaceSDKManager.getInstance().setSdkInitListener(new SdkInitListener());
        }
コード例 #3
0
        private static void process(int[] argb, int width, int height, ArgbPool pool)
        {
            //        if (skip) {
            //            skip = !skip;
            //            return;
            //        } else {
            //            skip = !skip;
            //        }
            int value = 0;

            ImageFrame frame = ImageSource.borrowImageFrame();

            frame.setArgb(argb);
            frame.setWidth(width);
            frame.setHeight(height);
            frame.setPool(pool);
            //        frame.retain();

            foreach (FaceProcessor processor in preProcessors)
            {
                if (processor.process(face, frame))
                {
                    break;
                }
            }
            if (UseDetect)
            {
                long starttime = DateTime.Now.Millisecond;
                value = FaceSDKManager.getInstance().getFaceDetector().detect(frame);
                // FaceSDKManager.getInstance().getFaceDetector().detectMultiFace(frame,5);
                FaceInfo[] faces = FaceSDKManager.getInstance().getFaceDetector().TrackedFaces;
                if (faces != null)
                {
                    Log.Error("faceMulti", faces.Length + "");
                }

                Log.Error("wtf", value + " process->" + (DateTime.Now.Millisecond - starttime));

                if (value == 0)
                {
                    faceFilter.filter(faces, frame);
                }
                if (Listener != null)
                {
                    Listener.onDetectFace(value, faces, frame);
                }
            }

            frame.release();
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 public void setUseDetect(bool useDetect)
 {
     UseDetect = useDetect;
     // 传给facesdk的图片高宽不同,将不能正确检出人脸,需要clear前面的trackedFaces
     FaceSDKManager.getInstance().getFaceDetector().clearTrackedFaces();
 }
コード例 #6
0
ファイル: MainActivity.cs プロジェクト: yulongjiang1997/app
        public override void OnClick(View v)
        {
            if (v == deviceActivateBtn)
            {
                if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.WriteExternalStorage) != Permission.Granted)
                {
                    ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.WriteExternalStorage }, 100);
                    return;
                }
                FaceSDKManager.showActivation();
                return;
            }

            if (FaceSDKManager.getInstance().InitStatus() == FaceSDKManager.SDK_UNACTIVATION)
            {
                toast("SDK还未激活,请先激活");
                return;
            }
            else if (FaceSDKManager.getInstance().InitStatus() == FaceSDKManager.SDK_UNINIT)
            {
                toast("SDK还未初始化完成,请先初始化");
                return;
            }
            else if (FaceSDKManager.getInstance().InitStatus() == FaceSDKManager.SDK_INITING)
            {
                toast("SDK正在初始化,请稍后再试");
                return;
            }
            if (v == imageMatchBtn)
            {
                Intent intent = new Intent(this, typeof(ImageMacthImageActivity));
                StartActivity(intent);
            }
            else if (v == videoMatchImageBtn)
            {
                if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != Permission.Granted)
                {
                    ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera }, 100);
                    return;
                }
                choiceMatchType();
            }
            else if (v == videoIdentifyBtn)
            {
                if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != Permission.Granted)
                {
                    ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera }, 100);
                    return;
                }
                showSingleAlertDialog();
            }
            else if (v == userGroupManagerBtn)
            {
                Intent intent = new Intent(this, typeof(UserGroupManagerActivity));
                StartActivity(intent);
            }
            else if (v == livenessSettingBtn)
            {
                Intent intent = new Intent(this, typeof(LivenessSettingActivity));
                StartActivity(intent);
            }
            else if (v == rgbIrBtn)
            {
                Intent intent = new Intent(this, typeof(QuestiongActivity));
                StartActivity(intent);
            }
            else if (v == btAttrTrack)
            {
                if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) != Permission.Granted)
                {
                    ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.Camera }, 100);
                    return;
                }
                choiceAttrTrackType();
            }
            else if (v == btMultiThread)
            {
                Intent intent = new Intent(this, typeof(MultiThreadActivity));
                StartActivity(intent);
                //            // 测试
                //            MultiThreadManager.getInstance().start(this);
            }
            else if (v == featureSettingBtn)
            {
                Intent intent = new Intent(this, typeof(FeatureSettingActivity));
                StartActivity(intent);
            }
        }