Skip to content

Commit 4544e6d

Browse files
committed
npm publish
0 parents  commit 4544e6d

28 files changed

+8726
-0
lines changed

.npmignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
demo/
2+
.idea/
3+
support/
4+
*.tar
5+
*.tgz
6+
.npmignore
7+
*.map
8+
*.ts
9+
tsconfig.json
10+
scripts
11+
.DS_Store
12+
*.aar
13+
node_modules
14+
*.esm.json
15+
!extractTGZ.js
16+
*.js.map
17+
*.log
18+
19+
# Editor directories and files
20+
.idea
21+
.vscode

README.md

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
[<img src="https://raw.githubusercontent.com/Yoonit-Labs/nativescript-yoonit-camera/development/logo_cyberlabs.png" width="300">](https://cyberlabs.ai/)
2+
3+
# NativeScript Yoonit Camera
4+
5+
![NativeScript](https://img.shields.io/badge/NativeScript-7-lightgrey.svg?style=for-the-badge&logo=nativescript) ![Version](https://img.shields.io/npm/v/@yoonit/nativescript-camera?color=lightgrey&style=for-the-badge&logo=npm) ![Downloads](https://img.shields.io/npm/dm/@yoonit/nativescript-camera?color=lightgrey&logo=npm&style=for-the-badge)
6+
7+
![Android](https://img.shields.io/badge/Android-YES-lightgrey.svg?style=for-the-badge&logo=android) ![iOS](https://img.shields.io/badge/iOS-YES-lightgrey.svg?style=for-the-badge&logo=apple) ![MIT license](https://img.shields.io/npm/l/@yoonit/nativescript-camera?color=lightgrey&style=for-the-badge)
8+
9+
A NativeScript plugin to provide:
10+
- Modern Android Camera API (Camera X)
11+
- MLKit integration
12+
- Camera preview (Front & Back)
13+
- Face detection (With Min & Max size)
14+
- Landmark detection (Soon)
15+
- Face crop
16+
- Face capture
17+
- Frame capture
18+
- Face ROI
19+
- QR Code scanning
20+
21+
## Installation
22+
23+
```javascript
24+
npm i -s @yoonit/nativescript-camera
25+
```
26+
27+
## Usage
28+
29+
All the functionalities that the `@yoonit/nativescript-camera` provides is accessed through the `YoonitCamera` component, that includes the camera preview. Below we have the basic usage code, for more details, your can see the [**Methods**](#methods), [**Events**](#events) or the [**Demo Vue**](https://github.com/Yoonit-Labs/nativescript-yoonit-camera/tree/development/demo-vue).
30+
31+
#### VueJS Plugin
32+
`main.js`
33+
```javascript
34+
import Vue from 'nativescript-vue'
35+
import YoonitCamera from '@yoonit/nativescript-camera/vue'
36+
37+
Vue.use(YoonitCamera)
38+
```
39+
40+
After that, you can access the camera object in your entire project using `this.$yoo.camera`
41+
42+
#### Vue Component
43+
`App.vue`
44+
```vue
45+
<template>
46+
<Page @loaded="onLoaded">
47+
<YoonitCamera
48+
ref="yooCamera"
49+
@faceDetected="doFaceDetected"
50+
@faceImage="doImageCreated"
51+
@frameImage="doImageCreated"
52+
@endCapture="doEndCapture"
53+
@qrCodeContent="doQRCodeContent"
54+
@status="doStatus"
55+
@permissionDenied="doPermissionDenied"
56+
/>
57+
</Page>
58+
</template>
59+
60+
<script>
61+
export default {
62+
data: () => ({}),
63+
64+
methods: {
65+
async onLoaded(args) {
66+
console.log('[YooCamera] Getting Camera view')
67+
this.$yoo.camera.registerElement(this.$refs.yooCamera)
68+
69+
console.log('[YooCamera] Getting permission')
70+
if (await this.$yoo.camera.requestPermission()) {
71+
console.log('[YooCamera] Permission granted, start preview')
72+
73+
this.$yoo.camera.preview()
74+
}
75+
},
76+
77+
doFaceDetected({ faceDetected }) {
78+
console.log('[YooCamera] faceDetected', faceDetected)
79+
},
80+
81+
doImageCreated({
82+
count,
83+
total,
84+
image: {
85+
path,
86+
source
87+
}
88+
}) {
89+
if (total === 0) {
90+
console.log('[YooCamera] doFaceImage', `[${count}] ${path}`)
91+
} else {
92+
console.log('[YooCamera] doFaceImage', `[${count}] of [${total}] - ${path}`)
93+
}
94+
95+
console.log('[YooCamera] doFaceImage', path, source)
96+
},
97+
98+
doEndCapture() {
99+
console.log('[YooCamera] doEndCapture')
100+
},
101+
102+
doQRCodeContent({ content }) {
103+
console.log('[YooCamera] doQRCodeContent', content)
104+
},
105+
106+
doStatus({ status }) {
107+
console.log('[YooCamera] doStatus', JSON.parse(status))
108+
},
109+
110+
doToggleLens() {
111+
const currentCameraLens = this.$yoo.camera.getLens()
112+
113+
console.log('[YooCamera] doToggleLens', currentCameraLens)
114+
115+
this.$yoo.camera.toggleLens()
116+
},
117+
118+
doStartCapture(captureType) {
119+
console.log('[YooCamera] doStartCapture', captureType)
120+
121+
this.$yoo.camera.startCapture(captureType)
122+
},
123+
124+
doFaceDetectionBox(status) {
125+
console.log('[YooCamera] doFaceDetectionBox', status)
126+
127+
this.$yoo.camera.setFaceDetectionBox(status)
128+
},
129+
130+
doPermissionDenied() {
131+
console.log('[YooCamera] doPermissionDenied')
132+
}
133+
}
134+
}
135+
</script>
136+
```
137+
138+
## API
139+
140+
#### Methods
141+
142+
| Function | Parameters | Valid values | Return Type | Description
143+
| - | - | - | - | -
144+
| **`requestPermission`** | - | - | promise | Ask to user to give the permission to access camera.
145+
| **`hasPermission`** | - | - | boolean | Return if application has camera permission.
146+
| **`preview`** | - | - | void | Start camera preview if has permission.
147+
| **`startCapture`** | `captureType: string` | <ul><li>`"none"`</li><li>`"face"`</li><li>`"barcode"`</li><li>`"frame"`</li></ul> | void | Set capture type none, face, barcode or frame.
148+
| **`stopCapture`** | - | - | void | Stop any type of capture.
149+
| **`toggleLens`** | - | - | void | Set camera lens facing front or back.
150+
| **`getLens`** | - | - | number | Return `number` that represents lens face state: 0 for front 1 for back camera.
151+
| **`setFaceNumberOfImages`** | `faceNumberOfImages: number` | Any positive `number` value | void | Default value is 0. For value 0 is saved infinity images. When saved images reached the "face number os images", the `onEndCapture` is triggered.
152+
| **`setFaceDetectionBox`** | `faceDetectionBox: boolean` | `true` or `false` | void | Set to show face detection box when face detected.
153+
| **`setFaceTimeBetweenImages`** | `faceTimeBetweenImages: number` | Any positive `number` that represent time in milli seconds | void | Set saving face images time interval in milli seconds.
154+
| **`setFacePaddingPercent`** | `facePaddingPercent: number` | Any positive `number` value | void | Set face image and bounding box padding in percent.
155+
| **`setFaceImageSize`** | `faceImageSize: number` | Any positive `number` value | void | Set face image size to be saved.
156+
| **`setFaceCaptureMinSize`** | `faceCaptureMinSize: number` | Value between `0` and `1`. Represents the percentage. | void | Set the minimum face capture related by percentage with the screen width.
157+
| **`setFaceCaptureMaxSize`** | `faceCaptureMaxSize: number` | Value between `0` and `1`. Represents the percentage. | void | Set the maximum face capture related by percentage with the screen width.
158+
| **`setFrameNumberOfImages`** | `frameNumberOfImages: number` | Any positive `number` value | void | Default value is 0. For value 0 is saved infinity images. When saved images reached the "frame number os images", the `onEndCapture` is triggered.
159+
| **`setFrameTimeBetweenImages`** | `frameTimeBetweenImages: number` | Any positive `number` that represent time in milli seconds | void | Set saving frame images time interval in milli seconds.
160+
| **`setFaceSaveImages`** | `faceSaveImages: boolean` | `true` or `false` | void | Set to enable/disable face save images when capturing faces.
161+
| **`setFaceROIEnable`** | `faceROIEnable: boolean` | `true` or `false` | void | Enable/disable face region of interest capture.
162+
| **`setFaceROIOffset`** | `topOffset: number, rightOffset: number,bottomOffset: number, leftOffset: number` | Values between `0` and `1`. Represents the percentage. | void | <ul><li>topOffset: "Above" the face detected.</li><li>rightOffset: "Right" of the face detected.</li><li>bottomOffset: "Bottom" of the face detected.</li><li>leftOffset: "Left" of the face detected.</li></ul>
163+
| **`setFaceROIMinSize`** | `minimumSize: number` | Values between `0` and `1`. Represents the percentage. | void | Set the minimum face size related with the region of interest.
164+
165+
#### Events
166+
167+
| Event | Parameters | Description
168+
| - | - | -
169+
| faceImage | `{ count: number, total: number, image: object = { path: string, source: blob } }` | Must have started capture type of face. Emitted when the face image file is created: <ul><li>count: current index</li><li>total: total to create</li><li>image.path: the face image path</li><li>image.source: the blob file</li><ul>
170+
| frameImage | `{ count: number, total: number, image: object = { path: string, source: blob } }` | Must have started capture type of frame. Emitted when the frame image file is created: <ul><li>count: current index</li><li>total: total to create</li><li>image.path: the frame image path</li><li>image.source: the blob file</li><ul>
171+
| faceDetected | `{ x: number, y: number, width: number, height: number }` | Must have started capture type of face. Emit the detected face bounding box. Emit all parameters null if no more face detecting.
172+
| endCapture | - | Must have started capture type of face or frame. Emitted when the number of face or frame image files created is equal of the number of images set (see the method `setFaceNumberOfImages` for face and `setFrameNumberOfImages`for frame).
173+
| qrCodeContent | `{ content: string }` | Must have started capture type of barcode (see `startCapture`). Emitted when the camera scan a QR Code.
174+
| status | `{ type: 'error'/'message', status: string }` | Emit message error from native. Used more often for debug purpose.
175+
| permissionDenied | - | Emit when try to `preview` but there is not camera permission.
176+
177+
### KeyError
178+
179+
Pre-define key error constants used by the `onError`event.
180+
181+
| KeyError | Description
182+
| - | -
183+
| NOT_STARTED_PREVIEW | Tried to start a process that depends on to start the camera preview.
184+
| INVALID_CAPTURE_TYPE | Tried to start a non-existent capture type.
185+
| INVALID_FACE_NUMBER_OF_IMAGES | Tried to input invalid face number of images to capture.
186+
| INVALID_FACE_TIME_BETWEEN_IMAGES | Tried to input invalid face time interval to capture face.
187+
| INVALID_FACE_PADDING_PERCENT | Tried to input invalid face padding percent.
188+
| INVALID_FACE_IMAGE_SIZE | Tried to input invalid image width or height.
189+
| INVALID_FACE_CAPTURE_MIN_SIZE | Tried to input invalid face capture minimum size.
190+
| INVALID_FACE_CAPTURE_MAX_SIZE | Tried to input invalid face capture maximum size.
191+
| INVALID_FRAME_NUMBER_OF_IMAGES | Tried to input invalid frame number of images to capture.
192+
| INVALID_FRAME_TIME_BETWEEN_IMAGES | Tried to input invalid frame time interval to capture face.
193+
| INVALID_FACE_ROI_OFFSET | Tried to input invalid face region of interest offset.
194+
| INVALID_FACE_ROI_MIN_SIZE | Tried to input invalid face region of interest minimum size.
195+
196+
### Message
197+
198+
Pre-define message constants used by the `onMessage` event.
199+
200+
| Message | Description
201+
| - | -
202+
| INVALID_CAPTURE_FACE_MIN_SIZE | Face width percentage in relation of the screen width is less than the setted (`setFaceCaptureMinSize`).
203+
| INVALID_CAPTURE_FACE_MAX_SIZE | Face width percentage in relation of the screen width is more than the setted (`setFaceCaptureMaxSize`).
204+
| INVALID_CAPTURE_FACE_OUT_OF_ROI | Face bounding box is out of the setted region of interest (`setFaceROIOffset`).
205+
| INVALID_CAPTURE_FACE_ROI_MIN_SIZE | Face width percentage in relation of the screen width is less than the setted (`setFaceROIMinSize`).
206+
207+
## To contribute and make it better
208+
209+
Clone the repo, change what you want and send PR.
210+
211+
Contributions are always welcome!
212+
213+
---
214+
215+
Code with ❤ by the [**Cyberlabs AI**](https://cyberlabs.ai/) Front-End Team

Yoonit.Camera.android.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { CameraBase } from './Yoonit.Camera.common';
2+
export declare class YoonitCamera extends CameraBase {
3+
nativeView: ai.cyberlabs.yoonit.camera.CameraView;
4+
createNativeView(): Object;
5+
initNativeView(): void;
6+
disposeNativeView(): void;
7+
requestPermission(explanation?: string): Promise<boolean>;
8+
hasPermission(): boolean;
9+
startCapture(captureType: string): void;
10+
setFaceNumberOfImages(faceNumberOfImages: number): void;
11+
setFaceDetectionBox(faceDetectionBox: boolean): void;
12+
setFaceSaveImages(faceSaveImages: boolean): void;
13+
setFaceTimeBetweenImages(faceTimeBetweenImages: number): void;
14+
setFacePaddingPercent(facePaddingPercent: number): void;
15+
setFaceImageSize(width: number, height: number): void;
16+
setFaceCaptureMinSize(faceCaptureMinSize: number): void;
17+
setFaceCaptureMaxSize(faceCaptureMaxSize: number): void;
18+
setFrameNumberOfImages(frameNumberOfImages: number): void;
19+
setFrameTimeBetweenImages(frameTimeBetweenImages: number): void;
20+
setFaceROIEnable(faceROIEnable: boolean): void;
21+
setFaceROIOffset(topOffset: number, rightOffset: number, bottomOffset: number, leftOffset: number): void;
22+
setFaceROIMinSize(minimumSize: boolean): void;
23+
}

0 commit comments

Comments
 (0)