2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.


これまでVisionでは顔の検出はできても、マスクをつけた顔は検知できなかった。

【従来はマスクの顔は検出されない】

僕はそれを逆手にとって、マスク未着用検知をしたりしました(Visionが反応するということはマスクをつけていない)。

2021年のiOS15バージョンから、マスクをつけた顔も検出できるようになった。

顔を検出する最小構成は以下。

let faceDetectionRequest = VNDetectFaceRectanglesRequest()
let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: .leftMirrored, options: [:])

do {
   try handler.perform([faceDetectionRequest])
   guard let faceObservations = faceDetectionRequest.results as? [VNFaceObservation] else { return }
} catch {
   print("Vision error: \(error.localizedDescription)")
}

マスクをつけた顔が検出できるのは、VNDetectFaceRectanglesRequestRevision3から。

let faceDetectionRequest = VNDetectFaceRectanglesRequest()
if #available(iOS 15.0, *) {
    faceDetectionRequest.revision = VNDetectFaceRectanglesRequestRevision3
} else {
    // Fallback on earlier versions
}

【マスクをつけた顔を検出】

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?