Showing
1 changed file
with
14 additions
and
17 deletions
| 1 | // | 1 | // |
| 2 | -// SwiftMobileScanner.swift | 2 | +// MobileScanner.swift |
| 3 | // mobile_scanner | 3 | // mobile_scanner |
| 4 | // | 4 | // |
| 5 | // Created by Julian Steenbakker on 15/02/2022. | 5 | // Created by Julian Steenbakker on 15/02/2022. |
| @@ -54,7 +54,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -54,7 +54,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 54 | private let backgroundQueue = DispatchQueue(label: "camera-handling") | 54 | private let backgroundQueue = DispatchQueue(label: "camera-handling") |
| 55 | 55 | ||
| 56 | var standardZoomFactor: CGFloat = 1 | 56 | var standardZoomFactor: CGFloat = 1 |
| 57 | - | 57 | + |
| 58 | private var nextScanTime = 0.0 | 58 | private var nextScanTime = 0.0 |
| 59 | 59 | ||
| 60 | private var imagesCurrentlyBeingProcessed = false | 60 | private var imagesCurrentlyBeingProcessed = false |
| @@ -191,7 +191,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -191,7 +191,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 191 | throw MobileScannerError.cameraError(error) | 191 | throw MobileScannerError.cameraError(error) |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | - captureSession.sessionPreset = AVCaptureSession.Preset.photo; | 194 | + captureSession.sessionPreset = AVCaptureSession.Preset.photo |
| 195 | // Add video output. | 195 | // Add video output. |
| 196 | let videoOutput = AVCaptureVideoDataOutput() | 196 | let videoOutput = AVCaptureVideoDataOutput() |
| 197 | 197 | ||
| @@ -294,7 +294,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -294,7 +294,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 294 | public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { | 294 | public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { |
| 295 | switch keyPath { | 295 | switch keyPath { |
| 296 | case "torchMode": | 296 | case "torchMode": |
| 297 | - // off = 0; on = 1; auto = 2; | 297 | + // off = 0; on = 1; auto = 2 |
| 298 | let state = change?[.newKey] as? Int | 298 | let state = change?[.newKey] as? Int |
| 299 | torchModeChangeCallback(state) | 299 | torchModeChangeCallback(state) |
| 300 | case "videoZoomFactor": | 300 | case "videoZoomFactor": |
| @@ -348,7 +348,6 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -348,7 +348,6 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 348 | } | 348 | } |
| 349 | } | 349 | } |
| 350 | 350 | ||
| 351 | - | ||
| 352 | /// Analyze a single image | 351 | /// Analyze a single image |
| 353 | func analyzeImage(image: UIImage, position: AVCaptureDevice.Position, callback: @escaping BarcodeScanningCallback) { | 352 | func analyzeImage(image: UIImage, position: AVCaptureDevice.Position, callback: @escaping BarcodeScanningCallback) { |
| 354 | let image = VisionImage(image: image) | 353 | let image = VisionImage(image: image) |
| @@ -363,18 +362,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -363,18 +362,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 363 | 362 | ||
| 364 | var barcodesString: Array<String?>? | 363 | var barcodesString: Array<String?>? |
| 365 | 364 | ||
| 366 | - | ||
| 367 | - | ||
| 368 | -// /// Convert image buffer to jpeg | ||
| 369 | -// private func ciImageToJpeg(ciImage: CIImage) -> Data { | ||
| 370 | -// | ||
| 371 | -// // let ciImage = CIImage(cvPixelBuffer: latestBuffer) | ||
| 372 | -// let context:CIContext = CIContext.init(options: nil) | ||
| 373 | -// let cgImage:CGImage = context.createCGImage(ciImage, from: ciImage.extent)! | ||
| 374 | -// let uiImage:UIImage = UIImage(cgImage: cgImage, scale: 1, orientation: UIImage.Orientation.up) | ||
| 375 | -// | ||
| 376 | -// return uiImage.jpegData(compressionQuality: 0.8)!; | ||
| 377 | -// } | 365 | + // /// Convert image buffer to jpeg |
| 366 | + // private func ciImageToJpeg(ciImage: CIImage) -> Data { | ||
| 367 | + // | ||
| 368 | + // // let ciImage = CIImage(cvPixelBuffer: latestBuffer) | ||
| 369 | + // let context:CIContext = CIContext.init(options: nil) | ||
| 370 | + // let cgImage:CGImage = context.createCGImage(ciImage, from: ciImage.extent)! | ||
| 371 | + // let uiImage:UIImage = UIImage(cgImage: cgImage, scale: 1, orientation: UIImage.Orientation.up) | ||
| 372 | + // | ||
| 373 | + // return uiImage.jpegData(compressionQuality: 0.8)! | ||
| 374 | + // } | ||
| 378 | 375 | ||
| 379 | /// Rotates images accordingly | 376 | /// Rotates images accordingly |
| 380 | func imageOrientation( | 377 | func imageOrientation( |
-
Please register or login to post a comment