|
|
|
@ -17,13 +17,29 @@ package com.mindspore.posenetdemo;
|
|
|
|
|
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
|
import android.graphics.Color;
|
|
|
|
|
import android.graphics.Paint;
|
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
|
import androidx.core.util.Pair;
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.LEFT_ANKLE;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.LEFT_ELBOW;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.LEFT_HIP;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.LEFT_KNEE;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.LEFT_SHOULDER;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.LEFT_WRIST;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.RIGHT_ANKLE;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.RIGHT_ELBOW;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.RIGHT_HIP;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.RIGHT_KNEE;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.RIGHT_SHOULDER;
|
|
|
|
|
import static com.mindspore.posenetdemo.Posenet.BodyPart.RIGHT_WRIST;
|
|
|
|
|
|
|
|
|
|
public class TestActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
@ -41,16 +57,33 @@ public class TestActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
// Draw the keypoints over the image.
|
|
|
|
|
Paint paint = new Paint();
|
|
|
|
|
paint.setColor(Color.RED);
|
|
|
|
|
paint.setColor(getResources().getColor(R.color.text_blue));
|
|
|
|
|
paint.setTextSize(80.0f);
|
|
|
|
|
paint.setStrokeWidth(5.0f);
|
|
|
|
|
|
|
|
|
|
Bitmap mutableBitmap = imageBitmap.copy(Bitmap.Config.ARGB_8888, true);
|
|
|
|
|
Canvas canvas = new Canvas(mutableBitmap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Posenet.KeyPoint keypoint : person.keyPoints) {
|
|
|
|
|
canvas.drawCircle(
|
|
|
|
|
keypoint.position.x,
|
|
|
|
|
keypoint.position.y, 2.0f, paint);
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < bodyJoints.size(); i++) {
|
|
|
|
|
Pair line = (Pair) bodyJoints.get(i);
|
|
|
|
|
Posenet.BodyPart first = (Posenet.BodyPart) line.first;
|
|
|
|
|
Posenet.BodyPart second = (Posenet.BodyPart) line.second;
|
|
|
|
|
|
|
|
|
|
if (person.keyPoints.get(first.ordinal()).score > minConfidence &
|
|
|
|
|
person.keyPoints.get(second.ordinal()).score > minConfidence) {
|
|
|
|
|
canvas.drawLine(
|
|
|
|
|
person.keyPoints.get(first.ordinal()).position.x,
|
|
|
|
|
person.keyPoints.get(first.ordinal()).position.y,
|
|
|
|
|
person.keyPoints.get(second.ordinal()).position.x,
|
|
|
|
|
person.keyPoints.get(second.ordinal()).position.y, paint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sampleImageView.setAdjustViewBounds(true);
|
|
|
|
|
sampleImageView.setImageBitmap(mutableBitmap);
|
|
|
|
@ -64,4 +97,17 @@ public class TestActivity extends AppCompatActivity {
|
|
|
|
|
drawable.draw(canvas);
|
|
|
|
|
return bitmap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private final static int MODEL_WIDTH = 257;
|
|
|
|
|
private final static int MODEL_HEIGHT = 257;
|
|
|
|
|
private final double minConfidence = 0.5;
|
|
|
|
|
private final float circleRadius = 8.0f;
|
|
|
|
|
|
|
|
|
|
private final List bodyJoints = Arrays.asList(
|
|
|
|
|
new Pair(LEFT_WRIST, LEFT_ELBOW), new Pair(LEFT_ELBOW, LEFT_SHOULDER),
|
|
|
|
|
new Pair(LEFT_SHOULDER, RIGHT_SHOULDER), new Pair(RIGHT_SHOULDER, RIGHT_ELBOW),
|
|
|
|
|
new Pair(RIGHT_ELBOW, RIGHT_WRIST), new Pair(LEFT_SHOULDER, LEFT_HIP),
|
|
|
|
|
new Pair(LEFT_HIP, RIGHT_HIP), new Pair(RIGHT_HIP, RIGHT_SHOULDER),
|
|
|
|
|
new Pair(LEFT_HIP, LEFT_KNEE), new Pair(LEFT_KNEE, LEFT_ANKLE),
|
|
|
|
|
new Pair(RIGHT_HIP, RIGHT_KNEE), new Pair(RIGHT_KNEE, RIGHT_ANKLE));
|
|
|
|
|
}
|