SwiftMaskDetection 0.1.1

SwiftMaskDetection 0.1.1

Keith Ito 维护。



  • Keith Ito

SwiftMaskDetection

CI Status Version License Platform

SwiftMaskDetection 是一个用 Swift 编写的口罩检测库。

它将 AIZOO 的 FaceMaskDetection 模型 转换为 CoreML,并提供一个 Swift 接口,以便在 iOS 应用中轻松使用。

该模型使用 convert.py 脚本 转换为 CoreML。它在最新的 iPhone 和 iPad 上运行超过 30fps。有关模型和训练数据的更多信息,请参阅 https://github.com/AIZOOTech/FaceMaskDetection

使用方法

图片

要识别图像

import SwiftMaskDetection

let detector = MaskDetector()
let image = UIImage(named: "my_photo")!
if let results = try? detector.detectMasks(cgImage: image.cgImage!) {
  // Do something with the results.
}

图像必须是 260x260 像素。`detectMasks` 支持 `CGImage`、`CIImage` 和 `CVPixelBuffer` 输入,并返回一个结果数组,每个检测到的脸对应一个。

public struct Result {
  /// The status of the detection (.mask or .noMask)
  public let status: Status

  /// The bounding box of the face in normalized coordinates (the top-left corner of the image
  /// is [0, 0], and the bottom-right corner is [1, 1]).
  public let bound: CGRect

  /// Value between 0 and 1 representing the confidence in the result
  public let confidence: Float
}

视频

MaskDetectionVideoHelper 可用于实时视频的运行。首先,创建助手

let helper = MaskDetectionVideoHelper(maskDetector: MaskDetector())

然后在每个视频帧上调用 detectInFrame

if let results = try? detector.detectInFrame(cmSampleBuffer) {
  // Do something with the results.
}

您不需要将图像调整到 260x260 像素;助手会为您处理。查看示例应用的 ViewController 以获取完整的示例。

需求

  • iOS 13及以上

示例

要运行示例项目,请克隆仓库,并从“示例”目录运行pod install

安装

SwiftMaskDetection可通过CocoaPods获取。要安装它,请将以下行添加到您的Podfile中

pod 'SwiftMaskDetection'

许可

SwiftMaskDetection遵循MIT许可。更多信息请参阅LICENSE文件。

面部口罩检测模型版权所有(c)2020 AIZOOTech,也遵循MIT许可