fixed scan area calculation

This commit is contained in:
Haik Aslanyan
2020-03-18 10:45:18 +04:00
parent 42f7fb1d85
commit 7f086fbdfe
3 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -25,6 +25,7 @@ import UIKit
final class RCImageDecoder {
var size = 0
lazy var sectionSize = self.size / 5
}
@@ -32,7 +33,6 @@ extension RCImageDecoder {
func process(pointer: UnsafeMutablePointer<UInt8>) throws -> [RCBit] {
let bufferData = UnsafeMutableBufferPointer<UInt8>(start: pointer, count: size * size)
let data = RCMatrix<UInt8>(rows: size, items: bufferData)
let sectionSize = size / 5
let sectors = Side.allCases.map { side -> (side: Side, x: Int, y: Int) in
switch side {
case .top:
@@ -103,6 +103,7 @@ extension RCCameraViewController {
super.viewDidLayoutSubviews()
configureMaskLayer()
videoPreviewLayer?.frame = view.bounds
calculateScanArea()
}
}
@@ -147,6 +148,7 @@ extension RCCameraViewController {
do {
captureSession.sessionPreset = .hd1280x720
coder.set(size: 720)
calculateScanArea()
let input = try AVCaptureDeviceInput(device: captureDevice)
input.device.activeVideoMaxFrameDuration = CMTimeMake(value: 1, timescale: 30)
captureSession.addInput(input)
@@ -159,6 +161,14 @@ extension RCCameraViewController {
}
}
private func calculateScanArea() {
let actualWidth = view.frame.height / 16 * 9
var sideArea: CGFloat = min(view.bounds.width, view.bounds.height) * 0.9 * 0.2
sideArea += (actualWidth - min(view.bounds.width, view.bounds.height) * 0.9) / 2
let area = sideArea / min(view.bounds.width, view.bounds.height) * 720
coder.set(scanArea: Int(area))
}
private func configureVideoPreview(orientation: AVCaptureVideoOrientation = .portrait) {
videoPreviewLayer?.removeFromSuperlayer()
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
+4
View File
@@ -64,4 +64,8 @@ extension RCCoder {
func set(size: Int) {
imageDecoder.size = size
}
func set(scanArea: Int) {
imageDecoder.sectionSize = scanArea
}
}