How to convert Normalized Device Coordinates to pixel coordinates for canvas on Android?

Viewed 47

I'm using Mediapipe framework to detect hands and i want to display own image on finger's landmark. The library provides landmarks in form of "Normalized Device Coordinate"(0...1). So i need to convert these coordinates to device(phone) coordinates in form of pixels.

Tried

  int  width= device_width;
  int  height= device_height;

        float  x = (float) ( handLandmarkList.get(HandLandmark.RING_FINGER_PIP).getX() * width );
        float  y = (float) (  handLandmarkList.get(HandLandmark.RING_FINGER_PIP).getY()*height );

x and y coordinates are not showing correct on device.

1 Answers

You need to multiply NDCs by your render target dimensions.

Related