This is only necessary if one wants to release the program while keeping the context around. + */ + public void release() { + GLES20.glDeleteProgram(program); + } + /** + * Not needed anymore, to be cleaned + * */ + private void drawDetection(Detection detection) { + + if (!detection.hasLocationData()) { + return; + } + // Draw keypoints. +// float[] points = new float[FaceKeypoint.NUM_KEY_POINTS * 2]; +// for (int i = 0; i < FaceKeypoint.NUM_KEY_POINTS; ++i) { +// points[2 * i] = detection.getLocationData().getRelativeKeypoints(i).getX(); +// points[2 * i + 1] = detection.getLocationData().getRelativeKeypoints(i).getY(); +// } +// GLES20.glUniform4fv(colorHandle, 1, KEYPOINT_COLOR, 0); +// FloatBuffer vertexBuffer = +// ByteBuffer.allocateDirect(points.length * 4) +// .order(ByteOrder.nativeOrder()) +// .asFloatBuffer() +// .put(points); +// vertexBuffer.position(0); +// GLES20.glEnableVertexAttribArray(positionHandle); +// GLES20.glVertexAttribPointer(positionHandle, 2, GLES20.GL_FLOAT, false, 0, vertexBuffer); +// GLES20.glDrawArrays(GLES20.GL_POINTS, 0, FaceKeypoint.NUM_KEY_POINTS); + if (!detection.getLocationData().hasRelativeBoundingBox()) { + return; + } + // Draw bounding box. +// float left = detection.getLocationData().getRelativeBoundingBox().getXmin(); +// float top = detection.getLocationData().getRelativeBoundingBox().getYmin(); +// float right = left + detection.getLocationData().getRelativeBoundingBox().getWidth(); +// float bottom = top + detection.getLocationData().getRelativeBoundingBox().getHeight(); +// drawLine(top, left, top, right); +// drawLine(bottom, left, bottom, right); +// drawLine(top, left, bottom, left); +// drawLine(top, right, bottom, right); + } + + private void drawLine(float y1, float x1, float y2, float x2) { + GLES20.glUniform4fv(colorHandle, 1, BBOX_COLOR, 0); + GLES20.glLineWidth(BBOX_THICKNESS); + float[] vertex = {x1, y1, x2, y2}; + FloatBuffer vertexBuffer = + ByteBuffer.allocateDirect(vertex.length * 4) + .order(ByteOrder.nativeOrder()) + .asFloatBuffer() + .put(vertex); + vertexBuffer.position(0); + GLES20.glEnableVertexAttribArray(positionHandle); + GLES20.glVertexAttribPointer(positionHandle, 2, GLES20.GL_FLOAT, false, 0, vertexBuffer); + GLES20.glDrawArrays(GLES20.GL_LINES, 0, 2); + } +} diff --git a/mediapipe/examples/android/solutions/posetracking-camera/src/main/res b/mediapipe/examples/android/solutions/posetracking-camera/src/main/res new file mode 120000 index 000000000..fc8850136 --- /dev/null +++ b/mediapipe/examples/android/solutions/posetracking-camera/src/main/res @@ -0,0 +1 @@ +../../../res \ No newline at end of file diff --git a/mediapipe/examples/android/solutions/settings.gradle b/mediapipe/examples/android/solutions/settings.gradle index 5bcd8da13..8bfb5e319 100644 --- a/mediapipe/examples/android/solutions/settings.gradle +++ b/mediapipe/examples/android/solutions/settings.gradle @@ -3,3 +3,4 @@ include ':facedetection' include ':facemesh' include ':posetracking' include ':hands' +include ':posetracking-camera' \ No newline at end of file