为什么当使用前置摄像头时,我的面部检测盒会向相反方向移动?

时间:2018-10-28 02:20:41

标签: swift xcode

我正在使用Vision Framework制作人脸检测应用程序。我遇到的问题是,当我使用前置摄像头时,人脸检测框未跟随我的脸。当我将脸向右移动时,脸部检测框会移到左侧,而当我将脸向左移动时,脸部检测框也会移至右侧。为什么会这样?

func drawFaceboundingBox(face : VNFaceObservation) {

    let transform = CGAffineTransform(scaleX: 1, y: -1).translatedBy(x: 0, y: -frame.height)

    let translate = CGAffineTransform.identity.scaledBy(x: frame.width, y: frame.height)

    // The coordinates are normalized to the dimensions of the processed image, with the origin at the image's lower-left corner.
    let facebounds = face.boundingBox.applying(translate).applying(transform)

    _ = createLayer(in: facebounds)

}

1 个答案:

答案 0 :(得分:0)

终于可以工作了。不得不将转换更改为此:

func drawFaceboundingBox(face : VNFaceObservation) {

let transform = CGAffineTransform(scaleX: -1, y: -1).translatedBy(x: -frame.width, y: -frame.height)

let translate = CGAffineTransform.identity.scaledBy(x: frame.width, y: frame.height)

// The coordinates are normalized to the dimensions of the processed image, with the origin at the image's lower-left corner.
let facebounds = face.boundingBox.applying(translate).applying(transform)

_ = createLayer(in: facebounds)

}