react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
376 lines (335 loc) • 12.3 kB
text/typescript
/// Auto-generated with ScanbotSDKCodegenV3. Modifications will be overwritten.
/// Generated from core/schemas/ParametricFilters.yaml
import { ImageFilterType } from '../base/types';
import { DeepPartial, PartiallyConstructible } from '../utils/utils';
/**
Output mode of binarization filter.
- `BINARY`:
BINARY - Black and white image, suitable for 1-bit compression.
- `ANTIALIASED`:
ANTIALIASED - When the source image is a document photo, this mode
will produce nice, smooth, antialiased text in grayscale, which is typically more readable
than the text in BINARY mode. Antialiasing requires extra processing,
which makes this mode slower than BINARY mode.
*/
export type OutputMode = 'BINARY' | 'ANTIALIASED';
export const OutputModeValues: OutputMode[] = ['BINARY', 'ANTIALIASED'];
/**
Preset of parameters for custom binarization filter.
- `PRESET_1`:
Very fast, performs well if there are no shadows.
- `PRESET_2`:
Performs well even if there are shadows. Binarized barcodes typically remain readable.
- `PRESET_3`:
Performs well even if there are shadows.
- `PRESET_4`:
Performs well even if there are shadows. Recommended for most use cases involving text documents.
- `PRESET_5`:
Performs well even if there are shadows.
The preset is an upgrade to PRESET_4 that adds special treatment for high contrast objects such as barcodes.
Binarized barcodes typically remain readable.
*/
export type BinarizationFilterPreset =
| 'PRESET_1'
| 'PRESET_2'
| 'PRESET_3'
| 'PRESET_4'
| 'PRESET_5';
export const BinarizationFilterPresetValues: BinarizationFilterPreset[] = [
'PRESET_1',
'PRESET_2',
'PRESET_3',
'PRESET_4',
'PRESET_5',
];
/**
Base class for all parametric filters.
*/
export type ParametricFilter =
| ScanbotBinarizationFilter
| CustomBinarizationFilter
| ColorDocumentFilter
| BrightnessFilter
| ContrastFilter
| GrayscaleFilter
| LegacyFilter
| WhiteBlackPointFilter;
/** @internal */
export namespace ParametricFilter {
/** @internal */
export function From(source: { [key: string]: any }): ParametricFilter {
const _type = source._type;
switch (_type) {
case 'ScanbotBinarizationFilter':
return new ScanbotBinarizationFilter(source);
case 'CustomBinarizationFilter':
return new CustomBinarizationFilter(source);
case 'ColorDocumentFilter':
return new ColorDocumentFilter(source);
case 'BrightnessFilter':
return new BrightnessFilter(source);
case 'ContrastFilter':
return new ContrastFilter(source);
case 'GrayscaleFilter':
return new GrayscaleFilter(source);
case 'LegacyFilter':
return new LegacyFilter(source);
case 'WhiteBlackPointFilter':
return new WhiteBlackPointFilter(source);
default:
throw `Unknown child class name: ${_type}`;
}
}
}
/**
Automatic binarization filter. This filter is a good starting point for most use cases.
*/
export class ScanbotBinarizationFilter extends PartiallyConstructible {
public readonly _type: 'ScanbotBinarizationFilter' = 'ScanbotBinarizationFilter';
/**
Output mode of the filter. BINARY will return a black and white image, GRAYSCALE will return an antialiased grayscale image.
Default is BINARY
*/
public outputMode: OutputMode = 'BINARY';
/** @param source {@displayType `DeepPartial<ScanbotBinarizationFilter>`} */
public constructor(source: DeepPartial<ScanbotBinarizationFilter> = {}) {
super();
if (source.outputMode !== undefined) {
this.outputMode = source.outputMode;
}
}
}
/**
Automatic binarization filter. This filter is a good starting point for most use cases.
*/
export class CustomBinarizationFilter extends PartiallyConstructible {
public readonly _type: 'CustomBinarizationFilter' = 'CustomBinarizationFilter';
/**
Output mode of the filter. BINARY will return a black and white image, GRAYSCALE will return an antialiased grayscale image.
Default is BINARY
*/
public outputMode: OutputMode = 'BINARY';
/**
Value controlling the amount of noise removal. Value between 0 and 1.
Too little noise removal may result in a very noisy image, worsening readability.
Too much noise removal may result in the degradation of text, again, worsening readability.
Default is 0.5
*/
public denoise: number = 0.5;
/**
Filter radius. The bigger the radius, the slower the filter and generally the less noise in the result.
The radius is used for both shadows removal and the calculation of local statistics in the main body of the filter.
Higher radius usually allows to cope better with regions of light text on dark background.
All the values larger than 127 are clamped to 127.
Default is 32
*/
public radius: number = 32;
/**
Preset of binarization filter parameters that are found to perform well on different types of documents.
Default is PRESET_4
*/
public preset: BinarizationFilterPreset = 'PRESET_4';
/** @param source {@displayType `DeepPartial<CustomBinarizationFilter>`} */
public constructor(source: DeepPartial<CustomBinarizationFilter> = {}) {
super();
if (source.outputMode !== undefined) {
this.outputMode = source.outputMode;
}
if (source.denoise !== undefined) {
this.denoise = source.denoise;
}
if (source.radius !== undefined) {
this.radius = source.radius;
}
if (source.preset !== undefined) {
this.preset = source.preset;
}
}
}
/**
Color document filter. This filter is a good starting point for most use cases.
*/
export class ColorDocumentFilter extends PartiallyConstructible {
public readonly _type: 'ColorDocumentFilter' = 'ColorDocumentFilter';
/** @param source {@displayType `DeepPartial<ColorDocumentFilter>`} */
public constructor(source: DeepPartial<ColorDocumentFilter> = {}) {
super();
}
}
/**
Brightness adjustment filter.
*/
export class BrightnessFilter extends PartiallyConstructible {
public readonly _type: 'BrightnessFilter' = 'BrightnessFilter';
/**
Brightness adjustment value in the range from -1 to 1. Negative values will make the image darker, positive values will make it brighter.
Default is 0.0
*/
public brightness: number = 0.0;
/** @param source {@displayType `DeepPartial<BrightnessFilter>`} */
public constructor(source: DeepPartial<BrightnessFilter> = {}) {
super();
if (source.brightness !== undefined) {
this.brightness = source.brightness;
}
}
}
/**
Contrast adjustment filter.
*/
export class ContrastFilter extends PartiallyConstructible {
public readonly _type: 'ContrastFilter' = 'ContrastFilter';
/**
Contrast adjustment value in the range from -1 to 254 (inclusively). Negative values will decrease the contrast, positive values will increase it.
Default is 0.0
*/
public contrast: number = 0.0;
/** @param source {@displayType `DeepPartial<ContrastFilter>`} */
public constructor(source: DeepPartial<ContrastFilter> = {}) {
super();
if (source.contrast !== undefined) {
this.contrast = source.contrast;
}
}
}
/**
Converts color images to grayscale and applies autocontrast.
*/
export class GrayscaleFilter extends PartiallyConstructible {
public readonly _type: 'GrayscaleFilter' = 'GrayscaleFilter';
/**
Ignore this fraction of pixels at the edge of the image when calculating statistics.
Pixels at the edge of the image typically have poor statistics. Ignoring them
and using only the inner pixels when calculating certain statistics can
substantially improve the quality of the result.
The value must be less than 0.5 but usually good values are between 0 and 0.15.
Default is 0.06
*/
public borderWidthFraction: number = 0.06;
/**
Clip this fraction of the darkest pixels in operations such as autocontrast.
Increasing the range of middle gray levels at the expense of the brightest and darkest levels
may improve the overall contrast and quality of the result.
Sum of blackOutliersFraction and whiteOutliersFraction must be less than 1 but usually
good values for the parameters do not exceed 0.05;.
Default is 0.0
*/
public blackOutliersFraction: number = 0.0;
/**
Clip this fraction of the brightest pixels in operations such as autocontrast.
Increasing the range of middle gray levels at the expense of the brightest and darkest levels
may improve the overall contrast and quality of the result.
Sum of blackOutliersFraction and whiteOutliersFraction must be less than 1 but usually
good values for the parameters do not exceed 0.05;.
Default is 0.02
*/
public whiteOutliersFraction: number = 0.02;
/** @param source {@displayType `DeepPartial<GrayscaleFilter>`} */
public constructor(source: DeepPartial<GrayscaleFilter> = {}) {
super();
if (source.borderWidthFraction !== undefined) {
this.borderWidthFraction = source.borderWidthFraction;
}
if (source.blackOutliersFraction !== undefined) {
this.blackOutliersFraction = source.blackOutliersFraction;
}
if (source.whiteOutliersFraction !== undefined) {
this.whiteOutliersFraction = source.whiteOutliersFraction;
}
}
}
/**
Deprecated image filters.
*/
export class LegacyFilter extends PartiallyConstructible {
public readonly _type: 'LegacyFilter' = 'LegacyFilter';
/**
Id of filter to be applied.
Default is 0
*/
public filterType: number = 0;
/** @param source {@displayType `DeepPartial<LegacyFilter>`} */
public constructor(source: DeepPartial<LegacyFilter> = {}) {
super();
if (source.filterType !== undefined) {
this.filterType = source.filterType;
}
}
public static fromImageFilterType(imageFilterType: ImageFilterType): LegacyFilter {
var imageFilterTypeAsNumber: number;
switch (imageFilterType) {
default:
case 'NONE':
imageFilterTypeAsNumber = 0;
break;
case 'COLOR':
imageFilterTypeAsNumber = 1;
break;
case 'GRAYSCALE':
imageFilterTypeAsNumber = 2;
break;
case 'BINARIZED':
imageFilterTypeAsNumber = 3;
break;
case 'COLOR_DOCUMENT':
imageFilterTypeAsNumber = 4;
break;
case 'PURE_BINARIZED':
imageFilterTypeAsNumber = 11;
break;
case 'BACKGROUND_CLEAN':
imageFilterTypeAsNumber = 13;
break;
case 'BLACK_AND_WHITE':
imageFilterTypeAsNumber = 14;
break;
case 'OTSU_BINARIZATION':
imageFilterTypeAsNumber = 15;
break;
case 'DEEP_BINARIZATION':
imageFilterTypeAsNumber = 16;
break;
case 'EDGE_HIGHLIGHT':
imageFilterTypeAsNumber = 17;
break;
case 'LOW_LIGHT_BINARIZATION':
imageFilterTypeAsNumber = 18;
break;
case 'LOW_LIGHT_BINARIZATION_2':
imageFilterTypeAsNumber = 19;
break;
case 'PURE_GRAY':
imageFilterTypeAsNumber = 21;
break;
}
return new LegacyFilter({ filterType: imageFilterTypeAsNumber });
}
}
/**
Maps image value channel so that all the pixels darker than the black point are set to 0,
all the pixels brighter than the white point are set to 255, and the pixels in between
are linearly scaled.
*/
export class WhiteBlackPointFilter extends PartiallyConstructible {
public readonly _type: 'WhiteBlackPointFilter' = 'WhiteBlackPointFilter';
/**
Fraction of the value channel range that is set to 0. The value should be in the range from 0 to 1.
Default is 0.0
*/
public blackPoint: number = 0.0;
/**
Fraction of the value channel range that is not set to 255. The value should be in the range from 0 to 1.
Default is 1.0
*/
public whitePoint: number = 1.0;
/** @param source {@displayType `DeepPartial<WhiteBlackPointFilter>`} */
public constructor(source: DeepPartial<WhiteBlackPointFilter> = {}) {
super();
if (source.blackPoint !== undefined) {
this.blackPoint = source.blackPoint;
}
if (source.whitePoint !== undefined) {
this.whitePoint = source.whitePoint;
}
}
}