1
1
import { Component , NgZone } from '@angular/core' ;
2
2
import { DemoSharedMlkitCore } from '@demo/shared' ;
3
- import { } from '@nativescript/mlkit-core' ;
3
+ import { Dialogs , ImageSource } from '@nativescript/core' ;
4
+ import { DetectionEvent , DetectionType , detectWithStillImage , MLKitView } from '@nativescript/mlkit-core' ;
4
5
5
6
@Component ( {
6
- selector : 'demo-mlkit-core' ,
7
- templateUrl : 'mlkit-core.component.html' ,
7
+ selector : 'demo-mlkit-core' ,
8
+ templateUrl : 'mlkit-core.component.html' ,
8
9
} )
9
10
export class MlkitCoreComponent {
10
-
11
+
12
+ camera : MLKitView ;
13
+ detectorType = DetectionType . All ;
14
+ isPaused = true ;
15
+ torchOn = true ;
11
16
demoShared : DemoSharedMlkitCore ;
12
-
13
- constructor ( private _ngZone : NgZone ) { }
17
+
18
+ constructor ( private _ngZone : NgZone ) { }
14
19
15
20
ngOnInit ( ) {
16
21
this . demoShared = new DemoSharedMlkitCore ( ) ;
17
22
}
23
+ onLoaded ( args ) {
24
+ this . camera = args . object ;
25
+ }
26
+
27
+ onDetection ( event : DetectionEvent ) {
28
+ console . log ( 'onDetection' , event . data , event . type ) ;
29
+ }
30
+
31
+ toggleCamera ( args ) {
32
+ this . camera . toggleCamera ( ) ;
33
+ }
34
+
35
+ requestPermission ( args ) {
36
+ this . camera . requestCameraPermission ( ) ;
37
+ }
38
+
39
+ changeType ( args ) {
40
+ Dialogs . action ( 'Change Detector Type' , 'Cancel' , [
41
+ 'all' ,
42
+ 'barcode' ,
43
+ 'digitalInk (unsupport atm)' ,
44
+ 'face' ,
45
+ 'image' ,
46
+ 'object' ,
47
+ 'pose' ,
48
+ 'text' ,
49
+ 'none'
50
+ ] ) . then ( value => {
51
+ if ( value === 'Cancel' ) { return }
52
+ if ( value . indexOf ( 'digitalInk' ) > - 1 ) {
53
+ Dialogs . alert ( 'digitalInk is currently unsupported' ) ;
54
+ this . detectorType = DetectionType . None ;
55
+ } else {
56
+ this . detectorType = value as any ;
57
+ }
58
+ } )
59
+ }
60
+
61
+ togglePause ( args ) {
62
+ this . camera . pause = ! this . camera . pause ;
63
+ this . isPaused = this . camera . pause ;
64
+ }
65
+
66
+ toggleTorch ( args ) {
67
+ this . camera . torchOn = ! this . camera . torchOn ;
68
+ this . torchOn = this . camera . torchOn ;
69
+ }
70
+
71
+ async processStill ( args ) {
72
+ try {
73
+ const src = await ImageSource . fromUrl ( 'https://www.jqueryscript.net/images/jQuery-Plugin-To-Generate-International-Article-Number-Barcode-EAN13.jpg' ) ;
74
+ const result = await detectWithStillImage ( src , {
75
+ detectorType : DetectionType . Barcode
76
+ } ) ;
77
+ console . log ( 'processStill' , result . barcode [ 0 ] ) ;
78
+ } catch ( e ) {
79
+ console . log ( e ) ;
80
+ }
81
+ }
18
82
19
83
}
0 commit comments