-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDocumentImageStraighteningUI2ViewController.swift
More file actions
92 lines (69 loc) · 3.57 KB
/
Copy pathDocumentImageStraighteningUI2ViewController.swift
File metadata and controls
92 lines (69 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// DocumentImageStraighteningUI2ViewController.swift
// ScanbotSDK Examples
//
// Created by Seifeddine Bouzid on 22.03.26.
//
import Foundation
import ScanbotSDK
class DocumentImageStraighteningUI2ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Start scanning here. Usually this is an action triggered by some button or menu.
Task {
await self.startScanning()
}
}
func startScanning() async {
// Create the default configuration object.
let configuration = SBSDKUI2DocumentScanningFlow()
// Create the parameters.
let parameters = SBSDKDocumentStraighteningParameters()
// Configure the properties.
// e.g
parameters.straighteningMode = .straighten
// By default, aspect ratio of the straightened document is automatically determined based on the detected document corners.
// If the document is significantly deformed, the estimated aspect ratio may be inaccurate.
// In such cases, providing a list of expected aspect ratios may help improve the accuracy of the straightening.
parameters.aspectRatios = [SBSDKAspectRatio(width: 1, height: 1),
SBSDKAspectRatio(width: 16, height: 9),
SBSDKAspectRatio(width: 3, height: 4)]
// Set the straightening parameters newly created.
configuration.outputSettings.straighteningParameters = parameters
// Pass the DOCUMENT_UUID here to resume an old session, or pass nil to start a new session or to resume a draft session.
configuration.documentUuid = nil
// Controls whether to resume an existing draft session or start a new one when DOCUMENT_UUID is nil.
configuration.cleanScanningSession = true
// Present the view controller modally.
do {
let result = try await SBSDKUI2DocumentScannerController.present(on: self, configuration: configuration)
// Handle the result.
print(result.uuid)
print(result.pageCount)
print(result.documentImageSizeLimit)
print(result.pdfURI)
print(result.tiffURI)
print(result.creationDate)
// Check out other available properties in `SBSDKScannedDocument`.
result.pages.forEach { scannedPage in
print(scannedPage.uuid)
print(scannedPage.documentDetectionStatus)
print(scannedPage.polygon)
print(scannedPage.source)
let originalImage = scannedPage.originalImage
let originalImageURI = scannedPage.originalImageURI
// Document image is straightened.
let documentImage = scannedPage.documentImage
let documentImageURI = scannedPage.documentImageURI
// Document image preview is straightened.
let documentImagePreview = scannedPage.documentImagePreview
let documentImagePreviewURI = scannedPage.documentImagePreviewURI
}
} catch SBSDKError.operationCanceled {
print("The operation was cancelled before completion or by the user")
} catch {
// Any other error
print("Error scanning document: \(error.localizedDescription)")
}
}
}