Overload method to allow for pose option parameters

This commit is contained in:
udamaster 2022-10-16 12:25:30 -04:00
parent 7f8fb91001
commit 4e7bcb8124

View File

@ -20,6 +20,7 @@ import java.util.List;
import java.util.stream.Collectors;
public class Lindera {
private ComputerVisionPlugin plugin;
private PoseTracking poseTracking;
// TODO: Verify that this is the timestamp used in Actual Plugin
@ -31,6 +32,7 @@ public class Lindera {
private CameraInput.CameraFacing cameraFacing = CameraInput.CameraFacing.FRONT;
private AppCompatActivity appCompatActivity;
private ViewGroup computerVisionContainerView;
public Lindera(ComputerVisionPlugin plugin){
this.plugin = plugin;
}
@ -46,9 +48,6 @@ public class Lindera {
this.cameraRotation = cameraRotation;
}
public void setupEventListener() {
poseTracking.setResultListener(
poseTrackingResult -> {
@ -70,6 +69,7 @@ public class Lindera {
return Arrays.stream(CameraInput.CameraFacing.values()).map(Enum::name).collect(Collectors.toList());
}
public void doOnDestroy(){
stopDetection();
appCompatActivity = null;
@ -86,26 +86,35 @@ public class Lindera {
}
/**
* To satisfy original API we start detection with reasonable
* default setting
* */
public void startDetection() {
startDetection(
PoseTrackingOptions.builder()
.setStaticImageMode(false)
.setLandmarkVisibility(false)
.setModelComplexity(1)
.setSmoothLandmarks(true)
.build()
);
}
public void startDetection(PoseTrackingOptions options){
// ensure that class is initalized
assert (appCompatActivity != null);
// Initializes a new MediaPipe Face Detection solution instance in the streaming mode.
poseTracking =
new PoseTracking(
appCompatActivity,
PoseTrackingOptions.builder()
.setStaticImageMode(false)
.setLandmarkVisibility(true)
.setModelComplexity(0)
.setSmoothLandmarks(true)
.build());
options);
poseTracking.setErrorListener(
(message, e) -> Log.e("Lindera", "MediaPipe Pose Tracking error:" + message));
cameraInput = new CameraInput(appCompatActivity);
cameraInput.setNewFrameListener(textureFrame -> poseTracking.send(textureFrame));
// Initializes a new Gl surface view with a user-defined PoseTrackingResultGlRenderer.
glSurfaceView =
new SolutionGlSurfaceView<>(
@ -124,6 +133,7 @@ public class Lindera {
glSurfaceView.setVisibility(View.VISIBLE);
computerVisionContainerView.requestLayout();
}
public void stopDetection(){
if (cameraInput != null) {
cameraInput.setNewFrameListener(null);
@ -138,13 +148,13 @@ public class Lindera {
timeStamp = 0;
}
private void landmarkToXYZPointWithConfidence(LandmarkProto.Landmark landmark,XYZPointWithConfidence bodyJoint){
bodyJoint.x = landmark.getX();
bodyJoint.y = landmark.getY();
bodyJoint.z = landmark.getZ();
bodyJoint.confidence = landmark.getVisibility();
}
private void landmarksToBodyJoints(ImmutableList<LandmarkProto.Landmark> landmarks , BodyJoints bodyJoints){
landmarkToXYZPointWithConfidence(landmarks.get(PoseTrackingResult.NOSE), bodyJoints.nose);
@ -209,5 +219,4 @@ public class Lindera {
glSurfaceView.getHeight());
}
}