X 和 Y 轴在 Vision Framework 中交换 Swift

X and Y-axis swapped in Vision Framework Swift

我正在使用 Vision Framework 通过 iPhone 的前置摄像头检测人脸。我的代码看起来像

  func detect(_ cmSampleBuffer: CMSampleBuffer) {
    guard let pixelBuffer = CMSampleBufferGetImageBuffer(cmSampleBuffer) else {return}
    var requests: [VNRequest] = []
    
    let requestLandmarks = VNDetectFaceLandmarksRequest { request, _ in
      DispatchQueue.main.async {
        guard let results = request.results as? [VNFaceObservation],
        print(results)
      }
    }
    requests.append(requestLandmarks)
            
    let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: .leftMirrored)
    do {
      try handler.perform(requests)
    } catch {
      print(error)
    }
  }

但是,我注意到当我水平移动脸部时,坐标会垂直改变,反之亦然。下图可以帮助理解

如果有人能帮助我,我会为之疯狂

出于某种原因,移除

let connectionVideo = videoDataOutput.connection(with: AVMediaType.video)
connectionVideo?.videoOrientation = AVCaptureVideoOrientation.portrait

我的AVCaptureVideoDataOutput解决了问题