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
| /** | |
| * Converts a list of bits (booleans) with big-endian ordering to its corresponding | |
| * integer. | |
| */ | |
| fun List<Boolean>.bigEndianBitsToInt(): Int { | |
| return reversed().foldIndexed(initial = 0) { bitNo: Int, output: Int, bit: Boolean -> | |
| output or (bit.toInt() shl bitNo) | |
| } | |
| } |
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
| /** | |
| * Uses OpenCV to decode an image that is an android test resource i.e. | |
| * a file from `src/androidTest/resources`. | |
| * Note that the resulting Mat will be empty if there was a problem loading the file. | |
| */ | |
| private fun loadOpenCvImage(testResourceFilename: String): Mat { | |
| val bytes: ByteArray = javaClass.classLoader!!.getResource(testResourceFilename).readBytes() | |
| val matOfByte = MatOfByte().apply { fromList(bytes.toList()) } | |
| return Imgcodecs.imdecode(matOfByte, CV_LOAD_IMAGE_COLOR) | |
| } |
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
| /** | |
| * Removes duplicate consecutive elements in a list, up to maxN duplicate consecutive elements | |
| * per group. | |
| * Ex. where maxN = 2: | |
| * [0, 0, 1, 2, 2, 4, 4, 4, 4] => [0, 1, 2, 4, 4] | |
| */ | |
| fun <T> List<T>.normalize(maxN: Int): List<T> { | |
| var nextIndexToConsider = 0 | |
| return windowed(size = maxN, step = 1, partialWindows = true) |
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
| fun getScreenCaptureSource( | |
| screenRectangle: Rectangle, | |
| numThreads: Int = 6, | |
| fpsPerThread: Int = 8, | |
| robot: Robot = Robot() | |
| ): Observable<BufferedImage> { | |
| val periodPerThreadMs: Long = 1000 / fpsPerThread.toLong() | |
| val perThreadOffsetMs: Long = periodPerThreadMs / numThreads | |
| val sources = (0 until numThreads).map { i -> |
OlderNewer