使用前置摄像头拍摄时未检测到人脸

Faces not detected when photographed with front facing camera

我在 iPhone 应用程序中使用 Azure 人脸识别 API。当我用后置摄像头拍照时它工作得很好,但是当我使用前置摄像头时,API 无法检测到人脸。

我试过将(正面)照片传输到我的笔记本电脑并将其拖到文档中的测试区域,然后就可以很好地检测到人脸了。

这让我相信可能有一些特定于正面照片的元数据或标志混淆了 API?那些通过浏览器上传时会被删除?

更新

以下是我使用 AlamoFire 上传文件的方式:

let data = UIImageJPEGRepresentation(photo, 0.5)
let url = "https://.../detect"
let octetHeaders = ["Content-Type": "application/octet-stream", "Ocp-Apim-Subscription-Key": "..."]
Alamofire.upload(data, to: url, method: .post, headers: octetHeaders)

谢谢!

轩虎说的对。事实证明 iPhone 不会旋转图像——它只是设置一个方向 EXIF 标签。

上传前硬旋转照片使一切正常:

func normalizeImageRotation(_ image: UIImage) -> UIImage {
    if (image.imageOrientation == UIImageOrientation.up) { return image }

    UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale)
    image.draw(in: CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
    let normalizedImage = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()
    return normalizedImage
}