This repository was archived by the owner on Apr 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +34
-5
lines changed
src/mlkit/barcodescanning Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 11import { ImageSource } from "tns-core-modules/image-source" ;
2- import { MLKitScanBarcodesOnDeviceOptions , MLKitScanBarcodesOnDeviceResult } from "./" ;
2+ import { MLKitScanBarcodesOnDeviceOptions , MLKitScanBarcodesOnDeviceResult , MLKitScanBarcodesResultBounds } from "./" ;
33import { MLKitOptions } from "../index" ;
44import { BarcodeFormat , MLKitBarcodeScanner as MLKitBarcodeScannerBase } from "./barcodescanning-common" ;
55
@@ -34,7 +34,8 @@ export class MLKitBarcodeScanner extends MLKitBarcodeScannerBase {
3434 result . barcodes . push ( {
3535 value : barcode . getRawValue ( ) ,
3636 format : BarcodeFormat [ barcode . getFormat ( ) ] ,
37- android : barcode
37+ android : barcode ,
38+ bounds : boundingBoxToBounds ( barcode . getBoundingBox ( ) )
3839 } ) ;
3940 }
4041 }
@@ -49,6 +50,19 @@ export class MLKitBarcodeScanner extends MLKitBarcodeScannerBase {
4950 }
5051}
5152
53+ function boundingBoxToBounds ( rect : any ) : MLKitScanBarcodesResultBounds {
54+ return {
55+ origin : {
56+ x : rect . left ,
57+ y : rect . top
58+ } ,
59+ size : {
60+ width : rect . width ( ) ,
61+ height : rect . height ( )
62+ }
63+ }
64+ }
65+
5266function getBarcodeDetector ( formats ?: Array < BarcodeFormat > ) : any {
5367 if ( formats && formats . length > 0 ) {
5468 const firebaseVisionBarcodeDetectorOptions =
@@ -79,7 +93,8 @@ export function scanBarcodesOnDevice(options: MLKitScanBarcodesOnDeviceOptions):
7993 result . barcodes . push ( {
8094 value : barcode . getRawValue ( ) ,
8195 format : BarcodeFormat [ barcode . getFormat ( ) ] ,
82- android : barcode
96+ android : barcode ,
97+ bounds : boundingBoxToBounds ( barcode . getBoundingBox ( ) )
8398 } ) ;
8499 }
85100 }
Original file line number Diff line number Diff line change @@ -4,11 +4,23 @@ import { MLKitResult, MLKitCameraView } from "../index";
44
55export { BarcodeFormat } ;
66
7+ export interface MLKitScanBarcodesResultBounds {
8+ origin : {
9+ x : number ;
10+ y : number ;
11+ } ,
12+ size : {
13+ width : number ;
14+ height : number ;
15+ }
16+ }
17+
718export interface MLKitScanBarcodesResultBarcode {
819 value : string ;
920 format : string ;
1021 ios ?: any ;
1122 android ?: any ;
23+ bounds ?: MLKitScanBarcodesResultBounds ;
1224 // TODO details
1325}
1426
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ export class MLKitBarcodeScanner extends MLKitBarcodeScannerBase {
3232 result . barcodes . push ( {
3333 value : barcode . rawValue ,
3434 format : BarcodeFormat [ barcode . format ] ,
35- ios : barcode
35+ ios : barcode ,
36+ bounds : barcode . frame
3637 } ) ;
3738 }
3839
@@ -79,7 +80,8 @@ export function scanBarcodesOnDevice(options: MLKitScanBarcodesOnDeviceOptions):
7980 result . barcodes . push ( {
8081 value : barcode . rawValue ,
8182 format : BarcodeFormat [ barcode . format ] ,
82- ios : barcode
83+ ios : barcode ,
84+ bounds : barcode . frame
8385 } ) ;
8486 }
8587 resolve ( result ) ;
You can’t perform that action at this time.
0 commit comments