我尝试在swift4中使用detectLandmarks
,但在let faceBoundingBox = boundingBox.scaled(to: self.view.bounds.size)
任何人都知道如何解决它
func detectLandmarks(on image: CIImage) {
try? faceLandmarksDetectionRequest.perform([faceLandmarks], on: image)
if let landmarksResults = faceLandmarks.results as? [VNFaceObservation] {
for observation in landmarksResults {
DispatchQueue.main.async {
if let boundingBox = self.faceLandmarks.inputFaceObservations?.first?.boundingBox {
let faceBoundingBox = boundingBox.scaled(to: self.view.bounds.size)
//different types of landmarks
let faceContour = observation.landmarks?.faceContour
self.convertPointsForFace(faceContour, faceBoundingBox)
}
}
}
}
}
答案 0 :(得分:1)
Try adding in this extension进入你的代码,事情应该很好地构建:
//
// CGRectExtension.swift
// Vision Face Detection
//
// Created by Pawel Chmiel on 23.06.2017.
// Copyright © 2017 Droids On Roids. All rights reserved.
//
import Foundation
import UIKit
extension CGRect {
func scaled(to size: CGSize) -> CGRect {
return CGRect(
x: self.origin.x * size.width,
y: self.origin.y * size.height,
width: self.size.width * size.width,
height: self.size.height * size.height
)
}
}