Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@yoonit/nativescript-camera

Package Overview
Dependencies
Maintainers
10
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@yoonit/nativescript-camera

Yoonit Camera have a custom view that shows a preview layer of the front/back camera and detects human faces in it and read qr code.

  • 1.8.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30
increased by400%
Maintainers
10
Weekly downloads
 
Created
Source

NativeScript Yoonit Camera

NativeScript Version Downloads

Android iOS MIT license

A NativeScript plugin to provide:

  • Modern Android Camera API (Camera X)
  • MLKit integration
  • Camera preview (Front & Back)
  • Face detection (With Min & Max size)
  • Landmark detection (Soon)
  • Face crop
  • Face capture
  • Frame capture
  • Face ROI
  • QR Code scanning

Installation

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, Events or the Demo Vue.

VueJS Plugin

main.js

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

<template>
  <Page @loaded="onLoaded">
    <YoonitCamera
      ref="yooCamera"
      @faceDetected="doFaceDetected"
      @faceImage="doImageCreated"
      @frameImage="doImageCreated"
      @endCapture="doEndCapture"
      @qrCodeContent="doQRCodeContent"
      @status="doStatus"
      @permissionDenied="doPermissionDenied"
    />
  </Page>
</template>

<script>
  export default {
    data: () => ({}),

    methods: {
      async onLoaded(args) {
        console.log('[YooCamera] Getting Camera view')
        this.$yoo.camera.registerElement(this.$refs.yooCamera)

        console.log('[YooCamera] Getting permission')
        if (await this.$yoo.camera.requestPermission()) {
          console.log('[YooCamera] Permission granted, start preview')

          this.$yoo.camera.preview()
        }
      },

      doFaceDetected({ faceDetected }) {
        console.log('[YooCamera] faceDetected', faceDetected)
      },

      doImageCreated({
        count,
        total,
        image: {
          path,
          source
        }
      }) {
        if (total === 0) {
          console.log('[YooCamera] doFaceImage', `[${count}] ${path}`)
        } else {
          console.log('[YooCamera] doFaceImage', `[${count}] of [${total}] - ${path}`)
        }

        console.log('[YooCamera] doFaceImage', path, source)
      },

      doEndCapture() {
        console.log('[YooCamera] doEndCapture')
      },

      doQRCodeContent({ content }) {
        console.log('[YooCamera] doQRCodeContent', content)
      },

      doStatus({ status }) {
        console.log('[YooCamera] doStatus', JSON.parse(status))
      },

      doToggleLens() {
        const currentCameraLens = this.$yoo.camera.getLens()

        console.log('[YooCamera] doToggleLens', currentCameraLens)

        this.$yoo.camera.toggleLens()
      },

      doStartCapture(captureType) {
        console.log('[YooCamera] doStartCapture', captureType)

        this.$yoo.camera.startCapture(captureType)
      },

      doFaceDetectionBox(status) {
        console.log('[YooCamera] doFaceDetectionBox', status)

        this.$yoo.camera.setFaceDetectionBox(status)
      },

      doPermissionDenied() {
        console.log('[YooCamera] doPermissionDenied')
      }
    }
  }
</script>

API

Methods
FunctionParametersValid valuesReturn TypeDescription
requestPermission--promiseAsk to user to give the permission to access camera.
hasPermission--booleanReturn if application has camera permission.
preview--voidStart camera preview if has permission.
startCapturecaptureType: string
  • "none"
  • "face"
  • "barcode"
  • "frame"
voidSet capture type none, face, barcode or frame.
stopCapture--voidStop any type of capture.
toggleLens--voidSet camera lens facing front or back.
getLens--numberReturn number that represents lens face state: 0 for front 1 for back camera.
setFaceNumberOfImagesfaceNumberOfImages: numberAny positive number valuevoidDefault value is 0. For value 0 is saved infinity images. When saved images reached the "face number os images", the onEndCapture is triggered.
setFaceDetectionBoxfaceDetectionBox: booleantrue or falsevoidSet to show face detection box when face detected.
setFaceTimeBetweenImagesfaceTimeBetweenImages: numberAny positive number that represent time in milli secondsvoidSet saving face images time interval in milli seconds.
setFacePaddingPercentfacePaddingPercent: numberAny positive number valuevoidSet face image and bounding box padding in percent.
setFaceImageSizefaceImageSize: numberAny positive number valuevoidSet face image size to be saved.
setFaceCaptureMinSizefaceCaptureMinSize: numberValue between 0 and 1. Represents the percentage.voidSet the minimum face capture related by percentage with the screen width.
setFaceCaptureMaxSizefaceCaptureMaxSize: numberValue between 0 and 1. Represents the percentage.voidSet the maximum face capture related by percentage with the screen width.
setFrameNumberOfImagesframeNumberOfImages: numberAny positive number valuevoidDefault value is 0. For value 0 is saved infinity images. When saved images reached the "frame number os images", the onEndCapture is triggered.
setFrameTimeBetweenImagesframeTimeBetweenImages: numberAny positive number that represent time in milli secondsvoidSet saving frame images time interval in milli seconds.
setFaceSaveImagesfaceSaveImages: booleantrue or falsevoidSet to enable/disable face save images when capturing faces.
setFaceROIEnablefaceROIEnable: booleantrue or falsevoidEnable/disable face region of interest capture.
setFaceROIOffsettopOffset: number, rightOffset: number,bottomOffset: number, leftOffset: numberValues between 0 and 1. Represents the percentage.void
  • topOffset: "Above" the face detected.
  • rightOffset: "Right" of the face detected.
  • bottomOffset: "Bottom" of the face detected.
  • leftOffset: "Left" of the face detected.
setFaceROIMinSizeminimumSize: numberValues between 0 and 1. Represents the percentage.voidSet the minimum face size related with the region of interest.
Events
EventParametersDescription
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:
  • count: current index
  • total: total to create
  • image.path: the face image path
  • image.source: the blob file
    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:
    • count: current index
    • total: total to create
    • image.path: the frame image path
    • image.source: the blob file
      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.
      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 setFrameNumberOfImagesfor frame).
      qrCodeContent{ content: string }Must have started capture type of barcode (see startCapture). Emitted when the camera scan a QR Code.
      status{ type: 'error'/'message', status: string }Emit message error from native. Used more often for debug purpose.
      permissionDenied-Emit when try to preview but there is not camera permission.

      KeyError

      Pre-define key error constants used by the onErrorevent.

      KeyErrorDescription
      NOT_STARTED_PREVIEWTried to start a process that depends on to start the camera preview.
      INVALID_CAPTURE_TYPETried to start a non-existent capture type.
      INVALID_FACE_NUMBER_OF_IMAGESTried to input invalid face number of images to capture.
      INVALID_FACE_TIME_BETWEEN_IMAGESTried to input invalid face time interval to capture face.
      INVALID_FACE_PADDING_PERCENTTried to input invalid face padding percent.
      INVALID_FACE_IMAGE_SIZETried to input invalid image width or height.
      INVALID_FACE_CAPTURE_MIN_SIZETried to input invalid face capture minimum size.
      INVALID_FACE_CAPTURE_MAX_SIZETried to input invalid face capture maximum size.
      INVALID_FRAME_NUMBER_OF_IMAGESTried to input invalid frame number of images to capture.
      INVALID_FRAME_TIME_BETWEEN_IMAGESTried to input invalid frame time interval to capture face.
      INVALID_FACE_ROI_OFFSETTried to input invalid face region of interest offset.
      INVALID_FACE_ROI_MIN_SIZETried to input invalid face region of interest minimum size.

      Message

      Pre-define message constants used by the onMessage event.

      MessageDescription
      INVALID_CAPTURE_FACE_MIN_SIZEFace width percentage in relation of the screen width is less than the setted (setFaceCaptureMinSize).
      INVALID_CAPTURE_FACE_MAX_SIZEFace width percentage in relation of the screen width is more than the setted (setFaceCaptureMaxSize).
      INVALID_CAPTURE_FACE_OUT_OF_ROIFace bounding box is out of the setted region of interest (setFaceROIOffset).
      INVALID_CAPTURE_FACE_ROI_MIN_SIZEFace width percentage in relation of the screen width is less than the setted (setFaceROIMinSize).

      To contribute and make it better

      Clone the repo, change what you want and send PR.

      Contributions are always welcome!


      Code with ❤ by the Cyberlabs AI Front-End Team

      Keywords

      FAQs

      Package last updated on 27 Nov 2020

      Did you know?

      Socket

      Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

      Install

      Related posts

      SocketSocket SOC 2 Logo

      Product

      • Package Alerts
      • Integrations
      • Docs
      • Pricing
      • FAQ
      • Roadmap
      • Changelog

      Packages

      npm

      Stay in touch

      Get open source security insights delivered straight into your inbox.


      • Terms
      • Privacy
      • Security

      Made with ⚡️ by Socket Inc