[orx-boofcv] Add colorBuffer resize

This commit is contained in:
Ricardo Matias
2020-08-03 17:23:06 +02:00
committed by Edwin Jakobs
parent 51b8c38230
commit 4a24cb5fea
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import org.openrndr.application
import org.openrndr.boofcv.binding.*
import org.openrndr.color.ColorRGBa
import org.openrndr.draw.loadImage
fun main() {
application {
program {
// Load an image, convert to BoofCV format using orx-boofcv
val input = loadImage("demo-data/images/image-001.png").toPlanarU8()
val scaled = input.resize(0.5).toColorBuffer()
val scaled2 = input.resize(0.25).toColorBuffer()
val scaled3 = input.resize(0.1).toColorBuffer()
extend {
drawer.clear(ColorRGBa.BLACK)
drawer.translate(0.0, (height - scaled.bounds.height) / 2.0)
drawer.image(scaled)
drawer.image(scaled2, scaled.bounds.width, scaled.bounds.height - scaled2.height)
drawer.image(scaled3, scaled.bounds.width + scaled2.bounds.width, scaled.bounds.height - scaled3.height)
}
}
}
}

View File

@@ -0,0 +1,12 @@
package org.openrndr.boofcv.binding
import boofcv.abst.distort.FDistort
import boofcv.struct.image.ImageBase
fun <T : ImageBase<out ImageBase<*>>?> ImageBase<T>.resize(scaleX: Double, scaleY: Double = scaleX): T {
val scaled = this.createNew((this.width * scaleX).toInt(), (this.height * scaleY).toInt())
FDistort(this, scaled).scaleExt().apply()
return scaled
}