react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
275 lines (251 loc) • 9.1 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DocumentQualityValues = exports.DocumentQualityThreshold = exports.DocumentQualityAnalyzerResult = exports.DocumentQualityAnalyzerConfiguration = void 0;
var _image = require("../imageRef/image");
var _JsonSerializationTypes = require("../utils/json/JsonSerializationTypes");
var _utils = require("../utils/utils");
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten.
/// Generated from core/schemas/DocumentQualityAnalyzerTypes.yaml
/**
Result of document quality analysis.
- `VERY_POOR`:
Very poor quality.
- `POOR`:
Poor quality.
- `REASONABLE`:
Reasonable quality.
- `GOOD`:
Good quality.
- `EXCELLENT`:
Excellent quality.
*/
const DocumentQualityValues = exports.DocumentQualityValues = ['VERY_POOR', 'POOR', 'REASONABLE', 'GOOD', 'EXCELLENT'];
/**
Point in the quality-number of symbols space to separate quality levels.
*/
class DocumentQualityThreshold extends _utils.PartiallyConstructible {
/**
Symbol quality.
*/
/**
Symbol ratio.
*/
/** @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.
*/
exports.DocumentQualityThreshold = DocumentQualityThreshold;
class DocumentQualityAnalyzerConfiguration extends _utils.PartiallyConstructible {
/**
Quality thresholds to separate quality levels.
*/
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.
*/
qualityIndices = ['VERY_POOR', 'POOR', 'REASONABLE', 'GOOD', 'EXCELLENT'];
/**
Enable orientation detection. Document orientation will be returned in `DocumentQualityAnalyzerResult.orientation`.
Default is false
*/
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
*/
inspectSmallText = false;
/**
Maximum image size in pixels, if image is bigger, it will be resized.
Default is 2000
*/
maxImageSize = 2000;
/**
If estimated number of symbols is less than this value, return that document is not found.
Default is 20
*/
minEstimatedNumberOfSymbolsForDocument = 20;
/**
At least this fraction of the image will be processed, range is from 0 to 1.
Default is 0
*/
minProcessedFraction = 0.0;
/**
At most this fraction of the image will be processed, range is from 0 to 1.
Default is 0.5
*/
maxProcessedFraction = 0.5;
/**
If this number of symbols is found and minProcessedFraction of the image is processed, the processing stops.
Default is 100
*/
earlyStopIfNSymbolsFound = 100;
/**
Image will be processed in tiles of this size; will be ignored if image is small.
Default is 300
*/
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
*/
returnQualityHeatmap = false;
/** @param source {@displayType `DeepPartial<DocumentQualityAnalyzerConfiguration>`} */
constructor(source = {}) {
super();
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.
*/
exports.DocumentQualityAnalyzerConfiguration = DocumentQualityAnalyzerConfiguration;
class DocumentQualityAnalyzerResult extends _utils.PartiallyConstructible {
/**
True if a document was found.
*/
/**
Quality of the document, if found.
*/
/**
Dominant orientation of the document, if found and if orientation detection is enabled.
The value is in degrees counter-clockwise, where 0 corresponds to the document
being straight, and the value is in the range of [-180, 180].
To rotate the document to be straight, rotate the image clockwise by this value.
*/
/**
Cumulative histogram where every entry is equal to the number of symbols with quality equal or lower than N percent, where N is the index of the entry in the array.
*/
/**
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.
*/
qualityHeatmap = null;
/** @param source {@displayType `DeepPartial<DocumentQualityAnalyzerResult>`} */
constructor(source = {}) {
super();
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 ? _image.ImageRef.From(source.qualityHeatmap) : null;
}
}
async serialize(config = new _JsonSerializationTypes.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
};
}
_released = false;
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();
}
}
}
exports.DocumentQualityAnalyzerResult = DocumentQualityAnalyzerResult;
//# sourceMappingURL=DocumentQualityAnalyzerTypes.js.map