2016-11-17 68 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