姿态坐标点对象

This commit is contained in:
jackfiled 2023-01-30 17:39:31 +08:00
parent 3253b6bcac
commit 3a58f83928

View File

@ -0,0 +1,70 @@
package top.rrricardo.motioncapture.models
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList
import java.nio.ByteBuffer
class PoseLandmark(
private val Type: Int,
private val X: Float,
private val Y: Float,
private val Z: Float,
private val Visibility: Float,
private val TimeStamp: Long) {
private val tolerance = 10E-6;
private val packetLength = 28;
fun toByteArray(): ByteArray {
val result = ByteBuffer.allocate(packetLength)
result.putInt(Type)
result.putFloat(X)
result.putFloat(Y)
result.putFloat(Z)
result.putFloat(Visibility)
result.putLong(TimeStamp)
return result.array()
}
fun valueOf(data: ByteArray): PoseLandmark {
val buffer = ByteBuffer.wrap(data)
val type = buffer.int
val x = buffer.float
val y = buffer.float
val z = buffer.float
val visibility = buffer.float
val timeStamp = buffer.long
return PoseLandmark(type, x, y, z, visibility, timeStamp)
}
fun valueOf(poseLandmarks: NormalizedLandmarkList, timeStamp: Long): Collection<PoseLandmark> {
val result = mutableSetOf<PoseLandmark>()
for ((landmarkIndex, landmark) in poseLandmarks.landmarkList.withIndex()) {
val poseLandmark = PoseLandmark(
landmarkIndex,
landmark.x,
landmark.y,
landmark.z,
landmark.visibility,
timeStamp
)
result.add(poseLandmark)
}
return result
}
override fun toString(): String {
val builder = StringBuilder()
builder.append("Time: $TimeStamp, Type: $Type\n")
builder.append("\tX:$X, Y:$Y, Z:$Z, Visibility: $Visibility\n")
return builder.toString()
}
}