Last active
May 31, 2018 20:51
-
-
Save duanebester/c9b796df528af1d56fac2057c6531592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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