diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..e709e0b --- /dev/null +++ b/.npmignore @@ -0,0 +1,21 @@ +demo/ +.idea/ +support/ +*.tar +*.tgz +.npmignore +*.map +*.ts +tsconfig.json +scripts +.DS_Store +*.aar +node_modules +*.esm.json +!extractTGZ.js +*.js.map +*.log + +# Editor directories and files +.idea +.vscode diff --git a/README.md b/README.md new file mode 100644 index 0000000..61c90bc --- /dev/null +++ b/README.md @@ -0,0 +1,319 @@ + +[](https://cyberlabs.ai/) + +# NativeScript Yoonit Camera + +![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) + +![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) + +A NativeScript plugin to provide: +- Modern Android Camera API [Camera X](https://developer.android.com/training/camerax) +- Camera preview (Front & Back) +- [PyTorch](https://pytorch.org/mobile/home/) integration (Android) +- Computer vision pipeline +- Face detection, capture and image crop +- Understanding of the human face +- Frame capture +- Capture timed images +- QR Code scanning + +> ### More about... +> +> The plugin's core is the native layer. Every change in the native layer, reflects here. This plugin, the Yoonit Camera, we can say that is an aggregation of many Yoonit's native libs: +> * [Android Yoonit Camera](https://github.com/Yoonit-Labs/android-yoonit-camera): Android core camera lib; +> * [iOS Yoonit Camera](https://github.com/Yoonit-Labs/ios-yoonit-camera): iOS core camera lib; +> * [Android Yoonit Facefy](https://github.com/Yoonit-Labs/android-yoonit-facefy): Android face detection and analysis; +> * [iOS Yoonit Facefy](https://github.com/Yoonit-Labs/ios-yoonit-facefy): iOS face detection and analysis; +> +> All this native libs can be used independently. + +## Table Of Contents + +* [Installation](#installation) +* [Usage](#usage) + * [VueJS Plugin](#vuejs-plugin) + * [Vue Component](#vue-component) +* [API](#api) + * [Props](#props) + * [Methods](#methods) + * [Events](#events) + * [Face Analysis](#face-analysis) + * [Head Movements](#head-movements) + * [Messages](#messages) +* [Contribute](#contribute-and-make-it-better) + +## Installation + +```javascript +npm i -s @yoonit/nativescript-camera +``` + +## Usage + +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). + +#### VueJS Plugin +`main.js` +```javascript +import Vue from 'nativescript-vue' +import YoonitCamera from '@yoonit/nativescript-camera/vue' + +Vue.use(YoonitCamera) +``` + +After that, you can access the camera object in your entire project using `this.$yoo.camera` + +#### Vue Component + +`App.vue` + +```vue + + + +``` + +## API + +#### Props + +| Props | Input/Format | Default value | Description | +| - | - | - | - | +| lens | `"front"` or `"back"` | `"front"` | The camera lens to use "front" or "back". | +| captureType | `"none"`, `"front"`, `"frame"` or `"qrcode"` | `"none"` | The capture type of the camera. | +| imageCapture | `boolean` | `false` | Enable/disabled save image capture. | +| imageCaptureAmount | `number` | `0` | The image capture amount goal. | +| imageCaptureInterval | `number` | `1000` | The image capture time interval in milliseconds. | +| imageCaptureWidth | `"NNpx"` | `"200px"` | The image capture width in pixels. | +| imageCaptureHeight | `"NNpx"` | `"200px"` | The image capture height in pixels. | +| colorEncoding | `"RGB"` or `"YUV"` | `"RGB"` | Only for android. The image capture color encoding type: `"RGB"` or `"YUV"`. | +| detectionBox | `boolean` | `false` | Show/hide the face detection box. +| detectionBoxColor | `string` | `#ffffff` | Set detection box color. | +| detectionMinSize | `"NN%"` | `"0%"` | The face minimum size percentage to capture. | +| detectionMaxSize | `"NN%"` | `"100%"` | The face maximum size percentage to capture. | +| roi | `boolean` | `false` | Enable/disable the region of interest capture. | +| roiTopOffset | `"NN%"` | `"0%"` | Distance in percentage of the top face bounding box with the top of the camera preview. | +| roiRightOffset | `"NN%"` | `"0%"` | Distance in percentage of the right face bounding box with the right of the camera preview. | +| roiBottomOffset | `"NN%"` | `"0%"` | Distance in percentage of the bottom face bounding box with the bottom of the camera preview. | +| roiLeftOffset | `"NN%"` | `"0%"` | Distance in percentage of the left face bounding box with the left of the camera preview. | +| roiAreaOffset | `boolean` | `false` | Enable/disable display of the region of interest area offset. | +| roiAreaOffsetColor | `string` | `'#ffffff73'` | Set display of the region of interest area offset color. | +| faceContours | `boolean` | `false` | Enable/disable display list of points on a detected face. | +| faceContoursColor | `string` | `'#FFFFFF'` | Set face contours color. | +| computerVision (`Android Only`) | `boolean` | `false` | Enable/disable computer vision model. | +| torch | `boolean` | `false` | Enable/disable device torch. Available only to camera lens `"back"`. | + +#### Methods + +| Function | Parameters | Valid values | Return Type | Description | +| - | - | - | - | - | +| requestPermission | - | - | promise | Ask the user to give the permission to access camera. | +| hasPermission | - | - | boolean | Return if application has camera permission. | +| preview | - | - | void | Start camera preview if has permission. | +| startCapture | `type: string` | | void | Set capture type "none", "face", "qrcode" or "frame". Default value is `"none"`. | +| stopCapture | - | - | void | Stop any type of capture. | +| destroy | - | - | void | Destroy preview. | +| toggleLens | - | - | void | Toggle camera lens facing "front"/"back". | +| setCameraLens | `lens: string` | `"front"` or `"back"` | void | Set camera to use "front" or "back" lens. Default value is `"front"`. | +| getLens | - | - | string | Return "front" or "back". | +| setImageCapture | `enable: boolean` | `true` or `false` | void | Enable/disabled save image capture. Default value is `false`. | +| setImageCaptureAmount | `amount: Int` | Any positive `Int` value | void | For value `0`, save infinity images. When the capture image amount is reached, the event `onEndCapture` is triggered. Default value is `0`. | +| setImageCaptureInterval | `interval: number` | Any positive number that represent time in milliseconds | void | Set the image capture time interval in milliseconds. | +| setImageCaptureWidth | `width: string` | Value format must be in `NNpx` | void | Set the image capture width in pixels. | +| setImageCaptureHeight | `height: string` | Value format must be in `NNpx` | void | Set the image capture height in pixels. | +| setImageCaptureColorEncoding | `colorEncoding: string` | `"YUV"` or `"RGB"` | void | Only for android. Set the image capture color encoding type: `"RGB"` or `"YUV"`. | +| setDetectionBox | `enable: boolean` | `true` or `false` | void | Set to show/hide the face detection box. | +| setDetectionBoxColor | `color: string` | hexadecimal | void | Set detection box color. | +| setFacePaddingPercent | `percentage: string` | Value format must be in `NN%` | void | Set face image capture and detection box padding in percentage. | +| setDetectionMinSize | `percentage: string` | Value format must be in `NN%` | void | Set the face minimum size percentage to capture. | +| setDetectionMaxSize | `percentage: string` | Value format must be in `NN%` | void | Set the face maximum size percentage to capture. | +| setROI | `enable: boolean` | `true` or `false` | void | Enable/disable face region of interest capture. | +| setROITopOffset | `percentage: string` | Value format must be in `NN%` | void | Distance in percentage of the top face bounding box with the top of the camera preview. | +| setROIRightOffset | `percentage: string` | Value format must be in `NN%` | void | Distance in percentage of the right face bounding box with the right of the camera preview. | +| setROIBottomOffset | `percentage: string` | Value format must be in `NN%` | void | Distance in percentage of the bottom face bounding box with the bottom of the camera preview. | +| setROILeftOffset | `percentage: string` | Value format must be in `NN%` | void | Distance in percentage of the left face bounding box with the left of the camera preview. | +| setROIMinSize | `percentage: string` | Value format must be in `NN%` | void | Set the minimum face size related within the ROI. | +| setROIAreaOffset | `enable: boolean` | `true` or `false` | void | Enable/disable display of the region of interest area offset. | +| setROIAreaOffsetColor | `color: string` | Hexadecimal color | void | Set display of the region of interest area offset color. | +| setFaceContours | `enable: boolean` | `true` or `false` | void | Enable/disable display list of points on a detected face. | +| setFaceContoursColor | `color: string` | Hexadecimal color | void | Set face contours color. | +| setComputerVision (`Android Only`) | `enable: boolean` | `true` or `false` | void | Enable/disable computer vision model. | +| setComputerVisionLoadModels (`Android Only`) | `modelPaths: Array` | Valid system path file to a PyTorch computer vision model | void | Set model to be used when image is captured. To se more about it, Click Here. | +| computerVisionClearModels (`Android Only`) | - | - | void | Clear models that was previous added using `setComputerVisionLoadModels`. | +| setTorch | `enable: boolean` | `true` or `false` | void | Enable/disable device torch. Available only to camera lens `"back"`. | + +#### Events + +| Event | Parameters | Description +| - | - | - +| imageCaptured | `{ type: string, count: number, total: number, image: object = { path: string, source: any, binary: any }, inferences: [{ ['model name']: model output }], darkness: number, lightness: number, sharpness: number }` | Must have started capture type of face/frame. Emitted when the face image file saved: