2016-04-18 8 views
2

フロントカメラでピントを合わせようとしています。ios 9 AVCaptureDevice設定のフォーカスポイント

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 

    let screenSize = cameraView.bounds.size 

    let frameSize:CGSize = view.frame.size 

    if let touchPoint = touches.first { 

     var location:CGPoint = touchPoint.locationInView(cameraView) 

     print("Tap Location : X: \(location.x), Y: \(location.y)") 

     if cameraManager.cameraDevice == .Front { 
      print("Front camera is used") 

      location.x = frameSize.width - location.x; 
     } 
     else { 
      print("Back camera is used") 
     } 

     let x = location.x/frameSize.width 
     let y = 1.0 - (location.x/frameSize.width) 

     let focusPoint = CGPoint(x: x, y: y) 

     print("POINT : X: \(x), Y: \(y)") 


     let captureDevice = (AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice]).filter{$0.position == .Front}.first 

     if let device = captureDevice { 
      do { 
       try device.lockForConfiguration() 

       let support:Bool = device.focusPointOfInterestSupported 

       if support { 

        print("focusPointOfInterestSupported: \(support)") 

        device.focusPointOfInterest = focusPoint 

        // device.focusMode = .ContinuousAutoFocus 
        device.focusMode = .AutoFocus 
        // device.focusMode = .Locked 

        device.unlockForConfiguration() 

        print("Focus point was set successfully") 
       } 
       else{ 
        print("focusPointOfInterestSupported is not supported: \(support)") 
       } 
      } 
      catch { 
       // just ignore 
       print("Focus point error") 
      } 
     } 
    } 
} 

バックカメラ用iphone6で動作します。しかし、私はフロントカメラを起動すると、それは打ち砕かれた。 focusPointOfInterestSupportedは常にfalseを返します。

どうすればこの問題を解決できますか。プログラムでフォーカスポイントを設定できますか?

ありがとうございます!

答えて

5

focusPointOfInterestSupportedブール値は、このデバイスのフロントカメラがこのようにフォーカスを設定することをサポートしていないことを示します。実際、iPhone 6の「FaceTime」カメラには一定の焦点があるように見えます。 iPhone 6 "FaceTime"カメラのTech Specsセクションには "focus"という言葉はありませんが、背面にある "iSight"カメラセクションにはあります。さらに、レンズに近いぼやけた被写体(カメラアプリでタップする)で正面向きのカメラを再フォーカスしようとすると、フォーカスではなく露出のみが調整されるように見えます。

出典:https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureDevice_Class/index.html#//apple_ref/occ/instp/AVCaptureDevice/focusPointOfInterestSupported

出典:返信用http://www.apple.com/iphone-6/specs/

+0

感謝。あなたが正しいです。フロントカメラは、露出の調整のみをサポートしています。ズームについてはどうですか? avfoundationでフロントカメラのズーム係数を設定できません。しかし、リンゴストアにあるいくつかのアプリケーションはズームを設定できます。 – gkhanacer

+0

iPhoneの前面または背面のどちらのカメラも光学ズームをサポートしていません。アプリケーションが行うすべての「ズーム」は、イメージを拡大表示するために効果的にトリミングするだけです。 AVFoundationがフロントカメラで「ズーム」を使用できない場合は、リアカメラよりも解像度が低いためです。 Cameraアプリでは、リアカメラの場合と同様に、フロントカメラをズームすることもできません。 –

関連する問題