【发布时间】:2016-02-06 19:14:09
【问题描述】:
我已经使用不同的主题和照明进行了许多测试。每个测试都显示标准 iOS 相机应用程序的质量明显优于我的自定义基于 AVFoundation 的应用程序(颜色不会褪色、对焦更好、照明更好、颗粒感更少)。我无法解释巨大的差异。下面是使用两种方法(使用前置摄像头)拍摄的视频的示例屏幕截图。
自定义实现代码:
let chosenCameraType = AVCaptureDevicePosition.Front
//get camera
let devices = AVCaptureDevice.devices()
for device in devices
{
if (!device.hasMediaType(AVMediaTypeVideo))
{
continue
}
if (device.position != chosenCameraType)
{
continue
}
camera = (device as? AVCaptureDevice)!
}
do
{
captureSession = AVCaptureSession()
captureSession!.sessionPreset = AVCaptureSessionPresetHigh
let video = try AVCaptureDeviceInput(device: camera) as AVCaptureDeviceInput
captureSession!.addInput(video)
let audio = try AVCaptureDeviceInput(device: AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)) as AVCaptureDeviceInput
captureSession!.addInput(audio)
fileOutput = AVCaptureMovieFileOutput()
captureSession?.addOutput(fileOutput)
captureSession!.startRunning()
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
let name = String(UInt64(NSDate().timeIntervalSince1970 * 1000))
fileOutput?.startRecordingToOutputFileURL(NSURL(fileURLWithPath: "\(documentsPath)/" + name + ".mov"), recordingDelegate: self)
}
catch let error as NSError
{
print(error)
}
请尝试!您也会看到不同之处...
【问题讨论】:
-
您的所有测试都是在低水平或人工照明下进行的吗?您可能需要启用“lowLightBoost”。 AVCaptureDevice 上有一个属性,automaticEnablesLowLightBoostWhenAvailable。这可能会弥补您所看到的差异。
-
是的,该测试是在弱光下进行的。我尝试启用您建议的该属性,但它说在使用前置摄像头进行测试时不支持它。我发布的主要图片显示了照明问题,但我所做的其他测试显示了更多问题(尤其是当我测试我的肖像时)。与我使用 AVFoundation 进行的测试相比,默认的相机应用看起来很壮观(没有褪色、适当的照明、更少的颗粒感、锐利等),看起来它是用 5 美分的 CMOS 传感器完成的。
-
您是否尝试过其他低光增强应用方法?您是否将您的结果与 Apple 的 AVCam-iOS 示例代码的结果进行了比较?
-
我不认为您的测试在某种程度上是有效的,AVFoundation 有很多选项可以重新创建相机应用程序的质量。例如,您没有设置 AVCaptureDeviceFormat,既没有设置曝光也没有设置焦点。您几乎没有使用默认值。所以你的结果很大程度上取决于你的代码实现,很抱歉,这很简单。要进行更好的测试,请尝试下载此developer.apple.com/library/prerelease/ios/samplecode/…
-
你的会话预设是什么?
标签: ios swift camera avfoundation