added confidence threshold while drawing

This commit is contained in:
Mautisim Munir 2022-10-28 20:19:04 +05:00
parent be07542ef7
commit 60bff660d2
3 changed files with 25 additions and 3 deletions

View File

@ -80,6 +80,18 @@ public class ComputerVisionPluginImpl implements ComputerVisionPlugin {
}
}
abbrev = abbrev.toUpperCase(Locale.ROOT);
// correct abbreviations here
switch (abbrev) {
case "P":
abbrev = "PE";
break;
case "T":
abbrev = "TH";
break;
case "S":
abbrev = "SP";
break;
}
XYZPointWithConfidence data = (XYZPointWithConfidence) field.get(bodyJoints);
assert data != null;
bodyJointsString = bodyJointsString.concat(String.format(abbrev+":%f,%f,%f=",data.x,data.y,data.z));

View File

@ -126,17 +126,22 @@ public class PoseTrackingResult extends ImageSolutionResult {
float x = 0;
float y = 0;
float z = 0;
float confidence = 1;
float presence = 1;
final List<Integer> ptsIdx = Arrays.asList(LEFT_EAR, LEFT_EYE, RIGHT_EYE, RIGHT_EAR);
for (Integer i :ptsIdx){
LandmarkProto.Landmark landmark = landmarks.get(i);
x+=landmark.getX();
y+=landmark.getY();
z+=landmark.getZ();
presence = min(presence,landmark.getPresence());
confidence = min(confidence,landmark.getVisibility());
}
x = x/ptsIdx.size();
y = y/ptsIdx.size();
z = z/ptsIdx.size();
LandmarkProto.Landmark midupper = LandmarkProto.Landmark.newBuilder().setX(x).setY(y).setZ(z).build();
LandmarkProto.Landmark midupper = LandmarkProto.Landmark.newBuilder().setX(x).setY(y).setZ(z)
.setVisibility(confidence).setPresence(presence).build();
LandmarkProto.Landmark midlower = getJointBetweenPoints(landmarks.get(MOUTH_LEFT), landmarks.get(MOUTH_RIGHT), 0.5f);

View File

@ -24,7 +24,9 @@ import com.google.mediapipe.solutioncore.ResultGlRenderer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/** A custom implementation of {@link ResultGlRenderer} to render {@link PoseTrackingResult}. */
@ -91,7 +93,10 @@ public class PoseTrackingResultGlRenderer implements ResultGlRenderer<PoseTracki
GLES20.glUseProgram(program);
GLES20.glUniformMatrix4fv(projectionMatrixHandle, 1, false, projectionMatrix, 0);
GLES20.glUniform1f(pointSizeHandle, KEYPOINT_SIZE);
ImmutableList<LandmarkProto.Landmark> landmarks = result.multiPoseLandmarks();
ImmutableList<LandmarkProto.Landmark> originalLandmarks = result.multiPoseLandmarks();
List<LandmarkProto.Landmark> landmarks = originalLandmarks.stream().filter((landmark -> {
return landmark.getVisibility() > 0.25 || landmark.getPresence()>0.25;
})).collect(Collectors.toList());
// Draw keypoints.