2016-11-17 72 views
0

在我的应用程序中,我试图将CIFilter(CIBumpDistortion)应用于我的图像。 我的问题是使用kcIInputCenterKey参数时,它似乎我必须给编号的坐标。当我运行应用程序,此代码返回左眼坐标:IOS Core Image Filter参数

if (face.hasLeftEyePosition) { 
       NSLog("Left eye %g %g", face.leftEyePosition.x, face.leftEyePosition.y); 

Hence, I can manually then enter the left eye coordinates into the kCInputCenterKey and then run the app again and the filter is applied to the left eye centre point: 

let filter = CIFilter(name: "CIBumpDistortion") 
      filter?.setValue(ciImage, forKey: kCIInputImageKey) 
      filter?.setValue(0.5, forKey: kCIInputScaleKey) 
      filter?.setValue(200, forKey: kCIInputRadiusKey) 

      filter?.setValue(CIVector(x:150, y: 150), forKey: kCIInputCenterKey) 
      if let output = filter?.value(forKey: kCIOutputImageKey) as? CIImage { 
       self.chosenImage?.image = UIImage(cgImage: context.createCGImage(output, from: output.extent)!) 

不过,我希望用户能够选择任何图像时使用的,我需要的Xcode找到左眼位置和应用过滤到该区域,而不必手动输入坐标。

我尝试过使用字符串,不同类型等来代替x和y坐标所需的数字,所有这些都没有运气。

任何帮助将非常欢迎和非常感谢!

回答

0

以下是我正在阅读的东西。用户需要从未知来源(相机?相册?相机胶卷?)中选取图像。

  • 如果用户选择的图像是由一组静态图像,你需要手动查找X/Y值,并将其传递给过滤器之前在代码中的值存储。

  • 如果用户选择的图像是在选择之前完全未知的,你真的应该有用户,不的Xcode情况决定了左眼。 (虽然你可以尝试的边缘检测滤波器,我认为你将有一个更难的时间是正确的。)

在后一种情况下,我会考虑增加2-4手势识别,挖掘初始点,捏调整区域大小,也许旋转(旋转)和平移(移动)。

+0

嗨,dfd,非常感谢您的建议。我对编码一般都比较陌生,从来没有想过尝试使用手势识别器!再次感谢,我再给它一次。 – Henry