Quality: Custom application AVFoundation Camera VS. Standard app for iOS camera

I conducted several tests using various objects and lighting. Each test shows the standard quality of the application for the iOS camera as significantly superior (colors do not wash out, better focus, better light, less grainy) in my regular application based on AVFoundation. I can not explain the huge differences. The following is an example of capturing a screen from a video made using both methods (using the front camera).

Standard app for iOS camera enter image description here

Custom AVFoundation Recorded Video enter image description here

Code for custom implementation:

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)
}

Give it a try! You will also see this difference ...

+4
1

, . , :

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()
        }
    }

, github

, , , , .

0

Source: https://habr.com/ru/post/1627592/


All Articles