@@ -8,69 +8,72 @@ import { ObjectResult } from '@nativescript/mlkit-object-detection';
8
8
import { PoseResult } from '@nativescript/mlkit-pose-detection' ;
9
9
import { TextResult } from '@nativescript/mlkit-text-recognition' ;
10
10
export function navigatingTo ( args : EventData ) {
11
- const page = < Page > args . object ;
12
- page . bindingContext = new DemoModel ( ) ;
11
+ const page = < Page > args . object ;
12
+ page . bindingContext = new DemoModel ( ) ;
13
13
}
14
14
15
15
export class DemoModel extends DemoSharedMlkitCore {
16
- camera : MLKitView ;
17
- detectorType = "all" ;
18
- isPaused = false ;
19
- onLoaded ( args ) {
20
- this . camera = args . object ;
21
- }
16
+ camera : MLKitView ;
17
+ detectorType = DetectionType . Barcode ;
18
+ isPaused = false ;
19
+ torchOn = false ;
20
+ onLoaded ( args ) {
21
+ this . camera = args . object ;
22
+ this . set ( 'isPaused' , this . camera . pause ) ;
23
+ this . set ( 'torchOn' , this . camera . torchOn ) ;
24
+ }
22
25
23
- onDetection ( event : DetectionEvent ) {
24
- console . log ( 'onDetection' , event . data , event . type ) ;
25
- }
26
+ onDetection ( event : DetectionEvent ) {
27
+ console . log ( 'onDetection' , event . data , event . type ) ;
28
+ if ( event . type === DetectionType . Barcode ) {
29
+ const first = event . data [ 0 ] as BarcodeResult ;
30
+ console . log ( 'bounds' , first . bounds ) ;
31
+ }
32
+ }
26
33
27
- toggleCamera ( ) {
28
- this . camera . toggleCamera ( ) ;
29
- }
34
+ toggleCamera ( ) {
35
+ this . camera . toggleCamera ( ) ;
36
+ }
30
37
31
- requestPermission ( ) {
32
- this . camera . requestCameraPermission ( ) ;
33
- }
38
+ toggleTorch ( ) {
39
+ this . camera . torchOn = ! this . camera . torchOn
40
+ this . set ( 'torchOn' , this . camera . torchOn ) ;
41
+ }
34
42
35
- changeType ( args ) {
36
- Dialogs . action ( 'Change Detector Type' , 'Cancel' , [
37
- 'all' ,
38
- 'barcode' ,
39
- 'digitalInk (unsupport atm)' ,
40
- 'face' ,
41
- 'image' ,
42
- 'object' ,
43
- 'pose' ,
44
- 'text' ,
45
- 'none'
46
- ] ) . then ( value => {
47
- if ( value === 'Cancel' ) { return }
48
- if ( value . indexOf ( 'digitalInk' ) > - 1 ) {
49
- Dialogs . alert ( 'digitalInk is currently unsupported' )
50
- this . set ( 'detectorType' , 'none' ) ;
51
- } else {
52
- this . set ( 'detectorType' , value ) ;
53
- }
54
- } )
55
- }
43
+ requestPermission ( ) {
44
+ this . camera . requestCameraPermission ( ) ;
45
+ }
56
46
57
- togglePause ( args ) {
58
- this . camera . pause = ! this . camera . pause ;
59
- this . set ( 'isPaused' , this . camera . pause ) ;
60
- }
47
+ changeType ( args ) {
48
+ Dialogs . action ( 'Change Detector Type' , 'Cancel' , [ 'all' , 'barcode' , 'digitalInk (unsupport atm)' , 'face' , 'image' , 'object' , 'pose' , 'text' , 'none' ] ) . then ( ( value ) => {
49
+ if ( value === 'Cancel' ) {
50
+ return ;
51
+ }
52
+ if ( value . indexOf ( 'digitalInk' ) > - 1 ) {
53
+ Dialogs . alert ( 'digitalInk is currently unsupported' ) ;
54
+ this . set ( 'detectorType' , 'none' ) ;
55
+ } else {
56
+ this . set ( 'detectorType' , value ) ;
57
+ }
58
+ } ) ;
59
+ }
61
60
62
- async processStill ( args ) {
63
- try {
64
- const src = await ImageSource . fromUrl ( 'https://www.jqueryscript.net/images/jQuery-Plugin-To-Generate-International-Article-Number-Barcode-EAN13.jpg' ) ;
65
-
66
- console . log ( src . android )
67
- const result = await detectWithStillImage ( src , {
68
- detectorType : DetectionType . Barcode
69
- } ) ;
70
- console . log ( 'processStill' , result . barcode [ 0 ] ) ;
71
- } catch ( e ) {
72
- console . log ( e ) ;
73
- }
74
- }
75
- }
61
+ togglePause ( args ) {
62
+ this . camera . pause = ! this . camera . pause ;
63
+ this . set ( 'isPaused' , this . camera . pause ) ;
64
+ }
65
+
66
+ async processStill ( args ) {
67
+ try {
68
+ const src = await ImageSource . fromUrl ( 'https://www.jqueryscript.net/images/jQuery-Plugin-To-Generate-International-Article-Number-Barcode-EAN13.jpg' ) ;
76
69
70
+ console . log ( src . android ) ;
71
+ const result = await detectWithStillImage ( src , {
72
+ detectorType : DetectionType . Barcode ,
73
+ } ) ;
74
+ console . log ( 'processStill' , result . barcode [ 0 ] ) ;
75
+ } catch ( e ) {
76
+ console . log ( e ) ;
77
+ }
78
+ }
79
+ }
0 commit comments