IOS ML套件面部跟踪无法正常工作
人脸检测的跟踪Id在人脸不移动的情况下不断变化,我在ios中使用ML工具包,并遵循google的文档 文件: 这是我的密码:IOS ML套件面部跟踪无法正常工作,ios,swift,xcode,firebase-mlkit,google-mlkit,Ios,Swift,Xcode,Firebase Mlkit,Google Mlkit,人脸检测的跟踪Id在人脸不移动的情况下不断变化,我在ios中使用ML工具包,并遵循google的文档 文件: 这是我的密码: func captureOutput( _ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { self.detectFaceMLKit(image: sampleBuffer) } 注意:开始
func captureOutput( _ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
self.detectFaceMLKit(image: sampleBuffer)
}
注意:开始时跟踪id工作正常,但在id“10”左右后,它会丢失人脸跟踪,并开始为同一人脸提供多id,而不会在相机中移动人脸
过滤跟踪id后的输出样本:
trackingId:21
trackingId:21
trackingId:21
trackingId:21
trackingId:21
trackingId:21
trackingId:22
trackingId:22
trackingId:22
trackingId:22
trackingId:22
trackingId:23
trackingId:23
trackingId:23
trackingId:23
trackingId:23
trackingId:24
trackingId:24
trackingId:24
trackingId:24
trackingId:24
问题是imageOrientation,我将方向设置为仅在Xcode中纵向,但基于UIDeviceOrientation旋转图像,这是错误的,通过将imageOrientation设置为固定在.up位置来修复它 编辑: 此外,请确保不要像这样覆盖输出图像方向:
private let videoDataOutput = AVCaptureVideoDataOutput()
guard let connection = self.videoDataOutput.connection(with: AVMediaType.video),
connection.isVideoOrientationSupported else { return }
connection.videoOrientation = .portrait
func imageOrientation(
deviceOrientation: UIDeviceOrientation,
cameraPosition: AVCaptureDevice.Position
) -> UIImage.Orientation {
switch deviceOrientation {
case .portrait:
return cameraPosition == .front ? .leftMirrored : .right
case .landscapeLeft:
return cameraPosition == .front ? .downMirrored : .up
case .portraitUpsideDown:
return cameraPosition == .front ? .rightMirrored : .left
case .landscapeRight:
return cameraPosition == .front ? .upMirrored : .down
case .faceDown, .faceUp, .unknown:
return .up
}
}
private let videoDataOutput = AVCaptureVideoDataOutput()
guard let connection = self.videoDataOutput.connection(with: AVMediaType.video),
connection.isVideoOrientationSupported else { return }
connection.videoOrientation = .portrait