public CaptureVideoDelegate() { metadata = new VisionImageMetadata(); vision = VisionApi.Create(); barcodeDetector = vision.GetBarcodeDetector(Configuration.BarcodeDetectorSupportFormat); // Using back-facing camera var devicePosition = AVCaptureDevicePosition.Back; var deviceOrientation = UIDevice.CurrentDevice.Orientation; switch (deviceOrientation) { case UIDeviceOrientation.Portrait: metadata.Orientation = devicePosition == AVCaptureDevicePosition.Front ? VisionDetectorImageOrientation.LeftTop : VisionDetectorImageOrientation.RightTop; break; case UIDeviceOrientation.LandscapeLeft: metadata.Orientation = devicePosition == AVCaptureDevicePosition.Front ? VisionDetectorImageOrientation.BottomLeft : VisionDetectorImageOrientation.TopLeft; break; case UIDeviceOrientation.PortraitUpsideDown: metadata.Orientation = devicePosition == AVCaptureDevicePosition.Front ? VisionDetectorImageOrientation.RightBottom : VisionDetectorImageOrientation.LeftBottom; break; case UIDeviceOrientation.LandscapeRight: metadata.Orientation = devicePosition == AVCaptureDevicePosition.Front ? VisionDetectorImageOrientation.TopRight : VisionDetectorImageOrientation.BottomRight; break; case UIDeviceOrientation.FaceUp: case UIDeviceOrientation.FaceDown: case UIDeviceOrientation.Unknown: metadata.Orientation = VisionDetectorImageOrientation.LeftTop; break; } }
public static async Task <List <BarcodeResult> > ScanFromImage(byte[] imageArray) { UIImage image = new UIImage(NSData.FromArray(imageArray)); var visionImage = new VisionImage(image); VisionImageMetadata metadata = new VisionImageMetadata(); VisionApi vision = VisionApi.Create(); VisionBarcodeDetector barcodeDetector = vision.GetBarcodeDetector(Configuration.BarcodeDetectorSupportFormat); VisionBarcode[] barcodes = await barcodeDetector.DetectAsync(visionImage); if (barcodes == null || barcodes.Length == 0) { return(new List <BarcodeResult>()); } List <BarcodeResult> resultList = new List <BarcodeResult>(); foreach (var barcode in barcodes) { resultList.Add(new BarcodeResult { BarcodeType = Methods.ConvertBarcodeResultTypes(barcode.ValueType), DisplayValue = barcode.DisplayValue, RawValue = barcode.RawValue }); } return(resultList); }
void AnalizeImage() { vision = VisionApi.Create(); switch (currentModelName.ToString()) { case nameof(Model.TextRecognition): UseTextRecognitionModel(); break; case nameof(Model.FaceDetection): UseFaceDetectionModel(); break; case nameof(Model.BarcodeScanning): UseBarcodeScanningModel(); break; case nameof(Model.LandmarkRecognition): UseLandmarkRecognitionModel(); break; default: TxtData.Text = "Model not supported"; break; } }
public static async Task <List <BarcodeResult> > ScanFromImage(byte[] imageArray) { UIImage image = new UIImage(NSData.FromArray(imageArray)); var visionImage = new VisionImage(image); VisionImageMetadata metadata = new VisionImageMetadata(); VisionApi vision = VisionApi.Create(); VisionBarcodeDetector barcodeDetector = vision.GetBarcodeDetector(Configuration.BarcodeDetectorSupportFormat); VisionBarcode[] barcodes = await barcodeDetector.DetectAsync(visionImage); if (barcodes == null || barcodes.Length == 0) { return(new List <BarcodeResult>()); } List <BarcodeResult> resultList = new List <BarcodeResult>(); foreach (var barcode in barcodes) { var points = barcode.CornerPoints.ToList().ConvertAll(nsvalue => nsvalue.PointFValue); resultList.Add(new BarcodeResult { BarcodeType = Methods.ConvertBarcodeResultTypes(barcode.ValueType), DisplayValue = barcode.DisplayValue, Points = points.Select(p => (p.X / (double)image.Size.Width, p.Y / (double)image.Size.Height)).ToList() });
/// <summary> /// <see cref="LabelReaderBase.GetFullTextFromImage(object)"/> /// </summary> /// <param name="image"></param> /// <returns></returns> public override async Task <string> GetFullTextFromImageAsync(object image) { CoreMedia.CMSampleBuffer iOSImage = (CoreMedia.CMSampleBuffer)image; VisionImage visionImage = new VisionImage(iOSImage); visionImage.Metadata = new VisionImageMetadata { Orientation = GetOrientation() }; VisionApi api = VisionApi.Create(); VisionTextRecognizer textRecognizer = api.GetOnDeviceTextRecognizer(); VisionText textResult = await textRecognizer.ProcessImageAsync(visionImage); return(textResult?.Text); }
/// <summary> /// <see cref="LabelReaderBase.GetRawBarcodeTextFromImageAsync(object)"/> /// </summary> /// <param name="image"></param> /// <returns></returns> public override async Task <string> GetRawBarcodeTextFromImageAsync(object image) { CoreMedia.CMSampleBuffer iOSImage = (CoreMedia.CMSampleBuffer)image; VisionImage visionImage = new VisionImage(iOSImage); visionImage.Metadata = new VisionImageMetadata { Orientation = GetOrientation() }; VisionApi api = VisionApi.Create(); VisionBarcodeDetector barcodeDetector = api.GetBarcodeDetector(new VisionBarcodeDetectorOptions(VisionBarcodeFormat.QRCode)); VisionBarcode[] barcodes = await barcodeDetector.DetectAsync(visionImage); if (barcodes.Length <= 0) { return(String.Empty); } return(barcodes.First().RawValue); }
void AnalizeImage() { vision = VisionApi.Create(); switch (currentModelName.ToString()) { case nameof(Model.TextRecognition): UseTextRecognitionModel(); break; case nameof(Model.FaceDetection): UseFaceDetectionModel(); break; case nameof(Model.BarcodeScanning): UseBarcodeScanningModel(); break; case nameof(Model.ImageLabeling): if (currentApiResource == ApiResource.OnDevice) { UseImageLabelingModel(); } else { UseCloudImageLabelingModel(); } break; case nameof(Model.LandmarkRecognition): UseLandmarkRecognitionModel(); break; default: TxtData.Text = "Model not supported"; break; } }