Skip to content

Commit

Permalink
added 11.5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
sMaltsevAcuant committed Dec 1, 2022
1 parent fb237d0 commit 92d5799
Show file tree
Hide file tree
Showing 156 changed files with 2,230 additions and 2,083 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import AVFoundation
private let captureVideoOutput = AVCaptureVideoDataOutput()
private var captureDeviceInput: AVCaptureDeviceInput!
private let captureDevice: AVCaptureDevice!
private let defaultVideoZoomFactor = 1.6
private weak var delegate: BarcodeCaptureDelegate?

init(captureDevice: AVCaptureDevice, delegate: BarcodeCaptureDelegate) {
Expand All @@ -29,6 +30,7 @@ import AVFoundation
self.configureMetadataOutput()
self.commitConfiguration()
self.startRunning()
self.applyZoom()
DispatchQueue.main.async {
completion()
}
Expand Down Expand Up @@ -63,6 +65,55 @@ import AVFoundation
}
}

private func applyZoom() {
if #available(iOS 15.0, *) {
let zoomFactor = getRecommendedZoomFactor()
try? captureDevice.lockForConfiguration()
captureDevice.videoZoomFactor = zoomFactor
captureDevice.unlockForConfiguration()
} else {
try? captureDevice.lockForConfiguration()
if captureDevice.maxAvailableVideoZoomFactor >= defaultVideoZoomFactor {
captureDevice.videoZoomFactor = defaultVideoZoomFactor
}
captureDevice.unlockForConfiguration()
}
}

@available(iOS 15.0, *)
private func getRecommendedZoomFactor() -> Double {
let deviceMinimumFocusDistance = Float(captureDevice.minimumFocusDistance)
guard deviceMinimumFocusDistance != -1 else { return defaultVideoZoomFactor }

let formatDimensions = CMVideoFormatDescriptionGetDimensions(captureDevice.activeFormat.formatDescription)
let rectOfInterestWidth = Float(formatDimensions.height) / Float(formatDimensions.width)
let deviceFieldOfView = captureDevice.activeFormat.videoFieldOfView
let minimumSubjectDistanceForDoc = minimumSubjectDistanceForDoc(fieldOfView: deviceFieldOfView,
minimumDocSizeInMillimeters: 85,
previewFillPercentage: rectOfInterestWidth)
var zoomFactor = 0.0
if minimumSubjectDistanceForDoc < deviceMinimumFocusDistance {
let optimalZoomFactor = Double(deviceMinimumFocusDistance / minimumSubjectDistanceForDoc)
if optimalZoomFactor <= captureDevice.maxAvailableVideoZoomFactor {
zoomFactor = optimalZoomFactor
}
} else if defaultVideoZoomFactor <= captureDevice.maxAvailableVideoZoomFactor {
zoomFactor = defaultVideoZoomFactor
}

return zoomFactor
}

private func minimumSubjectDistanceForDoc(fieldOfView: Float, minimumDocSizeInMillimeters: Float, previewFillPercentage: Float) -> Float {
let radians = degreesToRadians(fieldOfView / 2)
let filledDocSize = minimumDocSizeInMillimeters / previewFillPercentage
return filledDocSize / (2 * tan(radians))
}

private func degreesToRadians(_ degrees: Float) -> Float {
return degrees * Float.pi / 180
}

}

//MARK: - AVCaptureMetadataOutputObjectsDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import AcuantImagePreparation
private let DEFAULT_FRAME_THRESHOLD = 1
private let FAST_FRAME_THRESHOLD = 3
private let TOO_SLOW_FOR_AUTO_CAPTURE = 130
private let VIDEO_ZOOM_FACTOR = 1.6
private let DEFAULT_VIDEO_ZOOM_FACTOR = 1.6
private var autoCapture = true
weak private var autoCaptureDelegate: AutoCaptureDelegate?
private var captureEnabled = true
Expand Down Expand Up @@ -121,13 +121,58 @@ import AcuantImagePreparation
self.captureMetadataOutput.metadataObjectTypes = [.pdf417]
}
self.startRunning()
try? videoDevice.lockForConfiguration()
if videoDevice.maxAvailableVideoZoomFactor >= VIDEO_ZOOM_FACTOR {
videoDevice.videoZoomFactor = VIDEO_ZOOM_FACTOR
applyZoom(captureDevice: videoDevice)
}

private func applyZoom(captureDevice: AVCaptureDevice) {
if #available(iOS 15.0, *) {
let zoomFactor = getRecommendedZoomFactor(captureDevice: captureDevice)
try? captureDevice.lockForConfiguration()
captureDevice.videoZoomFactor = zoomFactor
captureDevice.unlockForConfiguration()
} else {
try? captureDevice.lockForConfiguration()
if captureDevice.maxAvailableVideoZoomFactor >= DEFAULT_VIDEO_ZOOM_FACTOR {
captureDevice.videoZoomFactor = DEFAULT_VIDEO_ZOOM_FACTOR
}
captureDevice.unlockForConfiguration()
}
videoDevice.unlockForConfiguration()
}

@available(iOS 15.0, *)
private func getRecommendedZoomFactor(captureDevice: AVCaptureDevice) -> Double {
let deviceMinimumFocusDistance = Float(captureDevice.minimumFocusDistance)
guard deviceMinimumFocusDistance != -1 else { return DEFAULT_VIDEO_ZOOM_FACTOR }

let formatDimensions = CMVideoFormatDescriptionGetDimensions(captureDevice.activeFormat.formatDescription)
let rectOfInterestWidth = Float(formatDimensions.height) / Float(formatDimensions.width)
let deviceFieldOfView = captureDevice.activeFormat.videoFieldOfView
let minimumSubjectDistanceForDoc = minimumSubjectDistanceForDoc(fieldOfView: deviceFieldOfView,
minimumDocSizeInMillimeters: 85,
previewFillPercentage: rectOfInterestWidth)
var zoomFactor = 0.0
if minimumSubjectDistanceForDoc < deviceMinimumFocusDistance {
let optimalZoomFactor = Double(deviceMinimumFocusDistance / minimumSubjectDistanceForDoc)
if optimalZoomFactor <= captureDevice.maxAvailableVideoZoomFactor {
zoomFactor = optimalZoomFactor
}
} else if DEFAULT_VIDEO_ZOOM_FACTOR <= captureDevice.maxAvailableVideoZoomFactor {
zoomFactor = DEFAULT_VIDEO_ZOOM_FACTOR
}

return zoomFactor
}

private func minimumSubjectDistanceForDoc(fieldOfView: Float, minimumDocSizeInMillimeters: Float, previewFillPercentage: Float) -> Float {
let radians = degreesToRadians(fieldOfView / 2)
let filledDocSize = minimumDocSizeInMillimeters / previewFillPercentage
return filledDocSize / (2 * tan(radians))
}

private func degreesToRadians(_ degrees: Float) -> Float {
return degrees * Float.pi / 180
}

private func imageFromSampleBuffer(sampleBuffer: CMSampleBuffer) -> UIImage? {
guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return nil }
let ciImage = CIImage(cvPixelBuffer: imageBuffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import AcuantImagePreparation
private let maxReadingAttempts = 7
private let maxDistanceBetweenPoints = 100
private var readingAttempts = 0
private let defaultVideoZoomFactor = 1.6
private var previousPoints = [CGPoint]()
private var cropping = false
private var callback: ((AcuantMrzCameraController.MrzCameraState, AcuantMrzResult?, Array<CGPoint>?) -> Void)?
Expand All @@ -39,6 +40,7 @@ import AcuantImagePreparation
self.addCaptureDevice()
self.addVideoOutput()
self.startRunning()
self.applyZoom()
}

private func setFocusMode() {
Expand Down Expand Up @@ -70,13 +72,62 @@ import AcuantImagePreparation
}
}

private func applyZoom() {
if #available(iOS 15.0, *) {
let zoomFactor = getRecommendedZoomFactor()
try? captureDevice.lockForConfiguration()
captureDevice.videoZoomFactor = zoomFactor
captureDevice.unlockForConfiguration()
} else {
try? captureDevice.lockForConfiguration()
if captureDevice.maxAvailableVideoZoomFactor >= defaultVideoZoomFactor {
captureDevice.videoZoomFactor = defaultVideoZoomFactor
}
captureDevice.unlockForConfiguration()
}
}

@available(iOS 15.0, *)
private func getRecommendedZoomFactor() -> Double {
let deviceMinimumFocusDistance = Float(captureDevice.minimumFocusDistance)
guard deviceMinimumFocusDistance != -1 else { return defaultVideoZoomFactor }

let formatDimensions = CMVideoFormatDescriptionGetDimensions(captureDevice.activeFormat.formatDescription)
let rectOfInterestWidth = Float(formatDimensions.height) / Float(formatDimensions.width)
let deviceFieldOfView = captureDevice.activeFormat.videoFieldOfView
let minimumSubjectDistanceForDoc = minimumSubjectDistanceForDoc(fieldOfView: deviceFieldOfView,
minimumDocSizeInMillimeters: 125,
previewFillPercentage: rectOfInterestWidth)
var zoomFactor = 0.0
if minimumSubjectDistanceForDoc < deviceMinimumFocusDistance {
let optimalZoomFactor = Double(deviceMinimumFocusDistance / minimumSubjectDistanceForDoc)
if optimalZoomFactor <= captureDevice.maxAvailableVideoZoomFactor {
zoomFactor = optimalZoomFactor
}
} else if defaultVideoZoomFactor <= captureDevice.maxAvailableVideoZoomFactor {
zoomFactor = defaultVideoZoomFactor
}

return zoomFactor
}

private func minimumSubjectDistanceForDoc(fieldOfView: Float, minimumDocSizeInMillimeters: Float, previewFillPercentage: Float) -> Float {
let radians = degreesToRadians(fieldOfView / 2)
let filledDocSize = minimumDocSizeInMillimeters / previewFillPercentage
return filledDocSize / (2 * tan(radians))
}

private func degreesToRadians(_ degrees: Float) -> Float {
return degrees * Float.pi / 180
}

private func imageFromSampleBuffer(sampleBuffer: CMSampleBuffer) -> UIImage? {
guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return nil }
let ciImage = CIImage(cvPixelBuffer: imageBuffer)
guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else { return nil }
return UIImage(cgImage: cgImage)
}

private func getScaledPoints(points: [CGPoint], frameSize: CGSize) -> [CGPoint] {
var scaledPoints = [CGPoint]()

Expand Down
2 changes: 1 addition & 1 deletion AcuantiOSSDKV11.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Pod::Spec.new do |s|
s.swift_versions = ['5.5.2']
s.ios.deployment_target = '11.0'
s.name = "AcuantiOSSDKV11"
s.version = "11.5.7"
s.version = "11.5.8"
s.summary = "Acuant's latest SDK with most advanced image capture technology and optimized user workflow "
s.description = "Acuant's latest SDK with most advanced image capture technology and optimized user workflow.
Expand Down
10 changes: 5 additions & 5 deletions EmbeddedFrameworks/AcuantCommon.xcframework/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
<array>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>AcuantCommon.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>AcuantCommon.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if 0
#elif defined(__arm64__) && __arm64__
// Generated by Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
// Generated by Apple Swift version 5.7.1 (swiftlang-5.7.1.135.3 clang-1400.0.29.51)
#ifndef ACUANTCOMMON_SWIFT_H
#define ACUANTCOMMON_SWIFT_H
#pragma clang diagnostic push
Expand Down
Binary file not shown.
Loading

0 comments on commit 92d5799

Please sign in to comment.