Slide 21
Slide 21 text
lazy var barcodeClassificationRequest: VNDetectBarcodesRequest = {
return VNDetectBarcodesRequest(completionHandler: { request, error in
guard let observations = request.results as? [VNBarcodeObservation] else {
return
}
let rects = observations.map { $0.boundingBox }
DispatchQueue.main.async { [weak self] in
for rect in rects {
let view = UIView(frame: convertedRect(rect: rect, to: self!.imageView.frame.size))
view.backgroundColor = .green
self?.imageView.addSubview(view)
}
}
let _ = observations.flatMap { observation -> CIBarcodeDescriptor? in
if let desc = observation.barcodeDescriptor as? CIBarcodeDescriptor {
return desc
} else {
return nil
}
}
})
}()