I've been having some issues in using the captureStillImageAsynchronouslyFromConnection() method on an iPhone 5S running iOS 8.4 when capturing 8MP images (using AVCaptureSessionPresetPhoto), but when capturing 2MP images (using AVCaptureSessionPresetHigh or AVCaptureSessionInputPriority) the process takes an insignificant amount of time. For every other device I've tested on (4S, 5, 5C), image capture takes no time when capturing 8MP images. A couple things about the images themselves, I am setting both the device exposure duration and ISO to their respective maximum values with the flash-mode raw value set to 0 (OFF) and AVVideoQualityKey (JPEG compresssion quality) is set to 1.0.
Here's the code I use to capture the image:
func captureSingleStillImage(completionHandler handler: ((image:UIImage, metadata:NSDictionary) -> Void)) {
let connection = self.stillCameraOutput.connectionWithMediaType(AVMediaTypeVideo)
connection.videoOrientation = AVCaptureVideoOrientation(rawValue: UIDevice.currentDevice().orientation.rawValue)!
self.stillCameraOutput.captureStillImageAsynchronouslyFromConnection(connection) {
(imageDataSampleBuffer, error) -> Void in
self.imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
self.metadata = CMCopyDictionaryOfAttachments(nil, imageDataSampleBuffer, CMAttachmentMode(kCMAttachmentMode_ShouldPropagate))!.takeUnretainedValue() as CFDictionaryRef
Then there's some code adding metadata to a separate mutable copy of the original metadata (I can't seem to attach either the original or the mutable copy to the image (even when I save the original image data and not as a UIImage), but that's irrelevant to this question (unless you have an idea as to why, in which case please feel free to help me out). Anyways, here's the rest of the code in that method.
if let image = UIImage(data: self.imageData) {
dispatch_async(dispatch_get_main_queue()) { () -> Void in
handler(image: image, metadata: self.metadataMutable!)
}
}
else {
NSLog("error while capturing still image: \(error)")
}
}
}
Another thing, when I test for exposure duration on the camera (by taking an image of an Arduino setup of a row of LED lights that turn on and and off consecutively [one at a time] with a constant interval between one turning off and the next one turning one. The number of bulbs that show up in the image as turned on can tell you what the true exposure duration is on the device camera), although the console log says that the exposure duration is at 0.5 seconds when I print it out, it's actually more like .1 seconds on the iPhone 5S when using AVCaptureSessionPresetPhoto even though it works fine on any other AVCaptureSessionPreset and on any other device I've tested regardless of the preset.
I'm using Xcode 7 beta (build 7A121l) with Swift 2.0 if anybody's wondering.
Also, I've done hours and hours of research on the topic (even heroically venturing onto the second and third pages of a Google Search), and nothing has seemed to work, so literally any and all help is very much appreciated.
Thanks, FC
Aucun commentaire:
Enregistrer un commentaire