diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectPhotoActivity.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectPhotoActivity.java
index d64d883a148..a8e4fec5c88 100644
--- a/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectPhotoActivity.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectPhotoActivity.java
@@ -87,10 +87,8 @@ public class ObjectPhotoActivity extends AppCompatActivity {
super.onActivityResult(requestCode, resultCode, data);
if (RC_CHOOSE_PHOTO == requestCode && null != data && null != data.getData()) {
- if (data != null) {
this.imageUri = data.getData();
showOriginImage();
- }
} else {
finish();
}
@@ -204,7 +202,7 @@ public class ObjectPhotoActivity extends AppCompatActivity {
Integer maxHeight = this.getMaxHeightOfImage();
targetWidth = this.isLandScape ? maxHeight : maxWidth;
targetHeight = this.isLandScape ? maxWidth : maxHeight;
- Log.i(ObjectPhotoActivity.TAG, "height:" + targetHeight + ",width:" + targetWidth);
+ Log.i(TAG, "height:" + targetHeight + ",width:" + targetWidth);
return new Pair<>(targetWidth, targetHeight);
}
}
\ No newline at end of file
diff --git a/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectRectView.java b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectRectView.java
index b5182295abc..198d3acf022 100644
--- a/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectRectView.java
+++ b/model_zoo/official/lite/Himindspore/imageObject/src/main/java/com/mindspore/imageobject/objectdetection/ui/ObjectRectView.java
@@ -88,12 +88,12 @@ public class ObjectRectView extends View {
mRecognitions.clear();
mRecognitions.addAll(recognitions);
- invalidate();
+ postInvalidate();
}
public void clearCanvas() {
mRecognitions.clear();
- invalidate();
+ postInvalidate();
}
@Override
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/Posenet.java b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/Posenet.java
index e43fe3e4b25..1df6f8d0e69 100644
--- a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/Posenet.java
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/Posenet.java
@@ -60,8 +60,8 @@ public class Posenet {
}
public class Position {
- int x;
- int y;
+ float x;
+ float y;
}
public class KeyPoint {
@@ -151,7 +151,6 @@ public class Posenet {
int[] intValues = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
-
int pixel = 0;
for (int y = 0; y < bitmap.getHeight(); y++) {
for (int x = 0; x < bitmap.getWidth(); x++) {
@@ -281,16 +280,16 @@ public class Posenet {
}
// Calculating the x and y coordinates of the keypoints with offset adjustment.
- int[] xCoords = new int[numKeypoints];
- int[] yCoords = new int[numKeypoints];
+ float[] xCoords = new float[numKeypoints];
+ float[] yCoords = new float[numKeypoints];
float[] confidenceScores = new float[numKeypoints];
for (int i = 0; i < keypointPositions.length; i++) {
Pair position = keypointPositions[i];
int positionY = (int) position.first;
int positionX = (int) position.second;
- yCoords[i] = (int) ((float) positionY / (float) (height - 1) * bitmap.getHeight() + offsets[0][positionY][positionX][i]);
- xCoords[i] = (int) ((float) positionX / (float) (width - 1) * bitmap.getWidth() + offsets[0][positionY][positionX][i + numKeypoints]);
+ yCoords[i] = ((float) positionY / (float) (height - 1) * bitmap.getHeight() + offsets[0][positionY][positionX][i]);
+ xCoords[i] = ((float) positionX / (float) (width - 1) * bitmap.getWidth() + offsets[0][positionY][positionX][i + numKeypoints]);
confidenceScores[i] = sigmoid(heatmaps[0][positionY][positionX][i]);
}
diff --git a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java
index 799e67928c2..cd3f867aa77 100644
--- a/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java
+++ b/model_zoo/official/lite/Himindspore/posenet/src/main/java/com/mindspore/posenet/PosenetMainActivity.java
@@ -52,7 +52,14 @@ import static com.mindspore.posenet.Posenet.BodyPart.RIGHT_WRIST;
@Route(path = "/posenet/PosenetMainActivity")
public class PosenetMainActivity extends AppCompatActivity implements CameraDataDealListener {
- private final List bodyJoints;
+ 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));
+ ;
/**
@@ -74,16 +81,6 @@ public class PosenetMainActivity extends AppCompatActivity implements CameraData
private int lensFacing = CameraCharacteristics.LENS_FACING_BACK;
private PoseNetFragment poseNetFragment;
- public PosenetMainActivity() {
- 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));
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -211,8 +208,8 @@ public class PosenetMainActivity extends AppCompatActivity implements CameraData
new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
new Rect(left, top, right, bottom), paint);
- float widthRatio = screenWidth / MODEL_WIDTH;
- float heightRatio = screenHeight / MODEL_HEIGHT;
+ float widthRatio = (float) screenWidth / MODEL_WIDTH;
+ float heightRatio = (float) screenHeight / MODEL_HEIGHT;
for (Posenet.KeyPoint keyPoint : person.keyPoints) {
if (keyPoint.score > minConfidence) {
diff --git a/model_zoo/official/lite/posenet/app/src/main/AndroidManifest.xml b/model_zoo/official/lite/posenet/app/src/main/AndroidManifest.xml
index 3f7c4da67e2..a5fec38299d 100644
--- a/model_zoo/official/lite/posenet/app/src/main/AndroidManifest.xml
+++ b/model_zoo/official/lite/posenet/app/src/main/AndroidManifest.xml
@@ -14,19 +14,23 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
-
+
+
+
+
+
-
-
-
\ No newline at end of file
diff --git a/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/MainActivity.java b/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/MainActivity.java
index 9ea88ee371a..d48ad7bdc67 100644
--- a/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/MainActivity.java
+++ b/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/MainActivity.java
@@ -204,8 +204,8 @@ public class MainActivity extends AppCompatActivity implements CameraDataDealLis
new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
new Rect(left, top, right, bottom), paint);
- float widthRatio = screenWidth / MODEL_WIDTH;
- float heightRatio = screenHeight / MODEL_HEIGHT;
+ float widthRatio = (float) screenWidth / MODEL_WIDTH;
+ float heightRatio = (float) screenHeight / MODEL_HEIGHT;
for (Posenet.KeyPoint keyPoint : person.keyPoints) {
if (keyPoint.score > minConfidence) {
diff --git a/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java b/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java
index a5a3d3f86b9..17ac8cd79b6 100644
--- a/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java
+++ b/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/Posenet.java
@@ -60,8 +60,8 @@ public class Posenet {
}
public class Position {
- int x;
- int y;
+ float x;
+ float y;
}
public class KeyPoint {
@@ -151,7 +151,6 @@ public class Posenet {
int[] intValues = new int[bitmap.getWidth() * bitmap.getHeight()];
bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
-
int pixel = 0;
for (int y = 0; y < bitmap.getHeight(); y++) {
for (int x = 0; x < bitmap.getWidth(); x++) {
@@ -281,16 +280,16 @@ public class Posenet {
}
// Calculating the x and y coordinates of the keypoints with offset adjustment.
- int[] xCoords = new int[numKeypoints];
- int[] yCoords = new int[numKeypoints];
+ float[] xCoords = new float[numKeypoints];
+ float[] yCoords = new float[numKeypoints];
float[] confidenceScores = new float[numKeypoints];
for (int i = 0; i < keypointPositions.length; i++) {
Pair position = keypointPositions[i];
int positionY = (int) position.first;
int positionX = (int) position.second;
- yCoords[i] = (int) ((float) positionY / (float) (height - 1) * bitmap.getHeight() + offsets[0][positionY][positionX][i]);
- xCoords[i] = (int) ((float) positionX / (float) (width - 1) * bitmap.getWidth() + offsets[0][positionY][positionX][i + numKeypoints]);
+ yCoords[i] = ((float) positionY / (float) (height - 1) * bitmap.getHeight() + offsets[0][positionY][positionX][i]);
+ xCoords[i] = ((float) positionX / (float) (width - 1) * bitmap.getWidth() + offsets[0][positionY][positionX][i + numKeypoints]);
confidenceScores[i] = sigmoid(heatmaps[0][positionY][positionX][i]);
}
diff --git a/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/TestActivity.java b/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/TestActivity.java
index ee50032a98f..ed5906ac37d 100644
--- a/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/TestActivity.java
+++ b/model_zoo/official/lite/posenet/app/src/main/java/com/mindspore/posenetdemo/TestActivity.java
@@ -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));
}
\ No newline at end of file