质量:定制AVFoundation相机应用程序VS.iOS标准相机应用程序

5
我使用不同的主题和灯光进行了一些测试。每个测试都显示标准的iOS相机应用程序质量明显优于我基于自定义AVFoundation的应用程序(颜色不褪色,对焦更好,照明更好,噪点更少)。我无法解释这些巨大的差异。以下是使用两种方法(使用前置摄像头)拍摄的视频的示例屏幕截图。
iOS标准相机应用程序: enter image description here 自定义AVFoundation录制的视频: enter image description here 自定义实现的代码:
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上有一个属性,automaticallyEnablesLowLightBoostWhenAvailable。这可以弥补你所看到的差异。 - alexkent
是的,那个测试是在低光环境下进行的。我尝试启用您建议的属性,但在使用前置摄像头进行测试时,它显示不支持该属性。我发布的照片主要显示了照明问题,但我进行的其他测试显示出更多问题(特别是当我测试我的肖像时)。与我使用 AVFoundation 进行的测试相比,默认相机应用程序看起来非常出色(没有被冲洗掉,适当的照明,不那么粗糙,锐利等)。我的测试看起来就像是用 5 分钱的 CMOS 传感器拍摄的。 - user2800679
1
你尝试过其他低光增强应用程序的方法吗?你是否将结果与苹果的AVCam-iOS示例代码进行了比较? - alexkent
我认为你的测试并不十分有效,AVFoundation有很多选项可以重新创建相机应用程序的质量。例如,你没有设置AVCaptureDeviceFormat,曝光或对焦。你几乎只使用默认值。因此,你的结果高度取决于你的代码实现,我很抱歉地说这相当平淡无奇。要进行更好的测试,请尝试下载此链接 https://developer.apple.com/library/prerelease/ios/samplecode/AVCamManual/Introduction/Intro.html - Andrea
你的会话预设是什么? - Nikhil Manapure
1个回答

0
我注意到你所描述的情况,并且查看了你的代码,我没有看到你实施以下内容:
backCamera.focusPointOfInterest = focusPoint
backCamera.focusMode = AVCaptureFocusMode.autoFocus
backCamera.exposureMode = AVCaptureExposureMode.autoExpose

我在touchesBegan方法中实现了这个功能,这样相机就会聚焦在用户触摸屏幕的区域。以下是相关代码部分:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        let touchPoint = touches.first
        let x = (touchPoint?.location(in: self.view).x)! / self.view.bounds.width
        let y = (touchPoint?.location(in: self.view).y)! / self.view.bounds.height

        let realX = (touchPoint?.location(in: self.view).x)!
        let realY = (touchPoint?.location(in: self.view).y)!

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

        let k = DrawSquare(frame: CGRect(
            origin: CGPoint(x: realX - 75, y: realY - 75),
            size: CGSize(width: 150, height: 150)))


        if backCamera != nil {
            do {
                try backCamera.lockForConfiguration()
                self.previewView.addSubview(k)
            }
            catch {
                print("Can't lock back camera for configuration")
            }
            if backCamera.isFocusPointOfInterestSupported {
                backCamera.focusPointOfInterest = focusPoint
            }
            if backCamera.isFocusModeSupported(AVCaptureDevice.FocusMode.autoFocus) {
                backCamera.focusMode = AVCaptureDevice.FocusMode.autoFocus
            }
            if backCamera.isExposureModeSupported(AVCaptureDevice.ExposureMode.autoExpose) {
                backCamera.exposureMode = AVCaptureDevice.ExposureMode.autoExpose
            }
            backCamera.unlockForConfiguration()

        }
        DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
            k.removeFromSuperview()
        }
    }

当相机显示暗图像时,用户可以轻松点击屏幕,它将调整曝光和对焦,使图片变亮。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接