Commit c17d42a5 authored by Nguyễn Văn An's avatar Nguyễn Văn An

update camera iphone x

parent 4d2eb396
...@@ -43,7 +43,7 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega ...@@ -43,7 +43,7 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega
var timer = Timer() var timer = Timer()
var timeRecord: Int = 0 var timeRecord: Int = 0
var checkStatusRecord: Bool = false var checkStatusRecord: Bool = false
private var screenHeight: CGFloat = 0
var idFront: String = "" var idFront: String = ""
var idBack: String = "" var idBack: String = ""
var URLToken: String = "" var URLToken: String = ""
...@@ -53,7 +53,7 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega ...@@ -53,7 +53,7 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega
public var zoom: CGFloat = 1.0 public var zoom: CGFloat = 1.0
public var imageStartRecord: UIImage? public var imageStartRecord: UIImage?
public var checkStep: Int = 0 public var checkStep: Int = 0
private var startusCheck : Bool = false
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder) super.init(coder: aDecoder)
commonInit() commonInit()
...@@ -72,6 +72,7 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega ...@@ -72,6 +72,7 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega
if AVCaptureDevice.authorizationStatus(for: .video) == .denied { if AVCaptureDevice.authorizationStatus(for: .video) == .denied {
return return
} }
self.checkScreen()
self.loadCamera() self.loadCamera()
} }
...@@ -91,6 +92,10 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega ...@@ -91,6 +92,10 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega
} }
} }
public func setCameraChecker(){
self.startusCheck = true
}
public func statusSubView(statusHide: Bool) { public func statusSubView(statusHide: Bool) {
viewSubIcon.isHidden = statusHide viewSubIcon.isHidden = statusHide
} }
...@@ -307,22 +312,39 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega ...@@ -307,22 +312,39 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega
debugPrint("unable to get image from sample buffer") debugPrint("unable to get image from sample buffer")
return return
} }
if #available(iOS 11.0, *) {
self.detectFace(in: self.resizeImageFace(pixelBuffer: frame)) if self.startusCheck {
if #available(iOS 11.0, *) {
if self.screenHeight == 2436 {
self.detectFace(in: self.resizeImageFace(pixelBuffer: frame.resized(to: CGSize(width: 360, height: 480))!))
} else {
self.detectFace(in: self.resizeImageFace(pixelBuffer: frame))
}
}
} }
} }
func checkScreen(){
if UIDevice().userInterfaceIdiom == .phone {
self.screenHeight = UIScreen.main.nativeBounds.height
}
}
private func addCameraInput() { private func addCameraInput() {
self.captureSession.sessionPreset = .medium if self.screenHeight == 2436 {
self.captureSession.sessionPreset = .high
} else {
self.captureSession.sessionPreset = .medium
}
if #available(iOS 11.1, *) { if #available(iOS 11.1, *) {
guard let device = AVCaptureDevice.DiscoverySession( guard let device = AVCaptureDevice.DiscoverySession(
deviceTypes: [.builtInWideAngleCamera, .builtInDualCamera, .builtInTrueDepthCamera], deviceTypes: [.builtInWideAngleCamera, .builtInDualCamera, .builtInTrueDepthCamera],
mediaType: .video, mediaType: .video,
position: .front).devices.first else { position: .front).devices.first else {
print("No back camera device found, please make sure to run SimpleLaneDetection in an iOS device and not a simulator") print("No back camera device found, please make sure to run SimpleLaneDetection in an iOS device and not a simulator")
return return
} }
let cameraInput = try! AVCaptureDeviceInput(device: device) let cameraInput = try! AVCaptureDeviceInput(device: device)
if captureSession.canAddInput(cameraInput) { if captureSession.canAddInput(cameraInput) {
self.captureSession.addInput(cameraInput) self.captureSession.addInput(cameraInput)
...@@ -468,10 +490,10 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega ...@@ -468,10 +490,10 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega
if Global.ratioPass < pass * 100 && self.dataImageSuccess.count > 2 { if Global.ratioPass < pass * 100 && self.dataImageSuccess.count > 2 {
DispatchQueue.main.async { DispatchQueue.main.async {
guard let urlImageStraight = SBKValidateInput.shared.saveImage(imageName: "imageStraightFile.png", image: self.dataImageSuccess[0]), guard let urlImageStraight = SBKValidateInput.shared.saveImage(imageName: "imageStraightFile.png", image: self.dataImageSuccess[0]),
let urlImageRight = SBKValidateInput.shared.saveImage(imageName: "imageRightFile.png", image: self.dataImageSuccess[1]), let urlImageRight = SBKValidateInput.shared.saveImage(imageName: "imageRightFile.png", image: self.dataImageSuccess[1]),
let urlImageLeft = SBKValidateInput.shared.saveImage(imageName: "imageLeftFile.png", image: self.dataImageSuccess[2]) else { let urlImageLeft = SBKValidateInput.shared.saveImage(imageName: "imageLeftFile.png", image: self.dataImageSuccess[2]) else {
return return
} }
let data: [String: Any] = [ let data: [String: Any] = [
"imageStraightFile": urlImageStraight, "imageStraightFile": urlImageStraight,
"imageRightFile": urlImageRight, "imageRightFile": urlImageRight,
...@@ -519,10 +541,10 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega ...@@ -519,10 +541,10 @@ open class SBKRecordFaceView: UIView, AVCaptureVideoDataOutputSampleBufferDelega
if self.dataImageSuccess.count > 2 { if self.dataImageSuccess.count > 2 {
DispatchQueue.main.async { DispatchQueue.main.async {
guard let urlImageStraight = SBKValidateInput.shared.saveImage(imageName: "imageStraightFile.png", image: self.dataImageSuccess[0]), guard let urlImageStraight = SBKValidateInput.shared.saveImage(imageName: "imageStraightFile.png", image: self.dataImageSuccess[0]),
let urlImageRight = SBKValidateInput.shared.saveImage(imageName: "imageRightFile.png", image: self.dataImageSuccess[1]), let urlImageRight = SBKValidateInput.shared.saveImage(imageName: "imageRightFile.png", image: self.dataImageSuccess[1]),
let urlImageLeft = SBKValidateInput.shared.saveImage(imageName: "imageLeftFile.png", image: self.dataImageSuccess[2]) else { let urlImageLeft = SBKValidateInput.shared.saveImage(imageName: "imageLeftFile.png", image: self.dataImageSuccess[2]) else {
return return
} }
let data: [String: Any] = [ let data: [String: Any] = [
"imageStraightFile": urlImageStraight, "imageStraightFile": urlImageStraight,
"imageRightFile": urlImageRight, "imageRightFile": urlImageRight,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment