scala can do this, too
TRANSCRIPT
Scala can do this, too
Matic Potocnik @ Scala Slovenia, 08.09.2016
Overview of Projects
Projects we’ll look at today
• IRC Bot
• OCR Optimization
• Digital Art Installation
• Color Correction
1
IRC Bot - Overview
The usual bot features
• Greeting new users
• Passing messages to offline users
• Wordplay and telling jokes
• Posting to social media
• ...
2
IRC Bot - Scala
• String interpolations"Hello, $toGreet!" ⇒ Hello, World!
• Parser combinatorsc"[Hi|Hello] {there}, $toGreet{!|.}" ⇒ Hi there, World!
c"[Hi|Hello] {there}, $toGreet{!|.}" ⇒ Hello, World.
c"[Hi|Hello] {there}, $toGreet{!|.}" ⇒ Hello there, World
c"[Hi|Hello] {there}, $toGreet{!|.}" ⇒ ...
3
IRC Bot - Scala
• Regex + Pattern matching
val cmd = "@([a-z]+) (.*)".r
input match {case cmd("msg", message) =>
/*handle message*/
case cmd("retweet", url)
if (url.matches(Regexes.URL)) =>
/*handle url*/
/*more cases*/
}
4
OCR Optimizer - Context
Scanning books and documentsOCR is hard in general... but easier for e.g. a single scan job
PreprocessingThresholding, removing stains, rotating, ...
⇒
5
OCR Optimizer - Design
MCQBIG
INPUT
ImageMagick OCR MLQBIG
OUTPUT
Comparator(LEVENSHTEIN)
Parameter generator(GENETIC ALGORITHMS)
-sigmoidal-contrast 1x78% -black-treshold 90% -negate
6
OCR Optimizer - Scala
• FuturesThe next talk will tell you more...
I mostly used them to spawn processes,
and misused Await for process timeout
• ProcessAs easy as: s"tesseract-ocr $image".!!
Also supports pipes, redirects, &&, ||, ...
Better libraries such as lihaoyi/Ammonite exist
• rockymadden/stringmetricString and phonetic similarity metrics
7
Digital Art Installation - Overview
Liminoidby Sasa Spacal & Matic Potocnik
produced by: LJUDMILA
8
Digital Art Installation - Context
Software development in artFrameworks and libraries exist for lots of stacks
I opted for Scala and LWJGL (plain OpenGL library)
Worked better than past projects (C++, VVVV, Python)
Art in software developmentVery different process than developing software by spec,
not much attachment to already written code or style,
playing with code is important for project progress
9
Digital Art Installation - Animation
Animation playerA moving particle mandala proved too hard for video codecs,
and the player was rigid and hard to integrate with OpenGL,
so we wrote a player, which handled sequences of PNG files
10
Digital Art Installation - Performance
Performance OptimizationHard to avoid noticeable pauses in VR
-XX:MaxGCPauseMillis to get frequent short GC pauses
Tried to keep variable scope and allocations to a minimum
Precomputing some things and reusing them
FutureLooking forward to improvements in 2.12 and Scala Native
11
Color Correction - Context
Color in the context of geology
Cheaply simplify and improve accuracy
0
5
10
15
Brez korekcije Premik Uteženo povpre/je
Linearna kombinacija Linearna kombinacija II
12
Color Correction - Computer Vision
JavaCV
ASIFT algorithm to detect the color chart
13
Color Correction - GUI
Scala Swing
It’s nicer than Java Swing, if that counts
Terse nested syntax, some reactive features
Moved out of stdlib and deprecated now ⇒ ScalaFX exists
14
Color Correction - Conclusion
Why else Scala?
Color library easier to write with expressive type system
Making code parallel and fast is simple (tnx scala-blitz)
All Java libraries still available (Jrawio, JavaCV, ...)
Numeric math is easier to get right (tnx Breeze, tnx Linter ;))
15
Conclusion
16
Conclusion
17
Conclusion
18
Scala can do this, too
Questions?
• IRC Bot
• OCR Optimization
• Digital Art Installation
• Color Correction
19