scala can do this, too

20
Scala can do this, too Matic Potocnik @ Scala Slovenia, 08.09.2016

Upload: matic-potocnik

Post on 22-Jan-2018

111 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Scala can do this, too

Scala can do this, too

Matic Potocnik @ Scala Slovenia, 08.09.2016

Page 2: Scala can do this, too

Overview of Projects

Projects we’ll look at today

• IRC Bot

• OCR Optimization

• Digital Art Installation

• Color Correction

1

Page 3: Scala can do this, too

IRC Bot - Overview

The usual bot features

• Greeting new users

• Passing messages to offline users

• Wordplay and telling jokes

• Posting to social media

• ...

2

Page 4: Scala can do this, too

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

Page 5: Scala can do this, too

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

Page 6: Scala can do this, too

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

Page 7: Scala can do this, too

OCR Optimizer - Design

MCQBIG

INPUT

ImageMagick OCR MLQBIG

OUTPUT

Comparator(LEVENSHTEIN)

Parameter generator(GENETIC ALGORITHMS)

-sigmoidal-contrast 1x78% -black-treshold 90% -negate

6

Page 8: Scala can do this, too

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

Page 9: Scala can do this, too

Digital Art Installation - Overview

Liminoidby Sasa Spacal & Matic Potocnik

produced by: LJUDMILA

8

Page 10: Scala can do this, too

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

Page 11: Scala can do this, too

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

Page 12: Scala can do this, too

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

Page 13: Scala can do this, too

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

Page 14: Scala can do this, too

Color Correction - Computer Vision

JavaCV

ASIFT algorithm to detect the color chart

13

Page 15: Scala can do this, too

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

Page 16: Scala can do this, too

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

Page 17: Scala can do this, too

Conclusion

16

Page 18: Scala can do this, too

Conclusion

17

Page 19: Scala can do this, too

Conclusion

18

Page 20: Scala can do this, too

Scala can do this, too

Questions?

• IRC Bot

• OCR Optimization

• Digital Art Installation

• Color Correction

19