A while ago I created a tool for the HoloLens device to calculate the interpupilary distance (distance between your eyes pupils) to properly configure the device. You can read all the details about that on the GitHub page.
In summary, I used the Microsoft Cognitive Services Face Detection API to detect facial landmarks and calculate the distance based on them.
One of the most interesting parts of the app was to load an image and annotate it with the locations of the faces detected in the image, just like you see in the online demos.
The solution I chose was to use a custom Canvas overlaid on top of the image. Knowing the actual dimensions of the image and the actual size when rendered, allows to calculate the position and size of the face rectangles as returned by the Face API. Once those ratios are calculated, we draw each rectangle (and any other landmarks we need) making sure we refresh every time the size changes since that would cause the ratios between the image size and render size to change.
Full code below:
public class AnnotationCanvas : Canvas
Here’s a screenshot of it in action (with an extra adornment for the HoloLens IPD app)
Some obvious improvements would be ability to configure color, strokes and potentially support more generic objects. I am also considering embedding the image directly in the canvas and make it a bit more encapsulated but for now it works fine as it is.