2015-09-29 7 views
7

क्या एक सटीक ऑटो फोकस और AVFoundation कस्टम परत कैमरे के लिए एक्सपोजर बनाने के लिए सबसे अच्छा तरीका है ?, उदाहरण के लिए, वर्तमान में मेरे कैमरा पूर्वावलोकन परत वर्ग, है मैं कैमरा फ्रेम फोकस और एक्सपोजर उस फ्रेम को निर्दिष्ट करने के लिए निर्दिष्ट करना चाहते हैं। यदि संभव हो तो मुझे स्विफ्ट 2 में इसकी आवश्यकता है, अगर नहीं, तो कृपया अपना उत्तर लिखें, मैं इसे स्वयं परिवर्तित कर पाऊंगा।ऑटो फोकस और कस्टम कैमरा परत पर AVFoundation में ऑटो एक्सपोजर

वर्तमान ऑटो फोकस और एक्सपोजर: लेकिन जैसा कि आप देख सकते हैं कि यह ध्यान केंद्रित करते समय पूरे दृश्य का मूल्यांकन करेगा।

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
    //Get Touch Point 
    let Point = touches.first!.locationInView(self.capture) 
    //Assign Auto Focus and Auto Exposour 
    if let device = currentCameraInput { 
     do { 
      try! device.lockForConfiguration() 
      if device.focusPointOfInterestSupported{ 
       //Add Focus on Point 
       device.focusPointOfInterest = Point 
       device.focusMode = AVCaptureFocusMode.AutoFocus 
      } 

      if device.exposurePointOfInterestSupported{ 
       //Add Exposure on Point 
       device.exposurePointOfInterest = Point 
       device.exposureMode = AVCaptureExposureMode.AutoExpose 
      } 
      device.unlockForConfiguration() 
     } 
    } 
} 

कैमरा परत: 1 में कुछ भी: 1 के अनुपात इस बाध्य भी कैमरा ध्यान देने के लिए एक स्पर्श घटना के रूप में नहीं माना जाएगा बाहर फ़ोकस और एक्सपोज़र बिंदु, और कुछ भी रूप में माना जाना चाहिए।

enter image description here

+2

क्या आप AVCaptureVideoPreviewLayer का उपयोग कर रहे हैं? यदि ऐसा है: 'सार्वजनिक func captureDevicePointOfInterestForPoint (pointInLayer: CGPoint) -> CGPoint' – jlw

+0

@jlw हाँ मैं 'AVCaptureVideoPreviewLayer' का उपयोग कर रहा हूं लेकिन मुझे वह फ़ंक्शन दिखाई नहीं देता है। :/ – Xrait

+1

https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVCaptureVideoPreviewLayer_Class/#//apple_ref/occ/instm/AVCaptureVideoPreviewLayer/captureDevicePointOfInterestForPoint: – jlw

उत्तर

8
public func captureDevicePointOfInterestForPoint(pointInLayer: CGPoint) -> CGPoint 

आप डिवाइस आपके AVCaptureVideoPreviewLayer की सेटिंग के आधार पर पर ध्यान केंद्रित करने के लिए बिंदु दे देंगे। docs देखें।

+0

फिर से धन्यवाद। – Xrait

7

जेएलडब्ल्यू के लिए धन्यवाद यह है कि आप इसे स्विफ्ट 2 में कैसे करते हैं। सबसे पहले, हमें टैप जेस्चर सेट अप करने की आवश्यकता है जिसे आप प्रोग्रामेटिक या स्टोरीबोर्ड कर सकते हैं।

//Add UITap Gesture Capture Frame for Focus and Exposure 
    let captureTapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "AutoFocusGesture:") 
    captureTapGesture.numberOfTapsRequired = 1 
    captureTapGesture.numberOfTouchesRequired = 1 
    self.captureFrame.addGestureRecognizer(captureTapGesture) 

captureTapGesture में हमारे चयनकर्ता पर फ़ंक्शन बेस बनाएं।

/*========================================= 
* FOCUS & EXPOSOUR 
==========================================*/ 
var animateActivity: Bool! 
internal func AutoFocusGesture(RecognizeGesture: UITapGestureRecognizer){ 
    let touchPoint: CGPoint = RecognizeGesture.locationInView(self.captureFrame) 
    //GET PREVIEW LAYER POINT 
    let convertedPoint = self.previewLayer.captureDevicePointOfInterestForPoint(touchPoint) 

    //Assign Auto Focus and Auto Exposour 
    if let device = currentCameraInput { 
     do { 
      try! device.lockForConfiguration() 
      if device.focusPointOfInterestSupported{ 
       //Add Focus on Point 
       device.focusPointOfInterest = convertedPoint 
       device.focusMode = AVCaptureFocusMode.AutoFocus 
      } 

      if device.exposurePointOfInterestSupported{ 
       //Add Exposure on Point 
       device.exposurePointOfInterest = convertedPoint 
       device.exposureMode = AVCaptureExposureMode.AutoExpose 
      } 
      device.unlockForConfiguration() 
     } 
    } 
} 

इसके अलावा, अगर आप अपने एनीमेशन सूचक का उपयोग करना चाहते, एक घटना का अपने स्पर्श से संपर्क सूत्र का उपयोग करें और अपने एनिमेटेड परत को असाइन करें।

//Assign Indicator Position 
touchIndicatorOutside.frame.origin.x = touchPoint.x - 10 
touchIndicatorOutside.frame.origin.y = touchPoint.y - 10 
संबंधित मुद्दे