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