类型的价值' CGRect'没有会员'缩放'

时间:2018-04-03 11:31:03

标签: swift cgrect

我尝试在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)    
                }
            }
        }
    }
}

1 个答案:

答案 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
        )
    }
}