Project import generated by Copybara.

GitOrigin-RevId: d4a11282d20fe4d2e137f9032cf349750030dcb9
This commit is contained in:
MediaPipe Team
2021-11-03 17:27:30 -07:00
committed by jqtang
parent 1faeaae7e5
commit d4bb35fe5a
72 changed files with 1089 additions and 336 deletions
@@ -32,9 +32,9 @@ public class FaceDetectionResultImageView extends AppCompatImageView {
private static final String TAG = "FaceDetectionResultImageView";
private static final int KEYPOINT_COLOR = Color.RED;
private static final int KEYPOINT_RADIUS = 15;
private static final int KEYPOINT_RADIUS = 8; // Pixels
private static final int BBOX_COLOR = Color.GREEN;
private static final int BBOX_THICKNESS = 10;
private static final int BBOX_THICKNESS = 5; // Pixels
private Bitmap latest;
public FaceDetectionResultImageView(Context context) {
@@ -28,7 +28,6 @@ import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.exifinterface.media.ExifInterface;
// ContentResolver dependency
import com.google.mediapipe.formats.proto.LocationDataProto.LocationData.RelativeKeypoint;
import com.google.mediapipe.solutioncore.CameraInput;
import com.google.mediapipe.solutioncore.SolutionGlSurfaceView;
import com.google.mediapipe.solutioncore.VideoInput;
@@ -36,6 +35,7 @@ import com.google.mediapipe.solutions.facedetection.FaceDetection;
import com.google.mediapipe.solutions.facedetection.FaceDetectionOptions;
import com.google.mediapipe.solutions.facedetection.FaceDetectionResult;
import com.google.mediapipe.solutions.facedetection.FaceKeypoint;
import com.google.mediapipe.formats.proto.LocationDataProto.LocationData.RelativeKeypoint;
import java.io.IOException;
import java.io.InputStream;
@@ -175,9 +175,9 @@ public class MainActivity extends AppCompatActivity {
setupStaticImageModePipeline();
}
// Reads images from gallery.
Intent gallery =
new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
imageGetter.launch(gallery);
Intent pickImageIntent = new Intent(Intent.ACTION_PICK);
pickImageIntent.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
imageGetter.launch(pickImageIntent);
});
imageView = new FaceDetectionResultImageView(this);
}
@@ -240,9 +240,9 @@ public class MainActivity extends AppCompatActivity {
stopCurrentPipeline();
setupStreamingModePipeline(InputSource.VIDEO);
// Reads video from gallery.
Intent gallery =
new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.INTERNAL_CONTENT_URI);
videoGetter.launch(gallery);
Intent pickVideoIntent = new Intent(Intent.ACTION_PICK);
pickVideoIntent.setDataAndType(MediaStore.Video.Media.INTERNAL_CONTENT_URI, "video/*");
videoGetter.launch(pickVideoIntent);
});
}
@@ -334,8 +334,15 @@ public class MainActivity extends AppCompatActivity {
private void logNoseTipKeypoint(
FaceDetectionResult result, int faceIndex, boolean showPixelValues) {
if (result.multiFaceDetections().isEmpty()) {
return;
}
RelativeKeypoint noseTip =
FaceDetection.getFaceKeypoint(result, faceIndex, FaceKeypoint.NOSE_TIP);
result
.multiFaceDetections()
.get(faceIndex)
.getLocationData()
.getRelativeKeypoints(FaceKeypoint.NOSE_TIP);
// For Bitmaps, show the pixel values. For texture inputs, show the normalized coordinates.
if (showPixelValues) {
int width = result.inputBitmap().getWidth();
@@ -34,19 +34,19 @@ public class FaceMeshResultImageView extends AppCompatImageView {
private static final String TAG = "FaceMeshResultImageView";
private static final int TESSELATION_COLOR = Color.parseColor("#70C0C0C0");
private static final int TESSELATION_THICKNESS = 5;
private static final int TESSELATION_THICKNESS = 3; // Pixels
private static final int RIGHT_EYE_COLOR = Color.parseColor("#FF3030");
private static final int RIGHT_EYE_THICKNESS = 8;
private static final int RIGHT_EYE_THICKNESS = 5; // Pixels
private static final int RIGHT_EYEBROW_COLOR = Color.parseColor("#FF3030");
private static final int RIGHT_EYEBROW_THICKNESS = 8;
private static final int RIGHT_EYEBROW_THICKNESS = 5; // Pixels
private static final int LEFT_EYE_COLOR = Color.parseColor("#30FF30");
private static final int LEFT_EYE_THICKNESS = 8;
private static final int LEFT_EYE_THICKNESS = 5; // Pixels
private static final int LEFT_EYEBROW_COLOR = Color.parseColor("#30FF30");
private static final int LEFT_EYEBROW_THICKNESS = 8;
private static final int LEFT_EYEBROW_THICKNESS = 5; // Pixels
private static final int FACE_OVAL_COLOR = Color.parseColor("#E0E0E0");
private static final int FACE_OVAL_THICKNESS = 8;
private static final int FACE_OVAL_THICKNESS = 5; // Pixels
private static final int LIPS_COLOR = Color.parseColor("#E0E0E0");
private static final int LIPS_THICKNESS = 8;
private static final int LIPS_THICKNESS = 5; // Pixels
private Bitmap latest;
public FaceMeshResultImageView(Context context) {
@@ -176,9 +176,9 @@ public class MainActivity extends AppCompatActivity {
setupStaticImageModePipeline();
}
// Reads images from gallery.
Intent gallery =
new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
imageGetter.launch(gallery);
Intent pickImageIntent = new Intent(Intent.ACTION_PICK);
pickImageIntent.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
imageGetter.launch(pickImageIntent);
});
imageView = new FaceMeshResultImageView(this);
}
@@ -240,9 +240,9 @@ public class MainActivity extends AppCompatActivity {
stopCurrentPipeline();
setupStreamingModePipeline(InputSource.VIDEO);
// Reads video from gallery.
Intent gallery =
new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.INTERNAL_CONTENT_URI);
videoGetter.launch(gallery);
Intent pickVideoIntent = new Intent(Intent.ACTION_PICK);
pickVideoIntent.setDataAndType(MediaStore.Video.Media.INTERNAL_CONTENT_URI, "video/*");
videoGetter.launch(pickVideoIntent);
});
}
@@ -28,7 +28,16 @@ import java.util.List;
public class HandsResultGlRenderer implements ResultGlRenderer<HandsResult> {
private static final String TAG = "HandsResultGlRenderer";
private static final float CONNECTION_THICKNESS = 20.0f;
private static final float[] LEFT_HAND_CONNECTION_COLOR = new float[] {0.2f, 1f, 0.2f, 1f};
private static final float[] RIGHT_HAND_CONNECTION_COLOR = new float[] {1f, 0.2f, 0.2f, 1f};
private static final float CONNECTION_THICKNESS = 25.0f;
private static final float[] LEFT_HAND_HOLLOW_CIRCLE_COLOR = new float[] {0.2f, 1f, 0.2f, 1f};
private static final float[] RIGHT_HAND_HOLLOW_CIRCLE_COLOR = new float[] {1f, 0.2f, 0.2f, 1f};
private static final float HOLLOW_CIRCLE_RADIUS = 0.01f;
private static final float[] LEFT_HAND_LANDMARK_COLOR = new float[] {1f, 0.2f, 0.2f, 1f};
private static final float[] RIGHT_HAND_LANDMARK_COLOR = new float[] {0.2f, 1f, 0.2f, 1f};
private static final float LANDMARK_RADIUS = 0.008f;
private static final int NUM_SEGMENTS = 120;
private static final String VERTEX_SHADER =
"uniform mat4 uProjectionMatrix;\n"
+ "attribute vec4 vPosition;\n"
@@ -37,12 +46,14 @@ public class HandsResultGlRenderer implements ResultGlRenderer<HandsResult> {
+ "}";
private static final String FRAGMENT_SHADER =
"precision mediump float;\n"
+ "uniform vec4 uColor;\n"
+ "void main() {\n"
+ " gl_FragColor = vec4(0, 1, 0, 1);\n"
+ " gl_FragColor = uColor;\n"
+ "}";
private int program;
private int positionHandle;
private int projectionMatrixHandle;
private int colorHandle;
private int loadShader(int type, String shaderCode) {
int shader = GLES20.glCreateShader(type);
@@ -61,6 +72,7 @@ public class HandsResultGlRenderer implements ResultGlRenderer<HandsResult> {
GLES20.glLinkProgram(program);
positionHandle = GLES20.glGetAttribLocation(program, "vPosition");
projectionMatrixHandle = GLES20.glGetUniformLocation(program, "uProjectionMatrix");
colorHandle = GLES20.glGetUniformLocation(program, "uColor");
}
@Override
@@ -74,7 +86,22 @@ public class HandsResultGlRenderer implements ResultGlRenderer<HandsResult> {
int numHands = result.multiHandLandmarks().size();
for (int i = 0; i < numHands; ++i) {
drawLandmarks(result.multiHandLandmarks().get(i).getLandmarkList());
boolean isLeftHand = result.multiHandedness().get(i).getLabel().equals("Left");
drawConnections(
result.multiHandLandmarks().get(i).getLandmarkList(),
isLeftHand ? LEFT_HAND_CONNECTION_COLOR : RIGHT_HAND_CONNECTION_COLOR);
for (NormalizedLandmark landmark : result.multiHandLandmarks().get(i).getLandmarkList()) {
// Draws the landmark.
drawCircle(
landmark.getX(),
landmark.getY(),
isLeftHand ? LEFT_HAND_LANDMARK_COLOR : RIGHT_HAND_LANDMARK_COLOR);
// Draws a hollow circle around the landmark.
drawHollowCircle(
landmark.getX(),
landmark.getY(),
isLeftHand ? LEFT_HAND_HOLLOW_CIRCLE_COLOR : RIGHT_HAND_HOLLOW_CIRCLE_COLOR);
}
}
}
@@ -87,7 +114,8 @@ public class HandsResultGlRenderer implements ResultGlRenderer<HandsResult> {
GLES20.glDeleteProgram(program);
}
private void drawLandmarks(List<NormalizedLandmark> handLandmarkList) {
private void drawConnections(List<NormalizedLandmark> handLandmarkList, float[] colorArray) {
GLES20.glUniform4fv(colorHandle, 1, colorArray, 0);
for (Hands.Connection c : Hands.HAND_CONNECTIONS) {
NormalizedLandmark start = handLandmarkList.get(c.start());
NormalizedLandmark end = handLandmarkList.get(c.end());
@@ -103,4 +131,51 @@ public class HandsResultGlRenderer implements ResultGlRenderer<HandsResult> {
GLES20.glDrawArrays(GLES20.GL_LINES, 0, 2);
}
}
private void drawCircle(float x, float y, float[] colorArray) {
GLES20.glUniform4fv(colorHandle, 1, colorArray, 0);
int vertexCount = NUM_SEGMENTS + 2;
float[] vertices = new float[vertexCount * 3];
vertices[0] = x;
vertices[1] = y;
vertices[2] = 0;
for (int i = 1; i < vertexCount; i++) {
float angle = 2.0f * i * (float) Math.PI / NUM_SEGMENTS;
int currentIndex = 3 * i;
vertices[currentIndex] = x + (float) (LANDMARK_RADIUS * Math.cos(angle));
vertices[currentIndex + 1] = y + (float) (LANDMARK_RADIUS * Math.sin(angle));
vertices[currentIndex + 2] = 0;
}
FloatBuffer vertexBuffer =
ByteBuffer.allocateDirect(vertices.length * 4)
.order(ByteOrder.nativeOrder())
.asFloatBuffer()
.put(vertices);
vertexBuffer.position(0);
GLES20.glEnableVertexAttribArray(positionHandle);
GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer);
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, vertexCount);
}
private void drawHollowCircle(float x, float y, float[] colorArray) {
GLES20.glUniform4fv(colorHandle, 1, colorArray, 0);
int vertexCount = NUM_SEGMENTS + 1;
float[] vertices = new float[vertexCount * 3];
for (int i = 0; i < vertexCount; i++) {
float angle = 2.0f * i * (float) Math.PI / NUM_SEGMENTS;
int currentIndex = 3 * i;
vertices[currentIndex] = x + (float) (HOLLOW_CIRCLE_RADIUS * Math.cos(angle));
vertices[currentIndex + 1] = y + (float) (HOLLOW_CIRCLE_RADIUS * Math.sin(angle));
vertices[currentIndex + 2] = 0;
}
FloatBuffer vertexBuffer =
ByteBuffer.allocateDirect(vertices.length * 4)
.order(ByteOrder.nativeOrder())
.asFloatBuffer()
.put(vertices);
vertexBuffer.position(0);
GLES20.glEnableVertexAttribArray(positionHandle);
GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 0, vertexBuffer);
GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, vertexCount);
}
}
@@ -31,10 +31,15 @@ import java.util.List;
public class HandsResultImageView extends AppCompatImageView {
private static final String TAG = "HandsResultImageView";
private static final int LANDMARK_COLOR = Color.RED;
private static final int LANDMARK_RADIUS = 15;
private static final int CONNECTION_COLOR = Color.GREEN;
private static final int CONNECTION_THICKNESS = 10;
private static final int LEFT_HAND_CONNECTION_COLOR = Color.parseColor("#30FF30");
private static final int RIGHT_HAND_CONNECTION_COLOR = Color.parseColor("#FF3030");
private static final int CONNECTION_THICKNESS = 8; // Pixels
private static final int LEFT_HAND_HOLLOW_CIRCLE_COLOR = Color.parseColor("#30FF30");
private static final int RIGHT_HAND_HOLLOW_CIRCLE_COLOR = Color.parseColor("#FF3030");
private static final int HOLLOW_CIRCLE_WIDTH = 5; // Pixels
private static final int LEFT_HAND_LANDMARK_COLOR = Color.parseColor("#FF3030");
private static final int RIGHT_HAND_LANDMARK_COLOR = Color.parseColor("#30FF30");
private static final int LANDMARK_RADIUS = 10; // Pixels
private Bitmap latest;
public HandsResultImageView(Context context) {
@@ -62,7 +67,11 @@ public class HandsResultImageView extends AppCompatImageView {
int numHands = result.multiHandLandmarks().size();
for (int i = 0; i < numHands; ++i) {
drawLandmarksOnCanvas(
result.multiHandLandmarks().get(i).getLandmarkList(), canvas, width, height);
result.multiHandLandmarks().get(i).getLandmarkList(),
result.multiHandedness().get(i).getLabel().equals("Left"),
canvas,
width,
height);
}
}
@@ -75,11 +84,16 @@ public class HandsResultImageView extends AppCompatImageView {
}
private void drawLandmarksOnCanvas(
List<NormalizedLandmark> handLandmarkList, Canvas canvas, int width, int height) {
List<NormalizedLandmark> handLandmarkList,
boolean isLeftHand,
Canvas canvas,
int width,
int height) {
// Draw connections.
for (Hands.Connection c : Hands.HAND_CONNECTIONS) {
Paint connectionPaint = new Paint();
connectionPaint.setColor(CONNECTION_COLOR);
connectionPaint.setColor(
isLeftHand ? LEFT_HAND_CONNECTION_COLOR : RIGHT_HAND_CONNECTION_COLOR);
connectionPaint.setStrokeWidth(CONNECTION_THICKNESS);
NormalizedLandmark start = handLandmarkList.get(c.start());
NormalizedLandmark end = handLandmarkList.get(c.end());
@@ -91,11 +105,23 @@ public class HandsResultImageView extends AppCompatImageView {
connectionPaint);
}
Paint landmarkPaint = new Paint();
landmarkPaint.setColor(LANDMARK_COLOR);
// Draw landmarks.
landmarkPaint.setColor(isLeftHand ? LEFT_HAND_LANDMARK_COLOR : RIGHT_HAND_LANDMARK_COLOR);
// Draws landmarks.
for (LandmarkProto.NormalizedLandmark landmark : handLandmarkList) {
canvas.drawCircle(
landmark.getX() * width, landmark.getY() * height, LANDMARK_RADIUS, landmarkPaint);
}
// Draws hollow circles around landmarks.
landmarkPaint.setColor(
isLeftHand ? LEFT_HAND_HOLLOW_CIRCLE_COLOR : RIGHT_HAND_HOLLOW_CIRCLE_COLOR);
landmarkPaint.setStrokeWidth(HOLLOW_CIRCLE_WIDTH);
landmarkPaint.setStyle(Paint.Style.STROKE);
for (LandmarkProto.NormalizedLandmark landmark : handLandmarkList) {
canvas.drawCircle(
landmark.getX() * width,
landmark.getY() * height,
LANDMARK_RADIUS + HOLLOW_CIRCLE_WIDTH,
landmarkPaint);
}
}
}
@@ -28,6 +28,7 @@ import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.exifinterface.media.ExifInterface;
// ContentResolver dependency
import com.google.mediapipe.formats.proto.LandmarkProto.Landmark;
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmark;
import com.google.mediapipe.solutioncore.CameraInput;
import com.google.mediapipe.solutioncore.SolutionGlSurfaceView;
@@ -177,9 +178,9 @@ public class MainActivity extends AppCompatActivity {
setupStaticImageModePipeline();
}
// Reads images from gallery.
Intent gallery =
new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);
imageGetter.launch(gallery);
Intent pickImageIntent = new Intent(Intent.ACTION_PICK);
pickImageIntent.setDataAndType(MediaStore.Images.Media.INTERNAL_CONTENT_URI, "image/*");
imageGetter.launch(pickImageIntent);
});
imageView = new HandsResultImageView(this);
}
@@ -193,7 +194,7 @@ public class MainActivity extends AppCompatActivity {
this,
HandsOptions.builder()
.setStaticImageMode(true)
.setMaxNumHands(1)
.setMaxNumHands(2)
.setRunOnGpu(RUN_ON_GPU)
.build());
@@ -241,9 +242,9 @@ public class MainActivity extends AppCompatActivity {
stopCurrentPipeline();
setupStreamingModePipeline(InputSource.VIDEO);
// Reads video from gallery.
Intent gallery =
new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.INTERNAL_CONTENT_URI);
videoGetter.launch(gallery);
Intent pickVideoIntent = new Intent(Intent.ACTION_PICK);
pickVideoIntent.setDataAndType(MediaStore.Video.Media.INTERNAL_CONTENT_URI, "video/*");
videoGetter.launch(pickVideoIntent);
});
}
@@ -269,7 +270,7 @@ public class MainActivity extends AppCompatActivity {
this,
HandsOptions.builder()
.setStaticImageMode(false)
.setMaxNumHands(1)
.setMaxNumHands(2)
.setRunOnGpu(RUN_ON_GPU)
.build());
hands.setErrorListener((message, e) -> Log.e(TAG, "MediaPipe Hands error:" + message));
@@ -336,7 +337,11 @@ public class MainActivity extends AppCompatActivity {
}
private void logWristLandmark(HandsResult result, boolean showPixelValues) {
NormalizedLandmark wristLandmark = Hands.getHandLandmark(result, 0, HandLandmark.WRIST);
if (result.multiHandLandmarks().isEmpty()) {
return;
}
NormalizedLandmark wristLandmark =
result.multiHandLandmarks().get(0).getLandmarkList().get(HandLandmark.WRIST);
// For Bitmaps, show the pixel values. For texture inputs, show the normalized coordinates.
if (showPixelValues) {
int width = result.inputBitmap().getWidth();
@@ -353,5 +358,16 @@ public class MainActivity extends AppCompatActivity {
"MediaPipe Hand wrist normalized coordinates (value range: [0, 1]): x=%f, y=%f",
wristLandmark.getX(), wristLandmark.getY()));
}
if (result.multiHandWorldLandmarks().isEmpty()) {
return;
}
Landmark wristWorldLandmark =
result.multiHandWorldLandmarks().get(0).getLandmarkList().get(HandLandmark.WRIST);
Log.i(
TAG,
String.format(
"MediaPipe Hand wrist world coordinates (in meters with the origin at the hand's"
+ " approximate geometric center): x=%f m, y=%f m, z=%f m",
wristWorldLandmark.getX(), wristWorldLandmark.getY(), wristWorldLandmark.getZ()));
}
}
@@ -37,7 +37,7 @@ android_binary(
srcs = glob(["*.java"]),
assets = [
"//mediapipe/graphs/hand_tracking:hand_detection_mobile_gpu.binarypb",
"//mediapipe/modules/palm_detection:palm_detection.tflite",
"//mediapipe/modules/palm_detection:palm_detection_full.tflite",
],
assets_dir = "",
manifest = "//mediapipe/examples/android/src/java/com/google/mediapipe/apps/basic:AndroidManifest.xml",
@@ -37,9 +37,11 @@ android_binary(
srcs = glob(["*.java"]),
assets = [
"//mediapipe/graphs/hand_tracking:hand_tracking_mobile_gpu.binarypb",
"//mediapipe/modules/hand_landmark:handedness.txt",
"//mediapipe/modules/hand_landmark:hand_landmark_full.tflite",
"//mediapipe/modules/palm_detection:palm_detection.tflite",
"//mediapipe/modules/hand_landmark:hand_landmark_lite.tflite",
"//mediapipe/modules/hand_landmark:handedness.txt",
"//mediapipe/modules/palm_detection:palm_detection_full.tflite",
"//mediapipe/modules/palm_detection:palm_detection_lite.tflite",
],
assets_dir = "",
manifest = "//mediapipe/examples/android/src/java/com/google/mediapipe/apps/basic:AndroidManifest.xml",
@@ -53,6 +55,7 @@ android_binary(
"outputVideoStreamName": "output_video",
"flipFramesVertically": "True",
"converterNumBuffers": "2",
# "modelComplexity": "0" # 0=lite, 1=heavy, not specified=heavy
},
multidex = "native",
deps = [
@@ -14,6 +14,9 @@
package com.google.mediapipe.apps.handtrackinggpu;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.util.Log;
import com.google.mediapipe.formats.proto.LandmarkProto.NormalizedLandmark;
@@ -30,6 +33,7 @@ public class MainActivity extends com.google.mediapipe.apps.basic.MainActivity {
private static final String TAG = "MainActivity";
private static final String INPUT_NUM_HANDS_SIDE_PACKET_NAME = "num_hands";
private static final String INPUT_MODEL_COMPLEXITY = "model_complexity";
private static final String OUTPUT_LANDMARKS_STREAM_NAME = "hand_landmarks";
// Max number of hands to detect/process.
private static final int NUM_HANDS = 2;
@@ -38,9 +42,22 @@ public class MainActivity extends com.google.mediapipe.apps.basic.MainActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ApplicationInfo applicationInfo;
try {
applicationInfo =
getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
} catch (NameNotFoundException e) {
throw new AssertionError(e);
}
AndroidPacketCreator packetCreator = processor.getPacketCreator();
Map<String, Packet> inputSidePackets = new HashMap<>();
inputSidePackets.put(INPUT_NUM_HANDS_SIDE_PACKET_NAME, packetCreator.createInt32(NUM_HANDS));
if (applicationInfo.metaData.containsKey("modelComplexity")) {
inputSidePackets.put(
INPUT_MODEL_COMPLEXITY,
packetCreator.createInt32(applicationInfo.metaData.getInt("modelComplexity")));
}
processor.setInputSidePackets(inputSidePackets);
// To show verbose logging, run:
@@ -282,8 +282,12 @@ absl::Status KinematicPathSolver::UpdatePixelsPerDegree(
absl::Status KinematicPathSolver::UpdateMinMaxLocation(const int min_location,
const int max_location) {
RET_CHECK(initialized_)
<< "UpdateMinMaxLocation called before first observation added.";
if (!initialized_) {
max_location_ = max_location;
min_location_ = min_location;
return absl::OkStatus();
}
double prior_distance = max_location_ - min_location_;
double updated_distance = max_location - min_location;
double scale_change = updated_distance / prior_distance;
@@ -435,6 +435,23 @@ TEST(KinematicPathSolverTest, PassBorderTest) {
EXPECT_FLOAT_EQ(state, 404.56668);
}
TEST(KinematicPathSolverTest, PassUpdateUpdateMinMaxLocationIfUninitialized) {
KinematicOptions options;
options.set_min_motion_to_reframe(2.0);
options.set_max_velocity(1000);
KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
MP_EXPECT_OK(solver.UpdateMinMaxLocation(0, 500));
}
TEST(KinematicPathSolverTest, PassUpdateUpdateMinMaxLocationIfInitialized) {
KinematicOptions options;
options.set_min_motion_to_reframe(2.0);
options.set_max_velocity(1000);
KinematicPathSolver solver(options, 0, 1000, 1000.0 / kWidthFieldOfView);
MP_ASSERT_OK(solver.AddObservation(500, kMicroSecInSec * 0));
MP_EXPECT_OK(solver.UpdateMinMaxLocation(0, 500));
}
} // namespace
} // namespace autoflip
} // namespace mediapipe
@@ -55,7 +55,7 @@ objc_library(
name = "HandDetectionGpuAppLibrary",
data = [
"//mediapipe/graphs/hand_tracking:hand_detection_mobile_gpu_binary_graph",
"//mediapipe/modules/palm_detection:palm_detection.tflite",
"//mediapipe/modules/palm_detection:palm_detection_full.tflite",
],
deps = [
"//mediapipe/examples/ios/common:CommonMediaPipeAppLibrary",
+1 -1
View File
@@ -64,7 +64,7 @@ objc_library(
"//mediapipe/graphs/hand_tracking:hand_tracking_mobile_gpu.binarypb",
"//mediapipe/modules/hand_landmark:hand_landmark_full.tflite",
"//mediapipe/modules/hand_landmark:handedness.txt",
"//mediapipe/modules/palm_detection:palm_detection.tflite",
"//mediapipe/modules/palm_detection:palm_detection_full.tflite",
],
deps = [
"//mediapipe/examples/ios/common:CommonMediaPipeAppLibrary",