CIDepthBlurEffect:设置inputFocusRect

问题描述 投票:2回答:1

我无法找到从触摸点设置“inputFocusRect”值的正确方法。我正在使用触控点

@IBAction func imageTapped(_ sender: UITapGestureRecognizer) {
    var touchPoint = sender.location(in: self.imageView)
    imageTapCoordinates = CIVector(cgPoint: touchPoint)

我通过单独的模糊功能将其传递给CIFilter。

filter?.setValue(imageTapCoordinates, forKey: "inputFocusRect")

然而,似乎坐标系不匹配!确定“inputFocusRect”的最佳方法是什么? Apple在他们的网站上没有太多关于此的文档......

谢谢!

swift blur depth coordinate cifilter
1个回答
1
投票

由于长度和更好的格式化,将此作为答案发布。

TL; DR;

最有可能的问题似乎是这个过滤器期望两个(或更多)输入 - 输入图像和CoreML或(更可能)面部识别的Vision框架输出。

我的想法是inputFocusRect,一个CIVector(原点位于左下方的翻转坐标),是CoreML或Vision框架输出识别较大图像中的面部的地方。

说明:

CIDepthBlurEffect是iOS 11或macOS 10.3中提供的新过滤器。事实上,它是如此新颖,苹果尚未更新他们的CI Filter Reference

我不得不求助于倾倒我能找到的东西。这是相当简单的代码。创建过滤器的实例并打印出其属性。

let filter = CIFilter(name: "CIDepthBlurEffect")
print(filter?.attributes)

了解,有更好的方法可以做到这一点 - 查询设备的可用过滤器(全部或特定类别),使用特定属性获取其显示名称等。我的意图是为这个问题提供我能做的。 “转储”会生成一个字典元素或[String:Any]数组,并且在此处未格式化。手动格式化产生这个:

[
    "inputRightEyePositions": {
        CIAttributeClass = CIVector;
        CIAttributeDisplayName = "Right Eye Positions";
        CIAttributeType = CIAttributeTypePosition;
    }, 
    "inputCalibrationData": {
        CIAttributeClass = AVCameraCalibrationData;
        CIAttributeDisplayName = CalibrationData;
    }, 
    "inputImage": {
        CIAttributeClass = CIImage;
        CIAttributeDescription = "The image to use as an input image. For filters that also use a background image, this is the foreground image.";
        CIAttributeDisplayName = Image;
        CIAttributeType = CIAttributeTypeImage;
    }, 
    "inputChinPositions": {
        CIAttributeClass = CIVector;
        CIAttributeDisplayName = "Chin Positions";
        CIAttributeType = CIAttributeTypePosition;
    }, 
    "inputLeftEyePositions": {
        CIAttributeClass = CIVector;
        CIAttributeDisplayName = "Left Eye Positions";
        CIAttributeType = CIAttributeTypePosition;
    }, 
    "inputAuxDataMetadata": {
        CIAttributeClass = NSDictionary;
        CIAttributeDisplayName = AuxDataMetadata;
    }, 
    "CIAttributeFilterAvailable_Mac": 10.13, 
    "CIAttributeFilterName": CIDepthBlurEffect,
    "CIAttributeReferenceDocumentation": http://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIDepthBlurEffect, 
    "inputAperture": {
        CIAttributeClass = NSNumber;
        CIAttributeDefault = 0;
        CIAttributeDisplayName = Aperture;
        CIAttributeMax = 22;
        CIAttributeMin = 0;
        CIAttributeSliderMax = 22;
        CIAttributeSliderMin = 1;
        CIAttributeType = CIAttributeTypeScalar;
    }, 
    "CIAttributeFilterDisplayName": Depth Blur Effect,
    "CIAttributeFilterAvailable_iOS": 11, 
    "inputNosePositions": {
        CIAttributeClass = CIVector;
        CIAttributeDisplayName = "Nose Positions";
        CIAttributeType = CIAttributeTypePosition;
    }, 
    "inputLumaNoiseScale": {
        CIAttributeClass = NSNumber;
        CIAttributeDefault = 0;
        CIAttributeDisplayName = "Luma Noise Scale";
        CIAttributeMax = "0.1";
        CIAttributeMin = 0;
        CIAttributeSliderMax = "0.1";
        CIAttributeSliderMin = 0;
        CIAttributeType = CIAttributeTypeScalar;
    }, 
    "inputScaleFactor": {
        CIAttributeClass = NSNumber;
        CIAttributeDefault = 1;
        CIAttributeDisplayName = "Scale Factor";
        CIAttributeSliderMax = 1;
        CIAttributeSliderMin = 0;
        CIAttributeType = CIAttributeTypeScalar;
    }, 
    "inputFocusRect": {
        CIAttributeClass = CIVector;
        CIAttributeDisplayName = "Focus Rectangle";
        CIAttributeIdentity = "[-8.98847e+307 -8.98847e+307 1.79769e+308 1.79769e+308]";
        CIAttributeType = CIAttributeTypeRectangle;
    }, 
    "inputDisparityImage": {
        CIAttributeClass = CIImage;
        CIAttributeDisplayName = DisparityImage;
    }, 
    "CIAttributeFilterCategories": <__NSArrayI 0x1c46588a0>(
        CICategoryBlur,
        CICategoryVideo,
        CICategoryStillImage,
        CICategoryBuiltIn
    )

我计算了12个可能的输入 - 2个CIImages,5个CIVectors,3个NSNumbers,1个NSDictionary和1个AVCameraCalibrationData

其中一些很容易破译......它们处理相机,图像,图像元数据和面部组件。有些人不那么 - 但也许有人更深入到Vision框架中了解更多。 (如果没有,也许这是个好看的地方!)

具体来说,我的问题是:

  • 什么是inputDisparityImage
  • 如果没有找到nil或chi位置,那么各种输入面部特征会有什么期待?

这不是许多SO标准的答案,如果低估,我会高兴地删除它。但我想告诉你如何了解过滤器的属性,并尝试提供帮助。

我对CoreML和Vision框架的了解很少。我已经了解了它们背后的概念 - 看一个图像(或视频)并检测/识别某些东西,并且(通常)给出一个置信因子。

由于脸部特征的其他输入也是CIVectors,我相信inputFocusRect是一个检测到整个脸部的地方。有意义的是,Vision框架可以轻松地将此类输出与此过滤器紧密集成。

最后,我确实尝试了属性中的文档链接,它变得空洞。

© www.soinside.com 2019 - 2024. All rights reserved.