1
1
import { useEffect , useState } from "react" ;
2
- import { Box } from "@mui/material" ;
2
+ import { Box , Button , CircularProgress } from "@mui/material" ;
3
3
import { SBStoreCroppedDetectionResult } from "scanbot-web-sdk/@types" ;
4
4
5
5
import SBSDKService from "../service/SBSDKService" ;
@@ -11,6 +11,7 @@ export default function StorageDetailsPage() {
11
11
12
12
const [ item , setItem ] = useState < SBStoreCroppedDetectionResult | null > ( null ) ;
13
13
const [ base64Image , setBase64Image ] = useState < string | undefined > ( undefined ) ;
14
+ const [ isLoading , setIsLoading ] = useState ( false ) ;
14
15
15
16
useEffect ( ( ) => {
16
17
@@ -26,15 +27,43 @@ export default function StorageDetailsPage() {
26
27
}
27
28
28
29
async function loadItem ( ) {
29
- const result = await SBSDKService . SDK . storage . getCroppedDetectionResult ( itemId ) ;
30
+ setIsLoading ( true ) ;
31
+ const sdk = await SBSDKService . awaitSDK ( ) ;
32
+ const result = await sdk . storage . getCroppedDetectionResult ( itemId ) ;
30
33
setItem ( result ) ;
31
34
const base64 = await ImageUtils . createBase64Image ( result ) ;
32
35
setBase64Image ( base64 ) ;
36
+ setIsLoading ( false ) ;
33
37
}
34
38
35
39
loadItem ( ) ;
36
40
} , [ ] ) ;
37
41
42
+ async function runDQA ( ) {
43
+ if ( ! item ) {
44
+ return ;
45
+ }
46
+ setIsLoading ( true ) ;
47
+ const image = item . croppedImage ?? item . originalImage ;
48
+ const analyzer = await SBSDKService . SDK . createDocumentQualityAnalyzer ( { } )
49
+ const result = await analyzer . analyze ( image ) ;
50
+ setIsLoading ( false ) ;
51
+ console . log ( "Document quality analysis: " , result ) ;
52
+ }
53
+
54
+ async function runOCR ( ) {
55
+ if ( ! item ) {
56
+ return ;
57
+ }
58
+
59
+ setIsLoading ( true ) ;
60
+ const image = item . croppedImage ?? item . originalImage ;
61
+ const engine = await SBSDKService . SDK . createOcrEngine ( )
62
+ const result = await engine . performOcr ( image ) ;
63
+ setIsLoading ( false ) ;
64
+ console . log ( "OCR result: " , result ) ;
65
+ }
66
+
38
67
return (
39
68
< Box style = { {
40
69
display : "flex" ,
@@ -47,9 +76,25 @@ export default function StorageDetailsPage() {
47
76
< TopBar title = { "Document Details" } isBackNavigationEnabled = { true } />
48
77
< h2 style = { { color : TextColor } } > Storage Details</ h2 >
49
78
< h3 style = { { color : TextColor } } > Item ID: { item ?. id } </ h3 >
50
- < img src = { base64Image }
51
- alt = { `Storage image ${ item ?. id } ` }
52
- style = { { width : "90%" , maxHeight : 500 , objectFit : "contain" } }
79
+ { base64Image && < Box style = { {
80
+ display : "flex" ,
81
+ flexDirection : "column" ,
82
+ alignItems : "center" ,
83
+ width : "100%" ,
84
+ height : "100%" ,
85
+ } } >
86
+ < img src = { base64Image }
87
+ alt = { `Storage image ${ item ?. id } ` }
88
+ style = { { width : "90%" , maxHeight : 500 , objectFit : "contain" } }
89
+ />
90
+ < Box style = { { paddingLeft : "5%" , paddingTop : 10 } } >
91
+ < Button onClick = { runDQA } > Run Document Quality Analysis</ Button >
92
+ < Button onClick = { runOCR } > Run Optical Character Recognition</ Button >
93
+ </ Box >
94
+ </ Box > }
95
+ < CircularProgress
96
+ style = { { position : "absolute" , top : "40%" , visibility : isLoading ? "visible" : "hidden" } }
97
+ color = "primary"
53
98
/>
54
99
</ Box >
55
100
)
0 commit comments