Scanning a document from an image | Web Document Scanner
async detectDocument(imageBuffer: ArrayBuffer, acceptedAngleScore?: number, acceptedSizeScore?: number): Promise<ContourDetectionResult>
class ContourDetectionResult {
horizontalLines?: MagneticLine[];
verticalLines?: MagneticLine[];
polygon?: Polygon;
detectionStatus?: DetectionStatus;
success?: boolean;
}
class MagneticLine {
p1: Point;
p2: Point;
}
Detects document on a still image on JPG file regardless of the image source (e.g. scanned document image, image picked from photo library, etc).
Example usage:
...
reader.readAsArrayBuffer(file);
reader.onload = async (e) => {
const result = await scanbotSDK.detectDocument(reader.result);
if (result.success === true) {
...
} else {
...
}
};
The result
object contains the following properties:
detectionStatus
– DetectionStatus, contains the same keys as the hint texts mentioned earliersuccess
– boolean, whether detection was successful or notoriginal
– Ifsuccess
, contains the cropped document ArrayBuffer (UInt8Array
)cropped
– Ifsuccess
, contains the cropped document ArrayBuffer (UInt8Array
)polygon
– Polygon, The page's cropping polygon as calculated by a document detection operation
enum DetectionStatus {
NotAcquired = 'NotAcquired',
OK = 'OK',
OK_SmallSize = 'OK_SmallSize',
OK_BadAngles = 'OK_BadAngles',
OK_BadAspectRatio ='OK_BadAspectRatio',
OK_OffCenter = 'OK_OffCenter',
Error_NothingDetected = 'Error_NothingDetected',
Error_Brightness = 'Error_Brightness',
Error_Noise = 'Error_Noise',
}
type Polygon = [Point, Point, Point, Point];
Want to scan longer than one minute?
Generate a free trial license to test the Scanbot SDK thoroughly.
Get your free Trial LicenseWhat do you think of this documentation?
What can we do to improve it? Please be as detailed as you like.