diff --git a/demo-data/images/life-cover.jpg b/demo-data/images/life-cover.jpg new file mode 100644 index 00000000..4f27dfb1 Binary files /dev/null and b/demo-data/images/life-cover.jpg differ diff --git a/demo-data/images/vw-beetle.jpg b/demo-data/images/vw-beetle.jpg new file mode 100644 index 00000000..849631ea Binary files /dev/null and b/demo-data/images/vw-beetle.jpg differ diff --git a/orx-runway/src/demo/kotlin/DemoBASNet.kt b/orx-runway/src/demo/kotlin/DemoBASNet.kt new file mode 100644 index 00000000..7ef4c70f --- /dev/null +++ b/orx-runway/src/demo/kotlin/DemoBASNet.kt @@ -0,0 +1,26 @@ +import org.openrndr.application +import org.openrndr.draw.* +import org.openrndr.extra.runway.* + +/** + * This example requires a `runway/BASNet` model to be active in Runway. + */ +fun main() = application { + configure { + width = 331 + height = 400 + } + + program { + val image = loadImage("demo-data/images/life-cover.jpg") + + val result: BASNETResult = + runwayQuery("http://localhost:8000/query", BASNETRequest(image.toData())) + + val segmentImage = ColorBuffer.fromData(result.image) + + extend { + drawer.image(segmentImage, 0.0, 0.0) + } + } +} \ No newline at end of file diff --git a/orx-runway/src/demo/kotlin/DemoPersonSegmentation.kt b/orx-runway/src/demo/kotlin/DemoPersonSegmentation.kt new file mode 100644 index 00000000..dce7c79d --- /dev/null +++ b/orx-runway/src/demo/kotlin/DemoPersonSegmentation.kt @@ -0,0 +1,26 @@ +import org.openrndr.application +import org.openrndr.draw.* +import org.openrndr.extra.runway.* + +/** + * This example requires a `runway/Person-Segmentation` model to be active in Runway. + */ +fun main() = application { + configure { + width = 331 + height = 400 + } + + program { + val image = loadImage("demo-data/images/life-cover.jpg") + + val result: PersonSegmentationResult = + runwayQuery("http://localhost:8000/query", PersonSegmentationRequest(image.toData(), 0.2)) + + val segmentImage = ColorBuffer.fromData(result.image) + + extend { + drawer.image(segmentImage, 0.0, 0.0) + } + } +} \ No newline at end of file diff --git a/orx-runway/src/demo/kotlin/DemoU2Net.kt b/orx-runway/src/demo/kotlin/DemoU2Net.kt new file mode 100644 index 00000000..f79202e7 --- /dev/null +++ b/orx-runway/src/demo/kotlin/DemoU2Net.kt @@ -0,0 +1,26 @@ +import org.openrndr.application +import org.openrndr.draw.* +import org.openrndr.extra.runway.* + +/** + * This example requires a `runway/U-2-Net` model to be active in Runway. + */ +fun main() = application { + configure { + width = 305 + height = 400 + } + + program { + val image = loadImage("demo-data/images/vw-beetle.jpg") + + val result: U2NetResult = + runwayQuery("http://localhost:8000/query", U2NetRequest(image.toData())) + + val segmentImage = ColorBuffer.fromData(result.image) + + extend { + drawer.image(segmentImage, 0.0, 0.0) + } + } +} \ No newline at end of file diff --git a/orx-runway/src/main/kotlin/Presets.kt b/orx-runway/src/main/kotlin/Presets.kt index 5c5e96aa..419910ca 100644 --- a/orx-runway/src/main/kotlin/Presets.kt +++ b/orx-runway/src/main/kotlin/Presets.kt @@ -7,6 +7,11 @@ class AttnGANRequest(val caption: String) class AttnGANResult(val result: String) +// -- BASNET +class BASNETRequest(val image: String) + +class BASNETResult(val image: String) + // -- BDCN class BdcnRequest(val input_image: String) @@ -67,6 +72,17 @@ class DeOldifyResponse(val image: String) class DenseCapRequest(val image: String, @SerializedName("max_detections") val maxDetections: Int = 10) class DenseCapResponse(val bboxes: List>, val classes: List, val scores: List) +// -- Person-Segmentation +/** + * Automatically detects people and extracts them from photos + * + * @property image + * @property threshold [0.0, 1.0] + */ +class PersonSegmentationRequest(val image: String, val threshold: Double) + +class PersonSegmentationResult(val image: String) + // -- PoseNet class PoseNetRequest( val image: String, @@ -76,3 +92,7 @@ class PoseNetRequest( ) class PoseNetResponse(val poses: List>>, val scores: List) +// -- U-2-Net +class U2NetRequest(val image: String) + +class U2NetResult(val image: String) diff --git a/orx-runway/src/main/kotlin/RunwayHttp.kt b/orx-runway/src/main/kotlin/RunwayHttp.kt index e9d7b5fe..ee9c298a 100644 --- a/orx-runway/src/main/kotlin/RunwayHttp.kt +++ b/orx-runway/src/main/kotlin/RunwayHttp.kt @@ -44,14 +44,13 @@ inline fun runwayQuery(target: String, query: Q): R { try { val queryJson = Gson().toJson(query) val connection = URL(target).openConnection() as HttpURLConnection - //with(connection) { + connection.doOutput = true connection.connectTimeout = 1_000 connection.readTimeout = 200_000 connection.requestMethod = "POST" connection.setRequestProperty("Content-Type", "application/json") connection.setRequestProperty("Accept", "application/json") - //} val outputStream = connection.outputStream outputStream.write(queryJson.toByteArray()) @@ -59,9 +58,10 @@ inline fun runwayQuery(target: String, query: Q): R { val inputStream = connection.inputStream val responseJson = String(inputStream.readBytes()) - println(responseJson) + inputStream.close() connection.disconnect() + return Gson().fromJson(responseJson, R::class.java) } catch (e: SocketTimeoutException) { error("RunwayML connection timed out '$target'. Check if Runway and model are running.")