Размытие и растяжение камеры с помощью GLKView - PullRequest
0 голосов
/ 11 декабря 2019

Я снимаю изображение, используя AVCaptureSession и GLKView. Изображение с камеры размыто и растянуто, но с хорошо снятым изображением все хорошо.

Вид с камеры My App

Изображение растянуто до

и встроенная камераПредварительный просмотр

приложение для камеры iphone

Вот мой код

настройка вида камеры

CameraSuperView

fileprivate lazy var cameraSuperView: VideoCameraView = {
let cameraView = VideoCameraView(frame: self.view.bounds)
cameraView.contentMode = .scaleAspectFit
cameraView.backgroundColor = UIColor.clear
cameraView.clipsToBounds = true

return cameraView

} ()

добавление его в VideoCamera

self.view.addSubview(cameraSuperView)
videoCamera = VideoCamera(cameraView: cameraSuperView)

Метод init () класса VideoCamera

init(cameraView: VideoCameraView) {
self.cameraView = cameraView
filterImageManager = ImageFilterManager()
cameraView.layer.addSublayer(shapeLayer)

super.init()

self.setupCameraView()  <<<---<<<-----<<-------

self.cameraView.cameraLifeCicleDelegate = self
self.cameraView.flashableDelegate = self

NotificationCenter.default.addObserver(self, selector: #selector(cameraDidEnterBackground),
                                       name: NSNotification.Name.UIApplicationWillResignActive, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(cameraDidEnterForeground),
                                       name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)

}

fileprivate func setupCameraView() {    <<<---<<<-----<<-------
self.setupGLKView()  <<<<=======

let allDevices = AVCaptureDevice.devices(for: AVMediaType.video)
let aDevice: AnyObject? = allDevices.first as AnyObject?

if aDevice == nil {
  return
}

self.captureSession.beginConfiguration()
self.captureDevice = (aDevice as! AVCaptureDevice)

objCaptureDeviceInput = try! AVCaptureDeviceInput(device: self.captureDevice!)

/// Change sessionPreset on iPad & iPhone
switch deviceType {
case .phone: self.captureSession.sessionPreset = AVCaptureSession.Preset.photo//JD -> high
case .pad: self.captureSession.sessionPreset = AVCaptureSession.Preset.photo
default: break
}

self.captureSession.addInput(objCaptureDeviceInput!)

let dataOutput = AVCaptureVideoDataOutput()
dataOutput.alwaysDiscardsLateVideoFrames = true
dataOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as AnyHashable: kCVPixelFormatType_32BGRA] as? [String : Any]
dataOutput.setSampleBufferDelegate(self, queue: DispatchQueue.main)
self.captureSession.addOutput(dataOutput)

self.captureSession.addOutput(self.stillImageOutput)

let connection = dataOutput.connections.first
connection?.videoOrientation = .portrait

self.captureSession.commitConfiguration()

//JDS: Setting camera exposure when camera capture session is ready "AVCaptureSessionDidStartRunning"
NotificationCenter.default.addObserver(self, selector: #selector(updateExposeMode), name: .AVCaptureSessionDidStartRunning, object: nil)

}

настройка GLKView здесь

fileprivate func setupGLKView() {    <<<<=======
if let _ = self.context {
  return
}

self.context = EAGLContext(api: .openGLES2)
self.glkView = GLKView(frame: cameraView.bounds, context: self.context!)
self.glkView?.frame = cameraView.frame
self.glkView!.autoresizingMask = ([UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight])
self.glkView!.translatesAutoresizingMaskIntoConstraints = true
self.glkView!.contentScaleFactor = 1.0
self.glkView!.drawableDepthFormat = .format24


cameraView.insertSubview(self.glkView!, at: 0)
glGenRenderbuffers(1, &self.renderBuffer)
glBindRenderbuffer(GLenum(GL_RENDERBUFFER), self.renderBuffer)

self.coreImageContext = CIContext(eaglContext: self.context!, options: [kCIContextUseSoftwareRenderer: true])
EAGLContext.setCurrent(self.context!)

}

Я думаю, что проблема заключается в виде с камеры, так как после того, как я снимаю изображение, все хорошо. Как правильно настроить вид камеры?

...