MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / KinectDriver

Class KinectDriver

src/main/java/trace/input/KinectDriver.kt:11–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9import java.nio.ShortBuffer
10
11
12class KinectDriver {
13
14
15 companion object {
16 @JvmField
17 var texture: Texture? = null
18 @JvmField
19 var floatFrame: FloatBuffer? = null
20
21 @JvmField
22 var dev: Device
23
24 @JvmField
25 var ctx: Context = Freenect.createContext()
26
27 var currentFrame: ByteBuffer? = null
28 var shortFrame: ShortBuffer? = null
29
30 var width: Int = -1
31 var height: Int = -1
32
33
34 var lock = Object()
35
36 init {
37 ctx.setLogHandler { dev, level, info ->
38 println("** $dev | $level `$info`")
39 }
40 ctx.setLogLevel(LogLevel.SPEW)
41
42 if (ctx.numDevices() > 0) {
43 dev = ctx.openDevice(0)
44
45 dev.setDepthFormat(DepthFormat.D11BIT)
46 } else {
47 throw IllegalArgumentException(" couldn't find a Kinect")
48 }
49
50 dev.startDepth(object : DepthHandler {
51 internal var frameCount = 0
52
53 override fun onFrameReceived(mode: FrameMode?, frame: ByteBuffer?, timestamp: Int) {
54 if (frame == null) {
55 System.err.println(" -- received null frame, continuing on")
56 return
57 }
58// println(" -- frame received, mode${mode?.depthFormat} / ${mode?.width} x ${mode?.height}")
59 if (currentFrame == null) {
60 currentFrame = ByteBuffer.allocate(frame.capacity()).order(ByteOrder.nativeOrder())
61 shortFrame = currentFrame!!.asShortBuffer()
62
63 val floatFrame_b = ByteBuffer.allocateDirect(shortFrame!!.capacity() * 4).order(ByteOrder.nativeOrder())
64 floatFrame = floatFrame_b.asFloatBuffer()
65
66 texture = Texture(Texture.TextureSpecification.float1(3, mode!!.width.toInt(), mode!!.height.toInt(), floatFrame_b))
67 }
68 synchronized(lock)

Callers

nothing calls this directly

Calls 1

ObjectFunction · 0.85

Tested by

no test coverage detected