UNPKG

capacitor-plugin-scanbot-sdk

Version:

Scanbot Document and Barcode Scanner SDK for Capacitor

222 lines (213 loc) 8.87 kB
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten. /// Generated from core/schemas/DocumentQualityAnalyzerTypes.yaml import { ImageRef } from '../imageRef/image'; import { ToJsonConfiguration } from '../utils/json/JsonSerializationTypes'; import { PartiallyConstructible } from '../utils/utils'; export const DocumentQualityValues = ['VERY_POOR', 'POOR', 'REASONABLE', 'GOOD', 'EXCELLENT']; /** Point in the quality-number of symbols space to separate quality levels. */ export class DocumentQualityThreshold extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<DocumentQualityThreshold>`} */ constructor(source = {}) { super(); if (source.symbolQuality !== undefined) { this.symbolQuality = source.symbolQuality; } else { throw new Error('symbolQuality must be present in constructor argument'); } if (source.symbolRatio !== undefined) { this.symbolRatio = source.symbolRatio; } else { throw new Error('symbolRatio must be present in constructor argument'); } } } /** Document Quality Analyzer configuration. */ export class DocumentQualityAnalyzerConfiguration extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<DocumentQualityAnalyzerConfiguration>`} */ constructor(source = {}) { super(); /** Quality thresholds to separate quality levels. */ this.qualityThresholds = [ new DocumentQualityThreshold({ symbolQuality: 0.5, symbolRatio: 0.5 }), new DocumentQualityThreshold({ symbolQuality: 0.7, symbolRatio: 0.3 }), new DocumentQualityThreshold({ symbolQuality: 0.85, symbolRatio: 0.3 }), new DocumentQualityThreshold({ symbolQuality: 0.9, symbolRatio: 0.1 }), ]; /** quality levels. */ this.qualityIndices = ['VERY_POOR', 'POOR', 'REASONABLE', 'GOOD', 'EXCELLENT']; /** Enable orientation detection. Document orientation will be returned in `DocumentQualityAnalyzerResult.orientation`. Default is false */ this.detectOrientation = false; /** Inspect small text (typically less than 12 pixels height) when analyzing the document quality. If true, processing will be slower, but when the quality issue with a document is the low resolution of the text, then the issue will be caught. Default is false */ this.inspectSmallText = false; /** Maximum image size in pixels, if image is bigger, it will be resized. Default is 2000 */ this.maxImageSize = 2000; /** If estimated number of symbols is less than this value, return that document is not found. Default is 20 */ this.minEstimatedNumberOfSymbolsForDocument = 20; /** At least this fraction of the image will be processed, range is from 0 to 1. Default is 0 */ this.minProcessedFraction = 0.0; /** At most this fraction of the image will be processed, range is from 0 to 1. Default is 0.5 */ this.maxProcessedFraction = 0.5; /** If this number of symbols is found and minProcessedFraction of the image is processed, the processing stops. Default is 100 */ this.earlyStopIfNSymbolsFound = 100; /** Image will be processed in tiles of this size; will be ignored if image is small. Default is 300 */ this.tileSize = 300; /** If true, will return the quality heatmap as a part of the result. In this case, the entire image will be processed and the minProcessedFraction will be ignored. Useful for debugging situations where the returned quality doesn't appear to match the perceived quality. Default is false */ this.returnQualityHeatmap = false; if (source.qualityThresholds !== undefined) { this.qualityThresholds = source.qualityThresholds.map((it) => { return new DocumentQualityThreshold(it); }); } if (source.qualityIndices !== undefined) { this.qualityIndices = source.qualityIndices.map((it) => { return it; }); } if (source.detectOrientation !== undefined) { this.detectOrientation = source.detectOrientation; } if (source.inspectSmallText !== undefined) { this.inspectSmallText = source.inspectSmallText; } if (source.maxImageSize !== undefined) { this.maxImageSize = source.maxImageSize; } if (source.minEstimatedNumberOfSymbolsForDocument !== undefined) { this.minEstimatedNumberOfSymbolsForDocument = source.minEstimatedNumberOfSymbolsForDocument; } if (source.minProcessedFraction !== undefined) { this.minProcessedFraction = source.minProcessedFraction; } if (source.maxProcessedFraction !== undefined) { this.maxProcessedFraction = source.maxProcessedFraction; } if (source.earlyStopIfNSymbolsFound !== undefined) { this.earlyStopIfNSymbolsFound = source.earlyStopIfNSymbolsFound; } if (source.tileSize !== undefined) { this.tileSize = source.tileSize; } if (source.returnQualityHeatmap !== undefined) { this.returnQualityHeatmap = source.returnQualityHeatmap; } } } /** Result of document quality analysis. It can be used to determine, e.g., if a document is good enough to be used for OCR processing. */ export class DocumentQualityAnalyzerResult extends PartiallyConstructible { /** @param source {@displayType `DeepPartial<DocumentQualityAnalyzerResult>`} */ constructor(source = {}) { super(); /** Quality heatmap. Black marks areas of no detected text. Colors represent the quality of detected text, with red meaning the lowest quality and yellow and green meaning progressively higher quality. */ this.qualityHeatmap = null; this._released = false; if (source.documentFound !== undefined) { this.documentFound = source.documentFound; } else { throw new Error('documentFound must be present in constructor argument'); } if (source.quality !== undefined) { this.quality = source.quality != null ? (DocumentQualityValues.includes(source.quality) ? source.quality : null) : null; } else { throw new Error('quality must be present in constructor argument'); } if (source.orientation !== undefined) { this.orientation = source.orientation != null ? source.orientation : null; } else { throw new Error('orientation must be present in constructor argument'); } if (source.cumulativeQualityHistogram !== undefined) { this.cumulativeQualityHistogram = source.cumulativeQualityHistogram.map((it) => { return it; }); } else { throw new Error('cumulativeQualityHistogram must be present in constructor argument'); } if (source.qualityHeatmap !== undefined) { this.qualityHeatmap = source.qualityHeatmap != null ? ImageRef.From(source.qualityHeatmap) : null; } } async serialize(config = new ToJsonConfiguration()) { return { documentFound: this.documentFound, quality: this.quality != null ? this.quality : null, orientation: this.orientation != null ? this.orientation : null, cumulativeQualityHistogram: this.cumulativeQualityHistogram.map((it) => { return it; }), qualityHeatmap: config.serializeImages ? this.qualityHeatmap != null ? await this.qualityHeatmap.serialize(config.imageSerializationMode) : null : undefined, }; } release() { if (this._released) { return; } { if (this.qualityHeatmap != null) { this.qualityHeatmap.release(); } } this._released = true; } async encodeImages() { if (this.qualityHeatmap != null) { await this.qualityHeatmap.encodeInPlace(); } } } //# sourceMappingURL=DocumentQualityAnalyzerTypes.js.map