【问题标题】:Convert Vision face detection VNFaceLandmarkRegion2D points into frame coordinates to be scale将Vision人脸检测VNFaceLandmarkRegion2D点转换为要缩放的帧坐标
【发布时间】:2019-07-14 07:01:41
【问题描述】:

我正在使用视觉框架来检测面部标志,它工作正常,但我需要转换面部标志,如鼻子、眼睛,为此我需要获取帧坐标中的鼻子、眼睛位置,因为面部标志正在使用 VNFaceLandmarkRegion2D 绘制点。

请告诉我如何将 VNFaceLandmarkRegion2D 点转换为框架坐标。因此,我可以获取要转换的位置或建议任何其他方式来转换面部地标。

【问题讨论】:

    标签: objective-c swift xcode face-detection vision


    【解决方案1】:

    Joshua Newnham 的这段代码解决了您的问题。

     func getTransformedPoints(
                    landmark:VNFaceLandmarkRegion2D,
                    faceRect:CGRect,
                    imageSize:CGSize) -> [CGPoint]{
    
                    // last point is 0.0
                    return landmark.normalizedPoints.map({ (np) -> CGPoint in
                        return CGPoint(
                            x: faceRect.origin.x + np.x * faceRect.size.width,
                            y: imageSize.height - (np.y * faceRect.size.height + faceRect.origin.y))
                    })
                }
    

    【讨论】:

    • 我在 y 位置上苦苦挣扎,这解决了我的问题。谢谢@Ozgur
    【解决方案2】:

    作为一个新手,这是我可以找到的将面部标记作为 CGPoint 的方法:

    1. 先将选中的图片转换成CIImage
    2. 在图像上使用 faceDetector
    3. 为每个人脸解析图像,以防它有多个人脸

    代码:

    let chosenPicture = CIImage(data: (self.selectedimage.image?.tiffRepresentation)!)
    let selectedFace = faceDetector?.features(in: chosenPicture!, options: [CIDetectorSmile:true])
    for person in selectedFace as! [CIFaceFeature] {
        let p1LeftEye = person.leftEyePosition
        let p1RightEye = person.rightEyePosition
        let p1Mouth = person.mouthPosition
    

    【讨论】:

    • 感谢您的回复。我想使用视觉框架而不是 CIDetector 定位
    猜你喜欢
    • 2014-04-06
    • 2019-06-18
    • 2012-08-25
    • 1970-01-01
    • 2013-05-15
    • 1970-01-01
    • 2016-09-15
    • 2017-11-29
    • 2017-07-30
    相关资源
    最近更新 更多