'CGRect' 类型的值没有成员 'scaled'
Value of type 'CGRect' has no member 'scaled'
我正在尝试在 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)
}
}
}
}
}
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
)
}
}
我正在尝试在 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)
}
}
}
}
}
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
)
}
}