获取捕捉坐标完成
新bug: 目前画面出现了多余的人体遮罩
This commit is contained in:
@@ -15,6 +15,7 @@ import com.google.mediapipe.components.PermissionHelper
|
||||
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmarkList
|
||||
import com.google.mediapipe.framework.AndroidAssetUtil
|
||||
import com.google.mediapipe.framework.PacketGetter
|
||||
import com.google.mediapipe.framework.ProtoUtil
|
||||
import com.google.mediapipe.glutil.EglManager
|
||||
import com.google.protobuf.InvalidProtocolBufferException
|
||||
|
||||
@@ -80,14 +81,18 @@ class MainActivity : AppCompatActivity() {
|
||||
processor.videoSurfaceOutput.setFlipY(true)
|
||||
|
||||
|
||||
// 展示
|
||||
// 捕获获得的坐标数据包
|
||||
// 遇到InvalidProtocolBufferException
|
||||
// 参考 https://github.com/google/mediapipe/issues/1013
|
||||
ProtoUtil.registerTypeName(NormalizedLandmarkList::class.java,
|
||||
"mediapipe.NormalizedLandmarkList")
|
||||
processor.addPacketCallback(
|
||||
outputLandmarksStreamName
|
||||
) {
|
||||
Log.i(tag, "Received Landmark Packets.")
|
||||
try {
|
||||
val landmarkRaw = PacketGetter.getProtoBytes(it)
|
||||
val poseLandmarks = NormalizedLandmarkList.parseFrom(landmarkRaw)
|
||||
// 从这里可以获得每个特征点的座标
|
||||
val landmarkList = PacketGetter.getProto(it, NormalizedLandmarkList::class.java)
|
||||
Log.i(tag, getPoseLandmarksDebugString(landmarkList))
|
||||
} catch (exception: InvalidProtocolBufferException) {
|
||||
Log.e(tag, "failed to get protocol.", exception)
|
||||
}
|
||||
@@ -248,4 +253,26 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化输出捕捉的标志位置
|
||||
*/
|
||||
private fun getPoseLandmarksDebugString(poseLandmarks: NormalizedLandmarkList): String {
|
||||
val debugString = StringBuilder("Pose LandMarks: " + poseLandmarks.landmarkCount + "\n")
|
||||
for ((landMarkIndex, landmark) in poseLandmarks.landmarkList.withIndex()) {
|
||||
debugString.append(
|
||||
"\tLandMark ["
|
||||
+ landMarkIndex
|
||||
+ "]: ("
|
||||
+ landmark.x
|
||||
+ ","
|
||||
+ landmark.y
|
||||
+ ","
|
||||
+ landmark.z
|
||||
+ ")\n"
|
||||
)
|
||||
}
|
||||
|
||||
return debugString.toString()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user