react-native-scanbot-sdk
Version:
Scanbot Document and Barcode Scanner SDK React Native Plugin for Android and iOS
331 lines (305 loc) • 10.3 kB
JavaScript
import { PartiallyConstructible } from '../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.
*/
/**
Preset of parameters for custom binarization filter.
- `PRESET_1`:
Usually performs well if there is no shadow.
- `PRESET_2`:
Usually performs well even if there are shadows.
- `PRESET_3`:
Usually performs well even if there are shadows.
- `PRESET_4`:
Usually performs well even if there are shadows.
*/
/** @internal */
export let ParametricFilter;
(function (_ParametricFilter) {
function From(source) {
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}`;
}
}
_ParametricFilter.From = From;
})(ParametricFilter || (ParametricFilter = {}));
/**
Automatic binarization filter. This filter is a good starting point for most use cases.
*/
export class ScanbotBinarizationFilter extends PartiallyConstructible {
_type = 'ScanbotBinarizationFilter';
/**
Output mode of the filter. BINARY will return a black and white image, GRAYSCALE will return an antialiased grayscale image.
Default is BINARY
*/
outputMode = 'BINARY';
/** @param source {@displayType `DeepPartial<ScanbotBinarizationFilter>`} */
constructor(source = {}) {
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 {
_type = 'CustomBinarizationFilter';
/**
Output mode of the filter. BINARY will return a black and white image, GRAYSCALE will return an antialiased grayscale image.
Default is BINARY
*/
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
*/
denoise = 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 512 are clamped to 512.
Default is 32
*/
radius = 32;
/**
Preset of binarization filter parameters that are found to perform well on different types of documents.
Default is PRESET_4
*/
preset = 'PRESET_4';
/** @param source {@displayType `DeepPartial<CustomBinarizationFilter>`} */
constructor(source = {}) {
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 {
_type = 'ColorDocumentFilter';
/** @param source {@displayType `DeepPartial<ColorDocumentFilter>`} */
constructor(source = {}) {
super();
}
}
/**
Brightness adjustment filter.
*/
export class BrightnessFilter extends PartiallyConstructible {
_type = '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
*/
brightness = 0.0;
/** @param source {@displayType `DeepPartial<BrightnessFilter>`} */
constructor(source = {}) {
super();
if (source.brightness !== undefined) {
this.brightness = source.brightness;
}
}
}
/**
Contrast adjustment filter.
*/
export class ContrastFilter extends PartiallyConstructible {
_type = '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
*/
contrast = 0.0;
/** @param source {@displayType `DeepPartial<ContrastFilter>`} */
constructor(source = {}) {
super();
if (source.contrast !== undefined) {
this.contrast = source.contrast;
}
}
}
/**
Converts color images to grayscale and applies autocontrast.
*/
export class GrayscaleFilter extends PartiallyConstructible {
_type = '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
*/
borderWidthFraction = 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
*/
blackOutliersFraction = 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
*/
whiteOutliersFraction = 0.02;
/** @param source {@displayType `DeepPartial<GrayscaleFilter>`} */
constructor(source = {}) {
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 {
_type = 'LegacyFilter';
/**
Id of filter to be applied.
Default is 0
*/
filterType = 0;
/** @param source {@displayType `DeepPartial<LegacyFilter>`} */
constructor(source = {}) {
super();
if (source.filterType !== undefined) {
this.filterType = source.filterType;
}
}
static fromImageFilterType(imageFilterType) {
var imageFilterTypeAsNumber;
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 {
_type = '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
*/
blackPoint = 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
*/
whitePoint = 1.0;
/** @param source {@displayType `DeepPartial<WhiteBlackPointFilter>`} */
constructor(source = {}) {
super();
if (source.blackPoint !== undefined) {
this.blackPoint = source.blackPoint;
}
if (source.whitePoint !== undefined) {
this.whitePoint = source.whitePoint;
}
}
}
//# sourceMappingURL=ParametricFilters.js.map