Skip to content

Instantly share code, notes, and snippets.

@codePrincess
Last active March 27, 2018 13:56
Show Gist options
  • Save codePrincess/5e54815193cd2dcad32701d17f12d828 to your computer and use it in GitHub Desktop.
Save codePrincess/5e54815193cd2dcad32701d17f12d828 to your computer and use it in GitHub Desktop.
func drawStroke(context: CGContext?, touch: UITouch) {
let location = touch.location(in: self)
if touch.type == .stylus {
minX = min(minX, Int(location.x))
minY = min(minY, Int(location.y))
maxX = max(maxX, Int(location.x))
maxY = max(maxY, Int(location.y))
//....
}
//....
}
public func setup () {
trackTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: {
timer in
//user pauses for more than a second when drawing
//let's draw a border around it and save the area to an uiimage
let now = Date().timeIntervalSince1970
if Int(self.lastTouchTimestamp!) > 0 && now - self.lastTouchTimestamp! > 1 {
self.drawDoodlingRect(context: self.context)
}
})
}
func drawDoodlingRect(context: CGContext?) {
let inset = 5
ocrImageRect = CGRect(x: minX - inset,
y: minY - inset,
width: (maxX-minX) + inset*2,
height: (maxY-minY) + 2*inset)
context!.strokePath()
//...
fetchOCRText()
}
func fetchOCRText () {
let ocrImage = image!.crop(rect: ocrImageRect!)
switch recognizeMode {
case .cognitiveServiceOCR:
recognizeWithCognitiveServiceOCR(ocrImage)
case .localMLModel:
recognizeWithLocalModel(ocrImage)
break
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment