2

我正在使用 iphone truedepth 相机捕获深度图像,并使用 ios 视觉框架在图像中查找人脸地标。捕获设备分辨率为 3088x2136,深度图为 640x480。我们正在尝试找到所有面部地标点的深度,但我无法缩小地标以正确匹配深度图尺寸。

这是我目前使用的代码:

var landmarks = [
    lastFaceObservation.landmarks?.leftEye,
    lastFaceObservation.landmarks?.rightEye,
    lastFaceObservation.landmarks?.nose,
    lastFaceObservation.landmarks?.noseCrest,
    lastFaceObservation.landmarks?.medianLine,
    lastFaceObservation.landmarks?.faceContour
]
        
var landmarkNames = [
    "leftEye",
    "rightEye",
    "nose",
    "noseCrest",
    "medianLine",
    "faceContour"
]

var data = ""

let frameSize = CGSize(width: 640, height: 480)
        
for (index, landmark) in landmarks.enumerated() {
            
    for (pointIndex, point) in landmark!.normalizedPoints.enumerated() {
                
        var vectorPoint: simd_float2 = simd_float2(Float(point.x), Float(point.y))
                
        var pixel: CGPoint = VNImagePointForFaceLandmarkPoint(vectorPoint, lastFaceObservation.boundingBox, Int(captureDeviceResolution.width), Int(captureDeviceResolution.height))
                              
        let transform = CGAffineTransform(scaleX: 640 / captureDeviceResolution.width, y: 480 / captureDeviceResolution.height)

        pixel = pixel.applying(transform)
                
        var pixelX = pixel.x
        var pixelY = pixel.y
                
        let Z = depthPointer[Int(Float(pixelY) * Float(CGFloat(width)) + Float(pixelX))]
        let X = (Float(pixelX) - principalPointX) * Z / focalX
        let Y = (Float(pixelY) - principalPointY) * Z / focalY
                
        data.append("\(landmarkNames[index]), \(pointIndex), \(X), \(Y), \(Z)\n")
            
    }
}

不知何故,它不像在全尺寸图像上取一个地标点,然后将其缩小为 640x480 图像那么简单,因为这样。当我运行此代码并绘制生成的深度云和地标点时,我得到以下信息:

正面: 正面

BACK(正面的反面: 背部

从背面的放大图片中可以看到,一些地标距离很远: 放大

模型的侧视图显示了未对准的程度: 边

我尝试在各个点缩小像素值,但没有奏效。我也尝试过删除主点偏移,但没有成功。我认为仿射变换有问题,但我不知道如何纠正它。我希望看到地标点与深度云正确对齐

4

0 回答 0