UNPKG

react-native-scanbot-sdk

Version:

Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS

528 lines (489 loc) 18.5 kB
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten. /// Generated from core/schemas/BarcodeScannerTypes.yaml import { BarcodeFormatCommonConfiguration, BarcodeFormatConfigurationBase, } from '../barcode/BarcodeConfigurationTypes'; import { BarcodeDocumentFormat } from '../barcode/BarcodeDocumentTypes'; import { BarcodeFormat, RangeEncoding, StructuredAppendInfo } from '../barcode/BarcodeTypes'; import { GenericDocument } from '../documents/GenericDocument'; import { ImageRef } from '../imageRef/image'; import { ToJsonConfiguration } from '../utils/json/JsonSerializationTypes'; import { DeepPartial, PartiallyConstructible, Point } from '../utils/utils'; /** A single barcode found in the input image. Barcodes with the same content but different locations in the image are considered separate barcodes. */ export class BarcodeItem extends PartiallyConstructible { /** Text contained in the barcode. Binary data is returned in the rawBytes field only. */ public readonly text: string; /** Raw bytes of barcode contents. Some barcode formats are able to encode binary data. If a barcode contains binary data, it's provided as a list of bytes in the rawBytes field. Some barcode formats additionally allow pieces of the data within to have different encodings - UTF-8, ASCII, binary, etc. The rawBytesEncodings field lists the encoding of each range in the rawBytes array. For barcode formats that contain a GS1 message (e.g. GS1 Composite), we recommend to use a GS1Handling and extract the GS1 message from the text. */ public readonly rawBytes: string; /** Encoding information for the rawBytes field. Each element of this list covers some portion of the rawBytes array. Taken together, the elements of the list cover the entirety of the rawBytes array without overlap and without holes. The elements are ordered in increasing order of the start and end indices. */ public readonly rawBytesEncodings: RangeEncoding[]; /** If this barcode is part of a structured append sequence, this field contains information about the sequence. */ public readonly structuredAppendInfo: StructuredAppendInfo | null; /** Barcode format. Default is NONE */ public readonly format: BarcodeFormat = 'NONE'; /** The four corners of the barcode in the input image, in clockwise order starting from the top left, in image coordinates. */ public readonly quad: Point[]; /** The four corners of the barcode in the input image, in clockwise order starting from the top left, normalized to the range [0, 1]. */ public readonly quadNormalized: Point[]; /** As quad, but extended to appropriate height for oned barcodes. */ public readonly extendedQuad: Point[]; /** As quadNormalized, but extended to appropriate height for oned barcodes. */ public readonly extendedQuadNormalized: Point[]; /** True if this is a 1D barcode that is printed upside-down, that is, the barcode was scanned right-to-left. Default is false */ public readonly isUpsideDown: boolean = false; /** A crop from the input image containing the barcode. */ public readonly sourceImage: ImageRef | null = null; /** If this is a UPC/EAN barcode that has an EAN-2 or EAN-5 extension, this field contains the extension value. Requires the UPC_EAN_EXTENSION format to be enabled in the decoding options. */ public readonly upcEanExtension: string; /** True if the barcode contains a GS1 message. Requires GS1 handling to be enabled in the decoding option. Default is false */ public readonly isGS1Message: boolean = false; /** True if this result is the 2D part of a GS1 Composite barcode. Can only happen if GS1_COMPOSITE scanning is disabled and a part of the composite (1D) or (2D) is scanned separately. When GS1_COMPOSITE scanning is enabled, parts of the composite barcode are never returned separately, even if their respective format is enabled in the decoding options. Default is false */ public readonly isGS1CompositePart: boolean = false; /** The number of 1D stacks in the barcode. Applies only to DATABAR and DATABAR_EXPANDED barcodes. Default is 1 */ public readonly dataBarStackSize: number = 1; /** The size score is a floating point value between 0 and 1 that represents the relative size of the barcode in the input image. Barcodes taking up a small portion of the input image will have a score close to 0, while barcodes that take a large portion will have a score close to 1. Default is 0 */ public readonly sizeScore: number = 0.0; /** The parsed known document format (if parsed successfully). */ public readonly extractedDocument: GenericDocument | null; /** The index of the barcode to uniquely identify it. In case of frame accumulation, the index remains the same across frames. Default is -1 */ public readonly globalIndex: number = -1; /** @param source {@displayType `DeepPartial<BarcodeItem>`} */ public constructor(source: DeepPartial<BarcodeItem> = {}) { super(); if (source.text !== undefined) { this.text = source.text; } else { throw new Error('text must be present in constructor argument'); } if (source.rawBytes !== undefined) { this.rawBytes = source.rawBytes; } else { throw new Error('rawBytes must be present in constructor argument'); } if (source.rawBytesEncodings !== undefined) { this.rawBytesEncodings = source.rawBytesEncodings.map((it: any) => { return new RangeEncoding(it); }); } else { throw new Error('rawBytesEncodings must be present in constructor argument'); } if (source.structuredAppendInfo !== undefined) { this.structuredAppendInfo = source.structuredAppendInfo != null ? new StructuredAppendInfo(source.structuredAppendInfo) : null; } else { throw new Error('structuredAppendInfo must be present in constructor argument'); } if (source.format !== undefined) { this.format = source.format; } if (source.quad !== undefined) { this.quad = source.quad.map((it: any) => { return { x: it.x, y: it.y }; }); } else { throw new Error('quad must be present in constructor argument'); } if (source.quadNormalized !== undefined) { this.quadNormalized = source.quadNormalized.map((it: any) => { return { x: it.x, y: it.y }; }); } else { throw new Error('quadNormalized must be present in constructor argument'); } if (source.extendedQuad !== undefined) { this.extendedQuad = source.extendedQuad.map((it: any) => { return { x: it.x, y: it.y }; }); } else { throw new Error('extendedQuad must be present in constructor argument'); } if (source.extendedQuadNormalized !== undefined) { this.extendedQuadNormalized = source.extendedQuadNormalized.map((it: any) => { return { x: it.x, y: it.y }; }); } else { throw new Error('extendedQuadNormalized must be present in constructor argument'); } if (source.isUpsideDown !== undefined) { this.isUpsideDown = source.isUpsideDown; } if (source.sourceImage !== undefined) { this.sourceImage = source.sourceImage != null ? ImageRef.From(source.sourceImage) : null; } if (source.upcEanExtension !== undefined) { this.upcEanExtension = source.upcEanExtension; } else { throw new Error('upcEanExtension must be present in constructor argument'); } if (source.isGS1Message !== undefined) { this.isGS1Message = source.isGS1Message; } if (source.isGS1CompositePart !== undefined) { this.isGS1CompositePart = source.isGS1CompositePart; } if (source.dataBarStackSize !== undefined) { this.dataBarStackSize = source.dataBarStackSize; } if (source.sizeScore !== undefined) { this.sizeScore = source.sizeScore; } if (source.extractedDocument !== undefined) { this.extractedDocument = source.extractedDocument != null ? new GenericDocument(source.extractedDocument) : null; } else { throw new Error('extractedDocument must be present in constructor argument'); } if (source.globalIndex !== undefined) { this.globalIndex = source.globalIndex; } } public async serialize( config: ToJsonConfiguration = new ToJsonConfiguration() ): Promise<DeepPartial<BarcodeItem>> { return { text: this.text, rawBytes: this.rawBytes, rawBytesEncodings: this.rawBytesEncodings.map((it: any) => { return it.serialize(config); }), structuredAppendInfo: this.structuredAppendInfo != null ? this.structuredAppendInfo.serialize(config) : null, format: this.format, quad: this.quad.map((it: any) => { return it; }), quadNormalized: this.quadNormalized.map((it: any) => { return it; }), extendedQuad: this.extendedQuad.map((it: any) => { return it; }), extendedQuadNormalized: this.extendedQuadNormalized.map((it: any) => { return it; }), isUpsideDown: this.isUpsideDown, sourceImage: config.serializeImages ? this.sourceImage != null ? await this.sourceImage.serialize(config.imageSerializationMode) : null : undefined, upcEanExtension: this.upcEanExtension, isGS1Message: this.isGS1Message, isGS1CompositePart: this.isGS1CompositePart, dataBarStackSize: this.dataBarStackSize, sizeScore: this.sizeScore, extractedDocument: this.extractedDocument != null ? await this.extractedDocument.serialize(config) : null, globalIndex: this.globalIndex, }; } private _released: Boolean = false; public release() { if (this._released) { return; } { if (this.sourceImage != null) { this.sourceImage.release(); } } { if (this.extractedDocument != null) { this.extractedDocument.release(); } } this._released = true; } public async encodeImages(): Promise<void> { if (this.sourceImage != null) { await this.sourceImage.encodeInPlace(); } if (this.extractedDocument != null) { await this.extractedDocument.encodeImages(); } } } /** The engine mode for barcode scanning. - `LEGACY`: Legacy mode. Very fast, significantly less accurate. Doesn't support all barcode types. - `NEXT_GEN_LOW_POWER`: A faster version of the main engine mode, for use with low-power devices. - `NEXT_GEN`: Main engine mode for high-power devices. Supports all barcodes types. - `NEXT_GEN_LOW_POWER_FAR_DISTANCE`: Similar to NEXT_GEN_LOW_POWER, but optimized for scanning from far distances. - `NEXT_GEN_FAR_DISTANCE`: Similar to NEXT_GEN, but optimized for scanning from far distances. */ export type BarcodeScannerEngineMode = | 'LEGACY' | 'NEXT_GEN_LOW_POWER' | 'NEXT_GEN' | 'NEXT_GEN_LOW_POWER_FAR_DISTANCE' | 'NEXT_GEN_FAR_DISTANCE'; export const BarcodeScannerEngineModeValues: BarcodeScannerEngineMode[] = [ 'LEGACY', 'NEXT_GEN_LOW_POWER', 'NEXT_GEN', 'NEXT_GEN_LOW_POWER_FAR_DISTANCE', 'NEXT_GEN_FAR_DISTANCE', ]; /** The method how to display barcodes from previous frames. - `LAST_VISIBLE`: The quad of a barcode is simply given as the last quad when it was detected. - `INTERPOLATE_BY_CAMERA`: The quad of barcode is interpolated by the camera movement. This option is recommended when the camera is moving, but the scanned object is not. */ export type BarcodeAccumulationMethod = 'LAST_VISIBLE' | 'INTERPOLATE_BY_CAMERA'; export const BarcodeAccumulationMethodValues: BarcodeAccumulationMethod[] = [ 'LAST_VISIBLE', 'INTERPOLATE_BY_CAMERA', ]; /** Configuration for how to accumulate results. */ export class BarcodeAccumulationConfiguration extends PartiallyConstructible { /** In case that ean/upc both with and without extensions are allowed, we require confirmations to consider a standalone EAN or UPC (i.e. without extension) as valid. Default is 1 */ public minConfirmationsStandaloneEAN: number = 1; /** The time in milliseconds to accumulate barcodes across multiple frames. Default is 500 */ public accumulationTime: number = 500; /** If true, the results from previous frames that are not connected to results on the current frame will be removed. This is should be enabled when large camera movements are expected. For small camera movements, the option can be disabled. Default is true */ public removeUnconnectedResults: boolean = true; /** The method how to display barcodes from previous frames. Default is INTERPOLATE_BY_CAMERA */ public method: BarcodeAccumulationMethod = 'INTERPOLATE_BY_CAMERA'; /** @param source {@displayType `DeepPartial<BarcodeAccumulationConfiguration>`} */ public constructor(source: DeepPartial<BarcodeAccumulationConfiguration> = {}) { super(); if (source.minConfirmationsStandaloneEAN !== undefined) { this.minConfirmationsStandaloneEAN = source.minConfirmationsStandaloneEAN; } if (source.accumulationTime !== undefined) { this.accumulationTime = source.accumulationTime; } if (source.removeUnconnectedResults !== undefined) { this.removeUnconnectedResults = source.removeUnconnectedResults; } if (source.method !== undefined) { this.method = source.method; } } } /** Configuration for the barcode scanner. */ export class BarcodeScannerConfiguration extends PartiallyConstructible { /** Options for barcode decoding. */ public barcodeFormatConfigurations: BarcodeFormatConfigurationBase[] = [ new BarcodeFormatCommonConfiguration({}), ]; /** List of document formats to be extracted. Barcodes that decode to one of the extracted document formats will have extractedDocument field in BarcodeItem populated with the parsed document. By default all supported barcode document formats are accepted. If empty, no barcodes will be parsed into documents. To only accept the document formats listed in extractedDocumentFormats, the property onlyAcceptDocuments must be true. */ public extractedDocumentFormats: BarcodeDocumentFormat[] = [ 'AAMVA', 'BOARDING_PASS', 'DE_MEDICAL_PLAN', 'MEDICAL_CERTIFICATE', 'ID_CARD_PDF_417', 'SEPA', 'SWISS_QR', 'VCARD', 'GS1', 'HIBC', ]; /** If true and extractedDocumentFormats is not empty, then barcodes that don't decode to one of the extracted document formats will be ignored. Default is false */ public onlyAcceptDocuments: boolean = false; /** If true, the barcode image will be returned in the BarcodeItem. Default is false */ public returnBarcodeImage: boolean = false; /** The engine mode for barcode scanning. Default is NEXT_GEN */ public engineMode: BarcodeScannerEngineMode = 'NEXT_GEN'; /** Configuration to accumulate barcodes across multiple frames in live mode. */ public accumulationConfig: BarcodeAccumulationConfiguration = new BarcodeAccumulationConfiguration({}); /** If true, the quads of linear (1D) barcodes will be further refined to more closely match the barcode's outline in the input image. This will also produce stabler barcode outlines across frames for use cases such as AR. Default is false */ public optimizedForOverlays: boolean = false; /** @param source {@displayType `DeepPartial<BarcodeScannerConfiguration>`} */ public constructor(source: DeepPartial<BarcodeScannerConfiguration> = {}) { super(); if (source.barcodeFormatConfigurations !== undefined) { this.barcodeFormatConfigurations = source.barcodeFormatConfigurations.map((it: any) => { return BarcodeFormatConfigurationBase.From(it); }); } if (source.extractedDocumentFormats !== undefined) { this.extractedDocumentFormats = source.extractedDocumentFormats.map((it: any) => { return it; }); } if (source.onlyAcceptDocuments !== undefined) { this.onlyAcceptDocuments = source.onlyAcceptDocuments; } if (source.returnBarcodeImage !== undefined) { this.returnBarcodeImage = source.returnBarcodeImage; } if (source.engineMode !== undefined) { this.engineMode = source.engineMode; } if (source.accumulationConfig !== undefined) { this.accumulationConfig = new BarcodeAccumulationConfiguration(source.accumulationConfig); } if (source.optimizedForOverlays !== undefined) { this.optimizedForOverlays = source.optimizedForOverlays; } } } /** The result of barcode scanning. */ export class BarcodeScannerResult extends PartiallyConstructible { /** List of found barcodes. */ public readonly barcodes: BarcodeItem[]; /** True if any barcodes were found. */ public readonly success: boolean; /** @param source {@displayType `DeepPartial<BarcodeScannerResult>`} */ public constructor(source: DeepPartial<BarcodeScannerResult> = {}) { super(); if (source.barcodes !== undefined) { this.barcodes = source.barcodes.map((it: any) => { return new BarcodeItem(it); }); } else { throw new Error('barcodes must be present in constructor argument'); } if (source.success !== undefined) { this.success = source.success; } else { throw new Error('success must be present in constructor argument'); } } public async serialize( config: ToJsonConfiguration = new ToJsonConfiguration() ): Promise<DeepPartial<BarcodeScannerResult>> { return { barcodes: await Promise.all( this.barcodes.map(async (it: any) => { return await it.serialize(config); }) ), success: this.success, }; } private _released: Boolean = false; public release() { if (this._released) { return; } this.barcodes.forEach((it) => { it.release(); }); this._released = true; } public async encodeImages(): Promise<void> { await Promise.all( this.barcodes.map(async (it) => { await it.encodeImages(); }) ); } }