Skip to content

Instantly share code, notes, and snippets.

@duanebester
Last active May 31, 2018 20:51
Show Gist options
  • Save duanebester/c9b796df528af1d56fac2057c6531592 to your computer and use it in GitHub Desktop.
Save duanebester/c9b796df528af1d56fac2057c6531592 to your computer and use it in GitHub Desktop.
// Add class wrapping String for JSON Streaming
case class OcrString(ocr:String)
def imageOcr = Flow[BufferedImage].map(bi => {
val ocr = tesseract.doOCR(bi)
OcrString(ocr)
})
// Update route
path("image" / "ocr") {
post {
fileUpload("fileUpload") {
case (_, fileStream) =>
val inputStream = fileStream.runWith(StreamConverters.asInputStream())
val image = ImageIO.read(inputStream)
val ocr = Source
.single(image)
.via(imageToBinaryImage)
.via(bufferedImageToMat)
.via(enhanceMat)
.via(matToBufferedImage)
.via(imageDeSkew())
.via(imageOcr)
complete(ocr)
}
}
}
// Add implicit ocrFormat
object MyJsonProtocol
extends SprayJsonSupport
with DefaultJsonProtocol {
implicit val ocrFormat = jsonFormat1(OcrString.apply)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment