capacitor-plugin-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK for Capacitor
310 lines (300 loc) • 11.9 kB
JavaScript
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten.
/// Generated from core/schemas/DocumentScannerTypes.yaml
import { AspectRatio, LineSegmentFloat, LineSegmentInt } from '../utils/geometry/Geometry';
import { ToJsonConfiguration } from '../utils/json/JsonSerializationTypes';
import { PartiallyConstructible } from '../utils/utils';
export const DocumentScannerEngineModeValues = ['ML', 'LEGACY'];
/**
Parameters for the document scanner.
*/
export class DocumentScannerParameters extends PartiallyConstructible {
/** @param source {@displayType `DeepPartial<DocumentScannerParameters>`} */
constructor(source = {}) {
super();
/**
The minimum score in percent (0 - 100) of the perspective distortion to accept a detected document.
Set lower values to accept more perspective distortion.
Warning: Lower values result in more blurred document images.
Default is 75
*/
this.acceptedAngleScore = 75;
/**
The minimum size in percent (0 - 100) of the screen size to accept a detected document.
It is sufficient that height or width match the score.
Warning: Lower values result in low resolution document images.
Default is 80
*/
this.acceptedSizeScore = 80;
/**
The minimum brightness value (0-255) to accept a detected document.
Default is 0
*/
this.acceptedBrightnessThreshold = 0;
/**
The minimum score in percent (0 - 100) that the aspect ratio of the document
must match one of the required aspect ratios (if any) to accept a detected document.
If acceptedAspectRatioScore is more than 0, then the document is only accepted if the aspect ratio
matches one of the given aspect ratios (if any), otherwise OK_BUT_BAD_ASPECT_RATIO is returned.
Default is 85
*/
this.acceptedAspectRatioScore = 85;
/**
The possible desired aspect ratios for the detected document.
A document matches if its aspect ratio matches any of the given aspect ratios.
If acceptedAspectRatioScore is more than 0, then the document is only accepted if the aspect ratio
matches one of the given aspect ratios, otherwise OK_BUT_BAD_ASPECT_RATIO is returned.
If empty, no aspect ratio is preferred.
*/
this.aspectRatios = [];
/**
If false, the document scanner will return OK_BUT_ORIENTATION_MISMATCH if the
detected document orientation does not match the input image orientation,
e.g. if the document is detected as landscape but the input image is portrait.
If true, the document scanner will ignore orientation mismatches.
Default is false
*/
this.ignoreOrientationMismatch = false;
if (source.acceptedAngleScore !== undefined) {
this.acceptedAngleScore = source.acceptedAngleScore;
}
if (source.acceptedSizeScore !== undefined) {
this.acceptedSizeScore = source.acceptedSizeScore;
}
if (source.acceptedBrightnessThreshold !== undefined) {
this.acceptedBrightnessThreshold = source.acceptedBrightnessThreshold;
}
if (source.acceptedAspectRatioScore !== undefined) {
this.acceptedAspectRatioScore = source.acceptedAspectRatioScore;
}
if (source.aspectRatios !== undefined) {
this.aspectRatios = source.aspectRatios.map((it) => {
return new AspectRatio(it);
});
}
if (source.ignoreOrientationMismatch !== undefined) {
this.ignoreOrientationMismatch = source.ignoreOrientationMismatch;
}
}
}
/**
Configuration for the document scanner.
*/
export class DocumentScannerConfiguration extends PartiallyConstructible {
/** @param source {@displayType `DeepPartial<DocumentScannerConfiguration>`} */
constructor(source = {}) {
super();
/**
The engine to use for document scanning.
Default is ML
*/
this.engineMode = 'ML';
/**
Initial parameters for the document scanner.
*/
this.parameters = new DocumentScannerParameters({});
if (source.engineMode !== undefined) {
this.engineMode = source.engineMode;
}
if (source.parameters !== undefined) {
this.parameters = new DocumentScannerParameters(source.parameters);
}
}
}
export const DocumentDetectionStatusValues = [
'NOT_ACQUIRED',
'OK',
'OK_BUT_TOO_SMALL',
'OK_BUT_BAD_ANGLES',
'OK_BUT_BAD_ASPECT_RATIO',
'OK_BUT_ORIENTATION_MISMATCH',
'OK_BUT_OFF_CENTER',
'OK_BUT_TOO_DARK',
'ERROR_NOTHING_DETECTED',
'ERROR_TOO_DARK',
'ERROR_TOO_NOISY',
];
/**
The total and partial scores for the detected document contour.
*/
export class DocumentDetectionScores extends PartiallyConstructible {
/** @param source {@displayType `DeepPartial<DocumentDetectionScores>`} */
constructor(source = {}) {
super();
if (source.totalScore !== undefined) {
this.totalScore = source.totalScore;
}
else {
throw new Error('totalScore must be present in constructor argument');
}
if (source.distanceScore !== undefined) {
this.distanceScore = source.distanceScore;
}
else {
throw new Error('distanceScore must be present in constructor argument');
}
if (source.angleScore !== undefined) {
this.angleScore = source.angleScore;
}
else {
throw new Error('angleScore must be present in constructor argument');
}
if (source.sizeScore !== undefined) {
this.sizeScore = source.sizeScore;
}
else {
throw new Error('sizeScore must be present in constructor argument');
}
if (source.aspectRatioScore !== undefined) {
this.aspectRatioScore = source.aspectRatioScore;
}
else {
throw new Error('aspectRatioScore must be present in constructor argument');
}
if (source.lineCoverageScore !== undefined) {
this.lineCoverageScore = source.lineCoverageScore;
}
else {
throw new Error('lineCoverageScore must be present in constructor argument');
}
if (source.widthScore !== undefined) {
this.widthScore = source.widthScore;
}
else {
throw new Error('widthScore must be present in constructor argument');
}
if (source.heightScore !== undefined) {
this.heightScore = source.heightScore;
}
else {
throw new Error('heightScore must be present in constructor argument');
}
}
serialize(config = new ToJsonConfiguration()) {
return {
totalScore: this.totalScore,
distanceScore: this.distanceScore,
angleScore: this.angleScore,
sizeScore: this.sizeScore,
aspectRatioScore: this.aspectRatioScore,
lineCoverageScore: this.lineCoverageScore,
widthScore: this.widthScore,
heightScore: this.heightScore,
};
}
}
/**
Result of the document contour detection.
*/
export class DocumentDetectionResult extends PartiallyConstructible {
/** @param source {@displayType `DeepPartial<DocumentDetectionResult>`} */
constructor(source = {}) {
super();
/**
Detection status.
Default is NOT_ACQUIRED
*/
this.status = 'NOT_ACQUIRED';
/**
Average brightness, calculated as the average
of the Value channel in the HSV color space of:
- the whole image, if no document was detected
- the document crop, if a document was detected
Ranges from 0 to 255.
Default is 0
*/
this.averageBrightness = 0;
if (source.status !== undefined) {
this.status = source.status;
}
if (source.detectionScores !== undefined) {
this.detectionScores = new DocumentDetectionScores(source.detectionScores);
}
else {
throw new Error('detectionScores must be present in constructor argument');
}
if (source.points !== undefined) {
this.points = source.points.map((it) => {
return { x: it.x, y: it.y };
});
}
else {
throw new Error('points must be present in constructor argument');
}
if (source.horizontalLines !== undefined) {
this.horizontalLines = source.horizontalLines.map((it) => {
return new LineSegmentInt(it);
});
}
else {
throw new Error('horizontalLines must be present in constructor argument');
}
if (source.verticalLines !== undefined) {
this.verticalLines = source.verticalLines.map((it) => {
return new LineSegmentInt(it);
});
}
else {
throw new Error('verticalLines must be present in constructor argument');
}
if (source.pointsNormalized !== undefined) {
this.pointsNormalized = source.pointsNormalized.map((it) => {
return { x: it.x, y: it.y };
});
}
else {
throw new Error('pointsNormalized must be present in constructor argument');
}
if (source.horizontalLinesNormalized !== undefined) {
this.horizontalLinesNormalized = source.horizontalLinesNormalized.map((it) => {
return new LineSegmentFloat(it);
});
}
else {
throw new Error('horizontalLinesNormalized must be present in constructor argument');
}
if (source.verticalLinesNormalized !== undefined) {
this.verticalLinesNormalized = source.verticalLinesNormalized.map((it) => {
return new LineSegmentFloat(it);
});
}
else {
throw new Error('verticalLinesNormalized must be present in constructor argument');
}
if (source.aspectRatio !== undefined) {
this.aspectRatio = source.aspectRatio;
}
else {
throw new Error('aspectRatio must be present in constructor argument');
}
if (source.averageBrightness !== undefined) {
this.averageBrightness = source.averageBrightness;
}
}
serialize(config = new ToJsonConfiguration()) {
return {
status: this.status,
detectionScores: this.detectionScores.serialize(config),
points: this.points.map((it) => {
return it;
}),
horizontalLines: this.horizontalLines.map((it) => {
return it.serialize(config);
}),
verticalLines: this.verticalLines.map((it) => {
return it.serialize(config);
}),
pointsNormalized: this.pointsNormalized.map((it) => {
return it;
}),
horizontalLinesNormalized: this.horizontalLinesNormalized.map((it) => {
return it.serialize(config);
}),
verticalLinesNormalized: this.verticalLinesNormalized.map((it) => {
return it.serialize(config);
}),
aspectRatio: this.aspectRatio,
averageBrightness: this.averageBrightness,
};
}
}
//# sourceMappingURL=DocumentScannerTypes.js.map