YoonitCamera

The most advanced and modern Camera module for iOS with a lot of awesome features

Showing:

Popularity

Downloads/wk

0

GitHub Stars

55

Maintenance

Last Commit

4d ago

Contributors

1

Package

Dependencies

1

License

MIT

Categories

Readme

ios-yoonit-camera

GitHub tag (latest by date) GitHub

A iOS plugin to provide:

  • Camera preview (Front & Back)
  • Yoonit Facefy integration
  • PyTorch integration (Soon)
  • Computer vision pipeline (Soon)
  • Face detection, capture and image crop
  • Understanding of the human face
  • Frame capture
  • Capture timed images
  • QR Code scanning

Table of Contents

Installation

Add the following line to your Podfile file:

pod 'YoonitCamera'

And run in the root of your project:

pod install

Usage

All the functionalities that the ios-yoonit-camera provides is accessed through the CameraView, that includes the camera preview. See an example how we use in our Demo.

Below we have the basic usage code, for more details, see the API section.

Camera Preview

@IBOutlet var cameraView: CameraView!

Do not forget request camera permission. Start camera preview:

self.cameraView.startPreview()

Start capturing face images

With camera preview, we can start capture detected face and generate images:

self.cameraView.startCaptureType("face")

Set camera event listener to get the result:

class YourViewController: UIViewController, CameraEventListenerDelegate {
    ...
    self.cameraView.cameraEventListener = self
    ...
    func onImageCaptured(
        _ type: String, 
        _ count: Int, 
        _ total: Int, 
        _ imagePath: String,
        _ darkness: NSNumber?,
        _ lightness: NSNumber?,
        _ sharpness: NSNumber?
    ) {
        // YOUR CODE
    }
    
    func onFaceDetected(
        _ x: Int, 
        _ y: Int, 
        _ width: Int, 
        _ height: Int, 
        _ leftEyeOpenProbability: NSNumber?, 
        _ rightEyeOpenProbability: NSNumber?, 
        _ smilingProbability: NSNumber?, 
        _ headEulerAngleX: NSNumber?, 
        _ headEulerAngleY: NSNumber?, 
        _ headEulerAngleZ: NSNumber?
    ) {
        // YOUR CODE
    }
    ...
}

Start scanning QR Codes

With camera preview, we can start scanning QR codes:

self.cameraView.startCaptureType("qrcode")

Set camera event listener to get the result:

class YourViewController: UIViewController, CameraEventListenerDelegate {
    ...
    self.cameraView.cameraEventListener = self
    ...
    func onQRCodeScanned(content: String) {
        // YOUR CODE
    }
}

API

Variables

VariableTypeDefault ValueDescription
detectionTopSizeFloat'0.0'Represents the percentage. Positive value enlarges and negative value reduce the top side of the detection. Use the setDetectionBox to have a visual result.
detectionRightSizeFloat'0.0'Represents the percentage. Positive value enlarges and negative value reduce the right side of the detection. Use the setDetectionBox to have a visual result.
detectionBottomSizeFloat'0.0'Represents the percentage. Positive value enlarges and negative value reduce the bottom side of the detection. Use the setDetectionBox to have a visual result.
detectionLeftSizeFloat'0.0'Represents the percentage. Positive value enlarges and negative value reduce the left side of the detection. Use the setDetectionBox to have a visual result.

Methods

FunctionParametersValid valuesReturn TypeDescription
startPreview--voidStart camera preview if has permission.
startCaptureTypecaptureType: String
  • "none"
  • "face"
  • "qrcode"
  • "frame"
voidSet capture type none, face, QR Code or frame.
stopCapture--voidStop any type of capture.
destroy--voidDestroy camera preview.
toggleCameraLens--voidToggle camera lens facing front/back.
setCameraLenscameraLens: String
  • "front"
  • "back"
voidSet camera to use "front" or "back" lens. Default value is "front".
getCameraLens--StringReturn "front" or "back".
setNumberOfImagesnumberOfImages: IntAny positive Int valuevoidDefault value is 0. For value 0 is saved infinity images. When saved images reached the "number os images", the onEndCapture is triggered.
setTimeBetweenImagestimeBetweenImages: Int64Any positive number that represent time in milli secondsvoidSet saving face/frame images time interval in milli seconds.
setOutputImageWidthwidth: IntAny positive number value that represents in pixelsvoidSet face image width to be created in pixels.
setOutputImageHeightheight: IntAny positive number value that represents in pixelsvoidSet face image height to be created in pixels.
setSaveImageCapturedenable: Booltrue or falsevoidSet to enable/disable save image when capturing face and frame.
setDetectionBoxenable: Booltrue or falsevoidSet to enable/disable detection box when face/qrcode detected. The detection box is the the face/qrcode bounding box normalized to UI.
setDetectionBoxColoralpha: Float, red: Float, green: Float, blue: FloatValue between 0 and 1voidSet detection box ARGB color. Default value is (0.4, 1.0, 1.0, 1.0).
setDetectionMinSizeminimumSize: FloatValue between 0 and 1. Represents the percentage.voidSet face/qrcode minimum size to detect in percentage related with the camera preview.
setDetectionMaxSizemaximumSize: FloatValue between 0 and 1. Represents the percentage.voidSet face/qrcode maximum size to detect in percentage related with the camera preview.
setFaceContoursenable: Booltrue or falsevoidSet to enable/disable face contours when face detected.
setFaceContoursColoralpha: Float, red: Float, green: Float, blue: FloatValue between 0 and 1voidSet face contours ARGB color. Default value is (0.4, 1.0, 1.0, 1.0).
setROIenable: Booltrue or falsevoidEnable/disable the region of interest capture.
setROITopOffsettopOffset: FloatValue between 0 and 1. Represents the percentage.voidCamera preview top distance in percentage.
setROIRightOffsetrightOffset: FloatValue between 0 and 1. Represents the percentage.voidCamera preview right distance in percentage.
setROIBottomOffsetbottomOffset: FloatValue between 0 and 1. Represents the percentage.voidCamera preview bottom distance in percentage.
setROILeftOffsetleftOffset: FloatValue between 0 and 1. Represents the percentage.voidCamera preview left distance in percentage.
setROIAreaOffsetenable: Booltrue or falsevoidSet to enable/disable region of interest offset visibility.
setROIAreaOffsetColoralpha: Float, red: Float, green: Float, blue: FloatValue between 0 and 1voidSet face region of interest area offset color. Default value is (0.4, 1.0, 1.0, 1.0).
setTorchenable: Booltrue or falsevoidSet to enable/disable the device torch. Available only to camera lens "back".

Events

EventParametersDescription
onImageCapturedtype: String, count: Int, total: Int, imagePath: String, darkness: NSNumber?, lightness: NSNumber?, sharpness: NSNumber?Must have started capture type of face/frame (see startCaptureType). Emitted when the image file is created:
  • type: '"face"' or '"frame"'
  • count: current index
  • total: total to create
  • imagePath: the image path
  • inferences: each array element is the image inference result.
  • darkness: image darkness classification.
  • lightness: image lightness classification.
  • sharpness: image sharpness classification.
    onFaceDetectedx: Int, y: Int, width: Int, height: Int, leftEyeOpenProbability: NSNumber?, rightEyeOpenProbability: NSNumber?, smilingProbability: NSNumber?, headEulerAngleX: NSNumber?, headEulerAngleY: NSNumber?, headEulerAngleZ: NSNumber?Must have started capture type of face. Emit the face analysis
    onFaceUndetected-Must have started capture type of face. Emitted after onFaceDetected, when there is no more face detecting.
    onEndCapture-Must have started capture type of face/frame. Emitted when the number of image files created is equal of the number of images set (see the method setNumberOfImages).
    onQRCodeScannedcontent: StringMust have started capture type of qrcode (see startCaptureType). Emitted when the camera scan a QR Code.
    onErrorerror: StringEmit message error.
    onMessagemessage: StringEmit message.
    onPermissionDenied-Emit when try to startPreview but there is not camera permission.

    Face Analysis

    The face analysis is the response send by the onFaceDetected. Here we specify all the parameters.

    AttributeTypeDescription
    xIntThe x position of the face in the screen.
    yIntThe y position of the face in the screen.
    widthIntThe width position of the face in the screen.
    heightIntThe height position of the face in the screen.
    leftEyeOpenProbabilityNSNumber?The left eye open probability.
    rightEyeOpenProbabilityNSNumber?The right eye open probability.
    smilingProbabilityNSNumber?The smiling probability.
    headEulerAngleXNSNumber?The angle in degrees that indicate the vertical head direction. See Head Movements
    headEulerAngleYNSNumber?The angle in degrees that indicate the horizontal head direction. See Head Movements
    headEulerAngleZNSNumber?The angle in degrees that indicate the tilt head direction. See Head Movements

    Head Movements

    Here we explaining the above gif and how reached the "results". Each "movement" (vertical, horizontal and tilt) is a state, based in the angle in degrees that indicate head direction;

    Head DirectionAttributev < -36°-36° < v < -12°-12° < v < 12°12° < v < 36°36° < v
    VerticalheadEulerAngleXSuper DownDownFrontalUpSuper Up
    HorizontalheadEulerAngleYSuper LeftLeftFrontalRightSuper Right
    TiltheadEulerAngleZSuper RightRightFrontalLeftSuper Left

    Image Quality

    The image quality is the classification of the three attributes: darkness, lightness and sharpness. Result available in the onImageCaptured event. Let's see each parameter specifications:

    ThresholdClassification
    Darkness
    darkness > 0.7Too dark
    darkness <= 0.7Acceptable
    Lightness
    lightness > 0.65Too light
    lightness <= 0.65Acceptable
    Sharpness
    sharpness >= 0.1591Blurred
    sharpness < 0.1591Acceptable

    KeyError

    Pre-define key error used by the onError event.

    KeyErrorDescription
    INVALID_CAPTURE_TYPETried to start a non-existent capture type.
    INVALID_CAMERA_LENSTried to input invalid camera lens.
    INVALID_NUMBER_OF_IMAGESTried to input invalid face/frame number of images to capture.
    INVALID_TIME_BETWEEN_IMAGESTried to input invalid face time interval to capture face.
    INVALID_OUTPUT_IMAGE_WIDTHTried to input invalid image width.
    INVALID_OUTPUT_IMAGE_HEIGHTTried to input invalid image height.
    INVALID_DETECTION_BOX_COLORTried to input invalid detection box ARGB value color.
    INVALID_MINIMUM_SIZETried to input invalid minimum size.
    INVALID_MAXIMUM_SIZETried to input invalid maximum size.
    INVALID_ROI_TOP_OFFSETTried to input invalid region of interest top offset.
    INVALID_ROI_RIGHT_OFFSETTried to input invalid region of interest right offset.
    INVALID_ROI_BOTTOM_OFFSETTried to input invalid region of interest bottom offset.
    INVALID_ROI_LEFT_OFFSETTried to input invalid region of interest left offset.
    INVALID_ROI_COLORTried to input invalid region of interest area offset ARGB value color.
    INVALID_FACE_CONTOURS_COLORTried to input invalid face contour ARGB value color.

    Message

    Pre-define key messages used by the onMessage event.

    MessageDescription
    INVALID_MINIMUM_SIZEFace/QRCode width percentage in relation of the screen width is less than the set (setDetectionMinSize).
    INVALID_MAXIMUM_SIZEFace/QRCode width percentage in relation of the screen width is more than the set (setDetectionMaxSize).
    INVALID_OUT_OF_ROIFace bounding box is out of the set region of interest (setROI).
    INVALID_TORCH_LENS_USAGETorch not available with camera lens "front" (setTorch).

    To contribute and make it better

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

    For commit messages we use Conventional Commits.

    Contributions are always welcome!


    Code with ❤ by the Cyberlabs AI Front-End Team

    Rate & Review

    Great Documentation0
    Easy to Use0
    Performant0
    Highly Customizable0
    Bleeding Edge0
    Responsive Maintainers0
    Poor Documentation0
    Hard to Use0
    Slow0
    Buggy0
    Abandoned0
    Unwelcoming Community0
    100