11# @nativescript/mlkit-core
22
3- ``` javascript
3+ A plugin that provides a UI component to access the different functionalities of [ Google's ML Kit] ( https://developers.google.com/ml-kit ) SDK.
4+
5+ ## Contents
6+
7+ * [ Installation] ( #installation )
8+ * [ Use @nativescript/mlkit-core ] ( #use-nativescriptmlkit-core )
9+ * [ Core] ( #core )
10+ * [ Angular] ( #angular )
11+ * [ Vue] ( #vue )
12+ * [ Vision APIs optional modules] ( #vision-apis-optional-modules )
13+ * [ Barcode Scanning] ( #barcode-scanning )
14+ * [ Face Detection] ( #face-detection )
15+ * [ Image Labeling] ( #image-labeling )
16+ * [ Object Detection] ( #object-detection )
17+ * [ Pose Detection] ( #pose-detection )
18+ * [ Text Recognition] ( #text-recognition )
19+
20+ * [ API] ( #api )
21+ * [ detectWithStillImage()] ( #detectwithstillimage )
22+ * [ StillImageDetectionOptions interface] ( #stillimagedetectionoptions-interface )
23+ * [ MLKitView class] ( #mlkitview-class )
24+ * [ Properties] ( #properties )
25+ * [ Methods] ( #methods )
26+ * [ Enums] ( #enums )
27+ * [ DetectionType] ( #detectiontype )
28+ * [ CameraPosition] ( #cameraposition )
29+ * [ BarcodeFormats] ( #barcodeformats )
30+ * [ FaceDetectionPerformanceMode] ( #facedetectionperformancemode )
31+ * [ License] ( #license )
32+
33+ ## Installation
34+
35+ ``` cli
436npm install @nativescript/mlkit-core
537```
638
7- ## Usage
39+ ## Use @nativescript/mlkit-core
40+ The usage of ` @nativescript/mlkit-core ` has the following flow:
841
42+ 1 . Registering and adding [ MLKitView] ( #mlkitview-class ) to your markup.
943
10- ## Core
44+ 2 . Setting the ` detectionType ` and listening to the ` detection ` event.
1145
12- > ** Important:** Ensure you've included xmlns: ui ="@nativescript/mlkit-core " on the Page element
46+ To access all the vision APIs at once, set the ` detectionType ` property to ` 'all' ` and identify them in the ` detection ` event's handler.
47+
48+ To access a specific API, Barcode scanning for example, set the ` detectionType ` property to the API name (` 'barcode' ` for Barcode scanning), AND import that API's NativeScript plugin(` @nativescript/mlkit-barcode-scanning ` ).
49+
50+ 3 . Check if ML Kit is supported
51+ To verify if ML Kit is supported on the device, call the static ` isAvailable() ` method on [ MLKitView class] ( #mlkitview-class ) .
52+
53+ ``` ts
54+ if (MLKitView .isAvailable ()){
55+
56+ }
57+ ```
58+ 4 . Request for permission to access the device camera by calling ` requestCameraPermission() ` :
59+
60+ ``` ts
61+ mlKitView .requestCameraPermission ().then (()=> {
62+
63+ })
64+ ```
65+ The following are examples of registering and using ` MLKitView ` in the different JS flavors.
66+
67+ ### Core
68+
69+ 1 . Register [ MLKitView] ( #mlkitview-class ) by adding ` xmlns:ui="@nativescript/mlkit-core" ` to the Page element.
70+
71+ 2 . Use the ` ui ` prefix to access ` MLKitView ` from the plugin.
1372
1473``` xml
1574<ui : MLKitView
@@ -19,8 +78,9 @@ npm install @nativescript/mlkit-core
1978/>
2079```
2180
81+ ### Angular
2282
23- #### Angular
83+ 1 . In Angular, register the ` MLKitView ` by adding ` MLKitModule ` to the ` NgModule ` of the component where you want to use ` MLKitView ` .
2484
2585``` ts
2686import { MLKitModule } from ' @nativescript/mlkit-core/angular' ;
@@ -36,6 +96,7 @@ import { MLKitModule } from '@nativescript/mlkit-core/angular';
3696})
3797```
3898
99+ 2 . Use ` MLKitView ` in markup.
39100
40101``` html
41102<MLKitView
@@ -45,14 +106,21 @@ detectionType="all"
45106></MLKitView >
46107```
47108
48- #### Vue
109+ ### Vue
110+
111+ 1 . To use [ MLKitView] ( #mlkitview-class ) , register it in the ` app.ts ` by passing it to the ` use ` method of the app instance.
49112
50113``` ts
51- import Vue from ' nativescript-vue'
114+ import { createApp } from ' nativescript-vue'
115+
52116import MLKit from ' @nativescript/mlkit-core/vue'
117+ import Home from ' ./components/Home.vue' ;
118+
119+ const app = createApp (Home )
53120
54- Vue .use (MLKit )
121+ app .use (MLKit )
55122```
123+ 2 . Use ` MLKitView ` in markup.
56124
57125``` html
58126<MLKitView
@@ -62,14 +130,14 @@ detectionType="all"
62130/>
63131```
64132
65- ### Optional modules
133+ ### Vision APIs optional modules
66134
67135> ** Important:** Detection works only for optional modules installed
68136
69- # Barcode Scanning
137+ #### Barcode Scanning
70138
71- ``` javascript
72- npm install @nativescript/ mlkit- barcode- scanning
139+ ``` cli
140+ npm i @nativescript/mlkit-barcode-scanning
73141```
74142
75143``` ts
@@ -82,26 +150,30 @@ onDetection(event: DetectionEvent){
82150}
83151```
84152
85- # Face Detection
153+ For more details, see [ @ nativescript/mlkit-barcode-scanning ] ( ../mlkit-barcode-scanning/ )
86154
87- ``` javascript
155+ #### Face Detection
156+
157+ ``` cli
88158npm install @nativescript/mlkit-face-detection
89159```
90160
91161``` ts
92162import { DetectionType , DetectionEvent } from ' @nativescript/mlkit-core' ;
93163import { FaceResult } from ' @nativescript/mlkit-face-detection' ;
164+
94165onDetection (event : DetectionEvent ){
95166 if (event .type === DetectionType .Face ){
96167 const faces: FaceResult [] = event .data ;
97168 }
98169}
99170```
100171
172+ For more details, see [ @nativescript/mlkit-face-detection ] ( ../mlkit-face-detection/ )
101173
102- # Image Labeling
174+ #### Image Labeling
103175
104- ``` javascript
176+ ``` cli
105177npm install @nativescript/mlkit-image-labeling
106178```
107179
@@ -115,10 +187,11 @@ onDetection(event: DetectionEvent){
115187}
116188```
117189
190+ For more details, see [ nativescript/mlkit-image-labeling] ( ../mlkit-image-labeling/ )
118191
119- # Object Detection
192+ #### Object Detection
120193
121- ``` javascript
194+ ``` cli
122195npm install @nativescript/mlkit-object-detection
123196```
124197
@@ -131,10 +204,11 @@ onDetection(event: DetectionEvent){
131204 }
132205}
133206```
207+ For more details, see [ @nativescript/mlkit-object-detection ] ( ../mlkit-object-detection/ )
134208
135- # Pose Detection
209+ #### Pose Detection
136210
137- ``` javascript
211+ ``` cli
138212npm install @nativescript/mlkit-pose-detection
139213```
140214
@@ -148,10 +222,11 @@ onDetection(event: DetectionEvent){
148222}
149223```
150224
225+ For more details, see [ @nativescript/mlkit-pose-detection ] ( ../mlkit-pose-detection/ )
151226
152- # Text Recognition
227+ #### Text Recognition
153228
154- ``` javascript
229+ ``` cli
155230npm install @nativescript/mlkit-text-recognition
156231```
157232
@@ -164,8 +239,153 @@ onDetection(event: DetectionEvent){
164239 }
165240}
166241```
242+ For more details, see [ @nativescript/mlkit-text-recognition ] ( ../mlkit-text-recognition/ )
243+
244+ ## API
245+
246+ ### detectWithStillImage()
247+
248+ ``` ts
249+ import { DetectionType , detectWithStillImage } from " @nativescript/mlkit-core" ;
250+
251+ async processStill (args ) {
252+ try {
253+
254+ result : { [key : string ]: any } = await detectWithStillImage (image : ImageSource , options )
255+ } catch (e ) {
256+ console .log (e );
257+ }
258+ }
259+ ```
260+ Detects barcode, pose, etc from a still image instead of using the camera.
261+ - ` image ` : The image to detect the object from
262+ - ` options ` : An _ optional_ [ StillImageDetectionOptions] ( #stillimagedetectionoptions ) object parameter specifying the detection characteristics.
263+
264+ ### MLKitView class
265+
266+ The MLKitView class provides the camera view for detection.
267+
268+ It has the following members.
269+
270+ #### Properties
271+
272+ | Property | Type
273+ |:---------|:-----
274+ | ` detectionEvent ` | ` string `
275+ | ` cameraPosition ` | [ CameraPosition] ( #cameraposition )
276+ | ` detectionType ` | [ DetectionType] ( #detectiontype )
277+ | ` barcodeFormats ` | [ BarcodeFormats] ( #barcodeformats )
278+ | ` faceDetectionPerformanceMode ` | [ FaceDetectionPerformanceMode] ( #facedetectionperformancemode )
279+ | ` faceDetectionTrackingEnabled ` | ` boolean `
280+ | ` faceDetectionMinFaceSize ` | ` number `
281+ | ` imageLabelerConfidenceThreshold ` | ` number `
282+ | ` objectDetectionMultiple ` | ` boolean `
283+ | ` objectDetectionClassify ` | ` boolean `
284+ | ` torchOn ` | ` boolean `
285+ | ` pause ` | ` boolean `
286+ | ` processEveryNthFrame ` | ` number `
287+ | ` readonly latestImage? ` | [ ImageSource] ( https://docs.nativescript.org/api-reference/classes/imagesource )
288+ | ` retrieveLatestImage ` | ` boolean `
289+
290+ #### Methods
291+
292+ | Method | Returns | Description
293+ |:-------|:--------|:-----------
294+ | ` isAvailable() ` | ` boolean ` | A static method to check if the device supports ML Kit.
295+ | ` stopPreview() ` | ` void `
296+ | ` startPreview() ` | ` void `
297+ | ` toggleCamera() ` | ` void `
298+ | ` requestCameraPermission() ` | ` Promise<void> `
299+ | ` hasCameraPermission() ` | ` boolean ` |
300+ | ` on() ` | ` void ` |
301+
302+
303+ #### StillImageDetectionOptions interface
304+
305+
306+ ``` ts
307+ interface StillImageDetectionOptions {
308+ detectorType: DetectionType ;
309+
310+ barcodeScanning? : {
311+ barcodeFormat? : [BarcodeFormats ];
312+ };
313+ faceDetection? : {
314+ faceTracking? : boolean ;
315+ minimumFaceSize: ? number ;
316+ detectionMode? : ' fast' | ' accurate' ;
317+ landmarkMode? : ' all' | ' none' ;
318+ contourMode? : ' all' | ' none' ;
319+ classificationMode? : ' all' | ' none' ;
320+ };
321+ imageLabeling? : {
322+ confidenceThreshold? : number ;
323+ };
324+ objectDetection? : {
325+ multiple: boolean ;
326+ classification: boolean ;
327+ };
328+ selfieSegmentation? : {
329+ enableRawSizeMask? : boolean ;
330+ smoothingRatio? : number ;
331+ };
332+ }
333+ ```
334+ ### Enums
335+
336+ #### DetectionType
167337
338+ ``` ts
339+ export enum DetectionType {
340+ Barcode = ' barcode' ,
341+ DigitalInk = ' digitalInk' ,
342+ Face = ' face' ,
343+ Image = ' image' ,
344+ Object = ' object' ,
345+ Pose = ' pose' ,
346+ Text = ' text' ,
347+ All = ' all' ,
348+ Selfie = ' selfie' ,
349+ None = ' none' ,
350+ }
351+ ```
168352
353+ #### CameraPosition
354+ ``` ts
355+ export enum CameraPosition {
356+ FRONT = ' front' ,
357+ BACK = ' back' ,
358+ }
359+ ```
360+
361+ #### BarcodeFormats
362+ ``` ts
363+ export enum BarcodeFormats {
364+ ALL = ' all' ,
365+ CODE_128 = ' code_128' ,
366+ CODE_39 = ' code_39' ,
367+ CODE_93 = ' code_93' ,
368+ CODABAR = ' codabar' ,
369+ DATA_MATRIX = ' data_matrix' ,
370+ EAN_13 = ' ean_13' ,
371+ EAN_8 = ' ean_8' ,
372+ ITF = ' itf' ,
373+ QR_CODE = ' qr_code' ,
374+ UPC_A = ' upc_a' ,
375+ UPC_E = ' upc_e' ,
376+ PDF417 = ' pdf417' ,
377+ AZTEC = ' aztec' ,
378+ UNKOWN = ' unknown' ,
379+ }
380+ ```
381+ #### FaceDetectionPerformanceMode
382+
383+ ``` ts
384+ export enum FaceDetectionPerformanceMode {
385+ Fast = ' fast' ,
386+ Accurate = ' accurate' ,
387+ }
388+ ```
169389## License
170390
171391Apache License Version 2.0
0 commit comments