Skip to content

Commit

Permalink
added 11.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
sMaltsevAcuant committed Oct 5, 2022
1 parent 4ad05da commit fb237d0
Show file tree
Hide file tree
Showing 181 changed files with 223,581 additions and 602 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ import AVFoundation
coordinator.animate(alongsideTransition: { [weak self] context in
guard let self = self else { return }

self.rotateCameraPreview(to: self.view.window?.interfaceOrientation)
let newFrame = CGRect(origin: self.view.frame.origin, size: size)
self.rotateCameraPreview(to: self.view.window?.interfaceOrientation, frame: newFrame)
})
}

Expand All @@ -77,10 +78,6 @@ import AVFoundation
messageLayer.foregroundColorCapture = capturingColor
messageLayer.backgroundColorCapture = UIColor.black.cgColor
messageLayer.textSizeCapture = 30
messageLayer.defaultWidth = 320
messageLayer.defaultHeight = 40
messageLayer.captureWidth = 320
messageLayer.captureHeight = 40
return messageLayer
}

Expand Down Expand Up @@ -149,7 +146,7 @@ import AVFoundation
private func attachSession() {
let captureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back)!
captureSession = BarcodeCaptureSession(captureDevice: captureDevice, delegate: self)
cameraPreviewView = CameraPreviewView(frame: view.bounds, captureSession: captureSession)
cameraPreviewView = CameraPreviewView(frame: view.frame, captureSession: captureSession)
cameraPreviewView.videoPreviewLayer.videoGravity = .resizeAspectFill

if let barcodeLayer = barcodeLayer {
Expand All @@ -164,7 +161,7 @@ import AVFoundation
}

captureSession.start {
self.rotateCameraPreview(to: self.view.window?.interfaceOrientation)
self.rotateCameraPreview(to: self.view.window?.interfaceOrientation, frame: self.view.frame)
}
}

Expand All @@ -173,31 +170,31 @@ import AVFoundation
cameraPreviewView.removeFromSuperview()
}

private func rotateCameraPreview(to interfaceOrientation: UIInterfaceOrientation?) {
private func rotateCameraPreview(to interfaceOrientation: UIInterfaceOrientation?, frame: CGRect) {
guard let connection = cameraPreviewView.videoPreviewLayer.connection,
connection.isVideoOrientationSupported,
let orientation = interfaceOrientation else {
return
}

cameraPreviewView.frame = view.bounds
cameraPreviewView.frame = frame
connection.videoOrientation = orientation.videoOrientation ?? .portrait
cameraPreviewView.clearAccessibilityElements()

if orientation.isLandscape {
messageLayer.transform = CATransform3DIdentity
messageLayer.setFrame(frame: view.bounds)
messageLayer.setFrame(frame: frame)
barcodeLayer?.transform = CATransform3DIdentity
barcodeLayer?.setFrame(frame: view.bounds)
barcodeLayer?.setFrame(frame: frame)
} else {
if CATransform3DIsIdentity(messageLayer.transform) {
messageLayer.rotate(angle: 90)
}
if let barcodeLayer = barcodeLayer, CATransform3DIsIdentity(barcodeLayer.transform) {
barcodeLayer.setFrame(frame: view.bounds)
barcodeLayer.setFrame(frame: frame)
barcodeLayer.rotate(angle: 90)
}
messageLayer.setVerticalDefaultSettings(frame: view.bounds)
messageLayer.setVerticalDefaultSettings(frame: frame)
}
cameraPreviewView.videoPreviewLayer.removeAllAnimations()
}
Expand Down Expand Up @@ -264,12 +261,12 @@ extension BarcodeCameraViewController: BarcodeCaptureDelegate {
public func captured(barcode: String?) {
guard let barcode = barcode, afterCaptureTimer == nil else { return }

messageLayer.string = NSLocalizedString("acuant_camera_capturing", comment: "")
if let orientation = view.window?.interfaceOrientation, orientation.isPortrait {
messageLayer.setVerticalCaptureSettings(frame: view.bounds)
} else {
messageLayer.setCaptureSettings(frame: view.bounds)
}
messageLayer.string = NSLocalizedString("acuant_camera_capturing", comment: "")
afterCaptureTimer = Timer.scheduledTimer(withTimeInterval: TimeInterval(options.timeInMsPerDigit/1000),
repeats: false) { [weak self] _ in
guard let self = self else { return }
Expand Down
28 changes: 15 additions & 13 deletions AcuantCamera/AcuantCamera/Camera/CameraOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@
import Foundation
import UIKit

@objcMembers public class CameraOptions : NSObject{
@objcMembers public class CameraOptions: NSObject {

public let timeInMsPerDigit: Int
public let digitsToShow: Int
public let allowBox: Bool
public let autoCapture: Bool
public let hideNavigationBar : Bool
public let bracketLengthInHorizontal : Int
public let hideNavigationBar: Bool
public let bracketLengthInHorizontal: Int
public let bracketLengthInVertical: Int
public let defaultBracketMarginWidth : CGFloat
public let defaultBracketMarginHeight : CGFloat
public let defaultBracketMarginWidth: CGFloat
public let defaultBracketMarginHeight: CGFloat
public let colorHold: CGColor
public let colorCapturing: CGColor
public let colorReposition: CGColor
public let colorBracketAlign: CGColor
public let colorBracketCloser: CGColor
public let colorBracketHold: CGColor
Expand All @@ -31,22 +32,22 @@ import UIKit

public init(timeInMsPerDigit: Int = 900,
digitsToShow: Int = 2,
allowBox : Bool = true,
autoCapture : Bool = true,
hideNavigationBar : Bool = true,
bracketLengthInHorizontal : Int = 80,
bracketLengthInVertical : Int = 50,
defaultBracketMarginWidth : CGFloat = 0.5,
defaultBracketMarginHeight : CGFloat = 0.6,
allowBox: Bool = true,
autoCapture: Bool = true,
hideNavigationBar: Bool = true,
bracketLengthInHorizontal: Int = 80,
bracketLengthInVertical: Int = 50,
defaultBracketMarginWidth: CGFloat = 0.5,
defaultBracketMarginHeight: CGFloat = 0.6,
colorHold: CGColor = UIColor.yellow.cgColor,
colorCapturing: CGColor = UIColor.green.cgColor,
colorReposition: CGColor = UIColor.red.cgColor,
colorBracketAlign: CGColor = UIColor.black.cgColor,
colorBracketCloser: CGColor = UIColor.red.cgColor,
colorBracketHold: CGColor = UIColor.yellow.cgColor,
colorBracketCapture: CGColor = UIColor.green.cgColor,
defaultImageUrl: String = "",
showBackButton: Bool = true) {

self.timeInMsPerDigit = timeInMsPerDigit
self.digitsToShow = digitsToShow
self.allowBox = allowBox
Expand All @@ -58,6 +59,7 @@ import UIKit
self.defaultBracketMarginHeight = defaultBracketMarginHeight
self.colorHold = colorHold
self.colorCapturing = colorCapturing
self.colorReposition = colorReposition
self.colorBracketAlign = colorBracketAlign
self.colorBracketCloser = colorBracketCloser
self.colorBracketHold = colorBracketHold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ import UIKit

@objc public protocol DocumentCaptureDelegate {
func readyToCapture()
func documentCaptured(image:UIImage, barcodeString:String?)
func documentCaptured(image: UIImage, barcodeString: String?)
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ import AcuantCommon
coordinator.animate(alongsideTransition: { [weak self] context in
guard let self = self else { return }

self.rotateCameraPreview(to: self.view.window?.interfaceOrientation)
let newFrame = CGRect(origin: self.view.frame.origin, size: size)
self.rotateCameraPreview(to: self.view.window?.interfaceOrientation, frame: newFrame)
})
}

Expand Down Expand Up @@ -160,7 +161,7 @@ import AcuantCommon
autoCaptureDelegate: self,
captureDevice: captureDevice)
self.captureSession.start()
cameraPreviewView = CameraPreviewView(frame: view.bounds, captureSession: captureSession)
cameraPreviewView = CameraPreviewView(frame: view.frame, captureSession: captureSession)
cameraPreviewView.videoPreviewLayer.videoGravity = UIDevice.current.userInterfaceIdiom == .pad
? .resizeAspectFill
: .resizeAspect
Expand All @@ -172,7 +173,7 @@ import AcuantCommon
self.cameraPreviewView.layer.addSublayer(self.cornerLayer)
self.view.addSubview(cameraPreviewView)

rotateCameraPreview(to: self.view.window?.interfaceOrientation)
rotateCameraPreview(to: self.view.window?.interfaceOrientation, frame: view.frame)

if self.options.showBackButton {
addNavigationBackButton()
Expand All @@ -198,27 +199,27 @@ import AcuantCommon
return image
}

private func rotateCameraPreview(to interfaceOrientation: UIInterfaceOrientation?) {
private func rotateCameraPreview(to interfaceOrientation: UIInterfaceOrientation?, frame: CGRect) {
guard let connection = cameraPreviewView.videoPreviewLayer.connection,
connection.isVideoOrientationSupported,
let orientation = interfaceOrientation else {
return
}

cameraPreviewView.frame = view.bounds
cameraPreviewView.frame = frame
connection.videoOrientation = orientation.videoOrientation ?? .portrait
cameraPreviewView.clearAccessibilityElements()

if orientation.isLandscape {
messageLayer.transform = CATransform3DIdentity
messageLayer.setFrame(frame: view.bounds)
cornerLayer.setHorizontalDefaultCorners(frame: view.bounds)
messageLayer.setFrame(frame: frame)
cornerLayer.setHorizontalDefaultCorners(frame: frame)
} else {
if CATransform3DIsIdentity(messageLayer.transform) {
messageLayer.rotate(angle: 90)
}
messageLayer.setVerticalDefaultSettings(frame: view.bounds)
cornerLayer.setFrame(frame: view.bounds)
messageLayer.setVerticalDefaultSettings(frame: frame)
cornerLayer.setFrame(frame: frame)
}
cameraPreviewView.videoPreviewLayer.removeAllAnimations()
}
Expand Down Expand Up @@ -271,21 +272,21 @@ import AcuantCommon
}

if interfaceOrientation.isLandscape {
landscapeSetting(view.bounds)
landscapeSetting(view.frame)
} else {
portraitSetting(view.bounds)
portraitSetting(view.frame)
}
}

private func cancelCapture(state: CameraState, message: String){
private func cancelCapture(state: CameraState, message: String) {
self.setLookFromState(state: state)
self.messageLayer.string = message
self.triggerHoldSteady()
self.captureTimerState = 0.0
}

private func triggerHoldSteady(){
if(!self.isHoldSteady && self.autoCapture){
private func triggerHoldSteady() {
if !self.isHoldSteady && self.autoCapture {
self.isHoldSteady = true
holdSteadyTimer = Timer.scheduledTimer(
timeInterval: 0.1,
Expand Down Expand Up @@ -424,13 +425,12 @@ extension DocumentCameraController: DocumentCaptureDelegate {
public func readyToCapture() {
DispatchQueue.main.async {
if self.messageLayer != nil {
self.messageLayer.string = NSLocalizedString("acuant_camera_capturing", comment: "")
if self.autoCapture {
self.setLookFromState(state: DocumentCameraController.CameraState.Capture)
self.setMessageCaptureSettings()
} else {
self.setMessageDefaultSettings()
}
self.messageLayer.string = NSLocalizedString("acuant_camera_capturing", comment: "")
self.captured = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ import AcuantImagePreparation
var scaledPoints = [CGPoint]()
var resolutionThreshold = CaptureConstants.MANDATORY_RESOLUTION_THRESHOLD_DEFAULT

if self.isDocumentAligned(croppedFrame.points), self.shouldShowBorder {
if self.shouldShowBorder {
croppedFrame.points.forEach{ point in
var scaled: CGPoint = CGPoint()
scaled.x = point.x/frameSize.width as CGFloat
Expand All @@ -162,21 +162,26 @@ import AcuantImagePreparation
resolutionThreshold = Int(Double(frameSize.width) * smallerDocumentDPIRatio)
}

if croppedFrame.error?.errorCode == AcuantErrorCodes.ERROR_CouldNotCrop || croppedFrame.dpi < CaptureConstants.NO_DOCUMENT_DPI_THRESHOLD {
let frameRect = CGRect(origin: CGPoint(x: 0, y: 0), size: frameSize).insetBy(dx: 15, dy: 15)
let detectedRect = CGRect(points: croppedFrame.points)

if croppedFrame.error?.errorCode == AcuantErrorCodes.ERROR_CouldNotCrop
|| croppedFrame.dpi < CaptureConstants.NO_DOCUMENT_DPI_THRESHOLD
|| !self.isDocumentAligned(croppedFrame.points) {
return (.NO_DOCUMENT, scaledPoints)
} else if !croppedFrame.isCorrectAspectRatio {
return (.BAD_ASPECT_RATIO, scaledPoints)
} else if croppedFrame.error?.errorCode == AcuantErrorCodes.ERROR_LowResolutionImage, croppedFrame.dpi < resolutionThreshold {
return (.SMALL_DOCUMENT, scaledPoints)
} else if !croppedFrame.isCorrectAspectRatio {
return (.BAD_ASPECT_RATIO, scaledPoints)
} else if CGRect(points: croppedFrame.points) != nil {
return (.GOOD_DOCUMENT, scaledPoints)
} else {
} else if let rect = detectedRect, !frameRect.contains(rect) {
return (.DOCUMENT_NOT_IN_FRAME, scaledPoints)
} else {
return (.GOOD_DOCUMENT, scaledPoints)
}
}

public func getFrameMatchThreshold(cropDuration: Double) -> Int{
switch(cropDuration){
public func getFrameMatchThreshold(cropDuration: Double) -> Int {
switch cropDuration {
case 0..<0.8:
return FAST_FRAME_THRESHOLD
default:
Expand Down
Loading

0 comments on commit fb237d0

Please sign in to comment.