[orx-realsense2] Fix support for multiple sensors
This commit is contained in:
45
orx-realsense2/src/demo/kotlin/DemoRS202.kt
Normal file
45
orx-realsense2/src/demo/kotlin/DemoRS202.kt
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import org.openrndr.application
|
||||||
|
import org.openrndr.color.ColorRGBa
|
||||||
|
import org.openrndr.draw.ColorFormat
|
||||||
|
import org.openrndr.draw.ColorType
|
||||||
|
import org.openrndr.draw.colorBuffer
|
||||||
|
import org.openrndr.draw.tint
|
||||||
|
import org.openrndr.extra.realsense2.RS2Sensor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* show how to use multiple RealSense sensors
|
||||||
|
*
|
||||||
|
* Tested with two sensors, only uses depth stream now
|
||||||
|
*/
|
||||||
|
fun main() {
|
||||||
|
application {
|
||||||
|
configure {
|
||||||
|
width = 1280
|
||||||
|
height = 720
|
||||||
|
}
|
||||||
|
program {
|
||||||
|
val sensorDescriptions = RS2Sensor.listSensors()
|
||||||
|
|
||||||
|
val sensors = sensorDescriptions.map {
|
||||||
|
it.open()
|
||||||
|
}
|
||||||
|
|
||||||
|
val depthFrames = sensors.map {
|
||||||
|
colorBuffer(640, 480, format = ColorFormat.R, type = ColorType.UINT16)
|
||||||
|
}
|
||||||
|
sensors.forEachIndexed { index, it ->
|
||||||
|
it.depthFrameReceived.listen {
|
||||||
|
it.copyTo(depthFrames[index])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
extend {
|
||||||
|
drawer.drawStyle.colorMatrix = tint(ColorRGBa.WHITE.shade(20.0))
|
||||||
|
for ((index, sensor) in sensors.withIndex()) {
|
||||||
|
sensor.waitForFrames()
|
||||||
|
drawer.image(depthFrames[index])
|
||||||
|
drawer.translate(640.0, 0.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@ private fun rs2_error.check() {
|
|||||||
enum class RS2DepthFormat {
|
enum class RS2DepthFormat {
|
||||||
UINT16
|
UINT16
|
||||||
}
|
}
|
||||||
class RS2SensorDescription(private val deviceList: rs2_device_list, private val deviceIndex: Int) {
|
data class RS2SensorDescription(private val deviceList: rs2_device_list, private val deviceIndex: Int) {
|
||||||
/**
|
/**
|
||||||
* open realsense sensor from description entry
|
* open realsense sensor from description entry
|
||||||
*/
|
*/
|
||||||
@@ -47,6 +47,9 @@ class RS2SensorDescription(private val deviceList: rs2_device_list, private val
|
|||||||
val config = rs2_create_config(error)
|
val config = rs2_create_config(error)
|
||||||
error.check()
|
error.check()
|
||||||
|
|
||||||
|
val info = rs2_get_device_info(device, RS2_CAMERA_INFO_SERIAL_NUMBER, error)
|
||||||
|
rs2_config_enable_device(config, info, error)
|
||||||
|
|
||||||
rs2_config_enable_stream(config, RS2_STREAM_DEPTH, 0, depthWidth, depthHeight, RS2_FORMAT_Z16, depthFps, error)
|
rs2_config_enable_stream(config, RS2_STREAM_DEPTH, 0, depthWidth, depthHeight, RS2_FORMAT_Z16, depthFps, error)
|
||||||
error.check()
|
error.check()
|
||||||
|
|
||||||
@@ -128,6 +131,9 @@ abstract class Sensor {
|
|||||||
*/
|
*/
|
||||||
val depthFrameReceived = Event<RS2FrameEvent>()
|
val depthFrameReceived = Event<RS2FrameEvent>()
|
||||||
|
|
||||||
|
|
||||||
|
abstract val serial: String
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a list of [Stream]s for the [Sensor]
|
* a list of [Stream]s for the [Sensor]
|
||||||
*/
|
*/
|
||||||
@@ -145,6 +151,8 @@ abstract class Sensor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DummySensor : Sensor() {
|
class DummySensor : Sensor() {
|
||||||
|
override val serial: String = "DummySensor-${System.identityHashCode(this)}"
|
||||||
|
|
||||||
override fun waitForFrames() {
|
override fun waitForFrames() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +169,16 @@ class RS2Sensor(
|
|||||||
private val pipelineProfile: rs2_pipeline_profile
|
private val pipelineProfile: rs2_pipeline_profile
|
||||||
|
|
||||||
) : Sensor() {
|
) : Sensor() {
|
||||||
|
|
||||||
|
override val serial: String by lazy {
|
||||||
|
val error = rs2_error()
|
||||||
|
val info = rs2_get_device_info(device, RS2_CAMERA_INFO_SERIAL_NUMBER, error)
|
||||||
|
val serial = info.string
|
||||||
|
error.close()
|
||||||
|
info.close()
|
||||||
|
serial
|
||||||
|
}
|
||||||
|
|
||||||
override fun waitForFrames() {
|
override fun waitForFrames() {
|
||||||
val error = rs2_error()
|
val error = rs2_error()
|
||||||
val frames = rs2_pipeline_wait_for_frames(pipeline, RS2_DEFAULT_TIMEOUT, error)
|
val frames = rs2_pipeline_wait_for_frames(pipeline, RS2_DEFAULT_TIMEOUT, error)
|
||||||
|
|||||||
Reference in New Issue
Block a user