Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 4ac147c

Browse files
committed
Added bounds to MLKitScanBarcodesResultBarcode
1 parent f29e768 commit 4ac147c

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

src/mlkit/barcodescanning/index.android.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImageSource } from "tns-core-modules/image-source";
2-
import { MLKitScanBarcodesOnDeviceOptions, MLKitScanBarcodesOnDeviceResult } from "./";
2+
import { MLKitScanBarcodesOnDeviceOptions, MLKitScanBarcodesOnDeviceResult, MLKitScanBarcodesResultBounds } from "./";
33
import { MLKitOptions } from "../index";
44
import { 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+
5266
function 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
}

src/mlkit/barcodescanning/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ import { MLKitResult, MLKitCameraView } from "../index";
44

55
export { 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+
718
export interface MLKitScanBarcodesResultBarcode {
819
value: string;
920
format: string;
1021
ios?: any;
1122
android?: any;
23+
bounds?: MLKitScanBarcodesResultBounds;
1224
// TODO details
1325
}
1426

src/mlkit/barcodescanning/index.ios.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)