【问题标题】:How to auto capture image using device camera in xamarin forms如何使用 xamarin 表单中的设备摄像头自动捕获图像
【发布时间】:2018-08-14 14:23:35
【问题描述】:

我正在尝试在我的 xamarin 应用程序中实现人脸检测以进行身份​​验证。我想在没有用户交互的情况下自动捕获图像,我可以使用捕获按钮捕获图像,但我的要求是图像捕获应该是自动的,请帮助我实现这一点。

【问题讨论】:

  • Vision Framework 是 iOS 11 的新成员,如果您只是在较新的手机上需要它,您可以使用它。对于 Android,我推荐Google Vision Api。您也可以使用类似 Microsoft 的服务。

标签: xaml xamarin xamarin.forms xamarin.ios xamarin.android


【解决方案1】:

要做到这一点有 2 个部分。您需要打开一个相机活动:

关于这个有多个tutorials

安卓

App.Instance.ShouldTakePicture += () => {
   var intent = new Intent(MediaStore.ActionImageCapture);
   intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(file));
   StartActivityForResult(intent, 0);
};

IOS

imagePicker.FinishedPickingMedia += (sender, e) => {
            var filepath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "tmp.png");
var image = (UIImage)e.Info.ObjectForKey(new NSString("UIImagePickerControllerOriginalImage"));
            InvokeOnMainThread(() => {
                image.AsPNG().Save(filepath, false);
                App.Instance.ShowImage(filepath);
            });
            DismissViewController(true, null);
        };

下一步是使用facial recognition,一旦你有了用户的脸,你就可以存储图像了。

using (var stream = photo.GetStream())
{
    var faceServiceClient = new FaceServiceClient("{FACE_API_SUBSCRIPTION_KEY}");

    // Step 4a - Detect the faces in this photo.
    var faces = await faceServiceClient.DetectAsync(stream);
    var faceIds = faces.Select(face => face.FaceId).ToArray();

    // Step 4b - Identify the person in the photo, based on the face.
    var results = await faceServiceClient.IdentifyAsync(personGroupId, faceIds);
    var result = results[0].Candidates[0].PersonId;

    // Step 4c - Fetch the person from the PersonId and display their name.
    var person = await faceServiceClient.GetPersonAsync(personGroupId, result);
    UserDialogs.Instance.ShowSuccess($"Person identified is {person.Name}.");
}

【讨论】:

    猜你喜欢
    • 2021-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-31
    • 2010-11-23
    相关资源
    最近更新 更多