首页 > 解决方案 > 视觉框架 (iOS):VNDetectFaceLandmarksRequest 和 VNDetectFaceRectanglesRequest 有何不同?

问题描述

有两种不同的请求可用于 iOS Vision Framework 的人脸检测任务:VNDetectFaceLandmarksRequestVNDetectFaceRectanglesRequest. 它们都返回一个数组VNFaceObservation,每个检测到的人脸一个。VNFaceObservation具有多种可选属性,包括boundingBoxlandmarks。然后,landmarks 对象还包括可选属性,如noseinnerLipsleftEye等。

两种不同的 Vision 请求在执行人脸检测的方式上是否有所不同?

似乎VNDetectFaceRectanglesRequest只找到了一个边界框(可能还有其他一些属性),但没有找到任何地标。另一方面,VNDetectFaceLandmarksRequest似乎找到了边界框和地标。是否存在一种请求类型会找到面孔而另一种不会找到面孔的情况?是VNDetectFaceLandmarksRequest 优于还是VNDetectFaceRectanglesRequest后者在性能可靠性方面可能具有优势?

下面是如何使用这两个 Vision 请求的示例代码:

let faceLandmarkRequest = VNDetectFaceLandmarksRequest()
let faceRectangleRequest = VNDetectFaceRectanglesRequest()
let requestHandler = VNImageRequestHandler(ciImage: image, options: [:])
try requestHandler.perform([faceRectangleRequest, faceLandmarkRequest])
if let rectangleResults = faceRectangleRequest.results as? [VNFaceObservation] {
    let boundingBox1 = rectangleResults.first?.boundingBox   //this is an optional type
}
if let landmarkResults = faceLandmarkRequest.results as? [VNFaceObservation] {
    let boundingBox2 = landmarkResults.first?.boundingBox   //this is an optional type
    let landmarks = landmarkResults.first?.landmarks   //this is an optional type
}

标签: iosswiftmachine-learningface-detectionvision

解决方案


  • VNDetectFaceRectanglesRequest是一种更轻量级的查找人脸矩形的操作
  • VNDetectFaceLandmarksRequest是比较重的操作,也可以帮助定位人脸的地标

推荐阅读