Verified Commit 2bf5cce3 authored by Geoff Pado's avatar Geoff Pado

Create visualization view to draw detected text

parent 4a0bfcbe
......@@ -6,18 +6,24 @@ import UIKit
class PhotoEditingView: UIView {
init() {
imageView = PhotoEditingImageView()
visualizationView = DetectionVisualizationView()
super.init(frame: .zero)
backgroundColor = .primary
addSubview(imageView)
addSubview(visualizationView)
NSLayoutConstraint.activate([
imageView.centerXAnchor.constraint(equalTo: centerXAnchor),
imageView.centerYAnchor.constraint(equalTo: centerYAnchor),
imageView.widthAnchor.constraint(equalTo: widthAnchor),
imageView.heightAnchor.constraint(equalTo: heightAnchor)
])
imageView.heightAnchor.constraint(equalTo: heightAnchor),
visualizationView.centerXAnchor.constraint(equalTo: centerXAnchor),
visualizationView.centerYAnchor.constraint(equalTo: centerYAnchor),
visualizationView.widthAnchor.constraint(equalTo: widthAnchor),
visualizationView.heightAnchor.constraint(equalTo: heightAnchor)
])
}
var image: UIImage? {
......@@ -27,9 +33,52 @@ class PhotoEditingView: UIView {
}
}
var textObservations: [DetectedTextObservation]? {
get { return visualizationView.textObservations }
set(newTextObservations) {
visualizationView.textObservations = newTextObservations
}
}
// MARK: Boilerplate
private var imageView: PhotoEditingImageView
private var visualizationView: DetectionVisualizationView
@available(*, unavailable)
required init(coder: NSCoder) {
let className = String(describing: type(of: self))
fatalError("\(className) does not implement init(coder:)")
}
}
class DetectionVisualizationView: UIView {
init() {
super.init(frame: .zero)
backgroundColor = .clear
isOpaque = false
translatesAutoresizingMaskIntoConstraints = false
}
override func draw(_ rect: CGRect) {
super.draw(rect)
guard let textObservations = textObservations else { return }
UIColor.black.setFill()
textObservations.forEach { observation in
UIBezierPath(rect: observation.bounds).fill()
}
}
var textObservations: [DetectedTextObservation]? {
didSet {
setNeedsDisplay()
}
}
// MARK: Boilerplate
@available(*, unavailable)
required init(coder: NSCoder) {
......
......@@ -29,7 +29,9 @@ class PhotoEditingViewController: UIViewController {
guard let image = image, isDegraded == false else { return }
self?.textRectangleDetector.detectTextRectangles(in: image) { (textObservations) in
dump(textObservations)
DispatchQueue.main.async { [weak self] in
self?.photoEditingView?.textObservations = textObservations
}
}
DispatchQueue.main.async { [weak self] in
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment