Skip to content

Commit

Permalink
Improve resource reporting accuracy by trying different scale factors
Browse files Browse the repository at this point in the history
(3-5)
  • Loading branch information
waicool20 committed Mar 29, 2018
1 parent 8a6c868 commit 358d8d7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/kotlin/com/waicool20/kaga/kcauto/Resources.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@ data class Resources(
)

private fun Region.readNumber(scaleFactor: Double = 3.0, threshold: Double = 0.4): Int {
val image = screen.capture(this).image
.scale(scaleFactor).binarizeImage(threshold)
var text = TextRecognizer.getInstance().recognizeWord(image)
numberReplacements.forEach { r, num ->
text = text.replace(Regex("[$r]"), num)
}
return text.toIntOrNull() ?: run {
logger.error("Could not read number from text: $text")
-1
val stringList = mutableListOf<String>()
repeat(3) { i ->
val image = screen.capture(this).image
.scale(scaleFactor + i).binarizeImage(threshold)
var text = TextRecognizer.getInstance().recognizeWord(image)
numberReplacements.forEach { r, num ->
text = text.replace(Regex("[$r]"), num)
}
text.toIntOrNull()?.let {
return it
} ?: stringList.add(text)
}
logger.error("Could not read number from text: $stringList")
return -1
}
}
}

0 comments on commit 358d8d7

Please sign in to comment.