Dev.to WebDev 🛠 Dev 👁 2 📖 7 min read

Building a 478-Point Face Analyzer With Zero Photo Uploads

A browser architecture for on-device geometry, with a request policy you can test and a clear boundary around derived results. A browser can extract face landmarks from a photo without sending that photo to a server. Th

A browser architecture for on-device geometry, with a request policy you can test and a clear boundary around derived results.

A browser can extract face landmarks from a photo without sending that photo to a server. That fact is easy to demonstrate in a bare demo. It is harder to preserve in a product where someone can clear a scan, export a result, open a support form, or report an error. Each of those interactions can pick up more data than it needs. The architecture starts with a promise narrow enough to test: the analyzer processes the selected image on the device and sends no photo pixels during the scan.

A 478-point MediaPipe setup gives the browser coordinates for a dense face mesh, including points around the irises. It can support styling comparisons such as relative widths and heights. Coordinate density does little for privacy by itself. The rest of this piece describes a reference design with local-only scan results, and a separate option for products that want users to share a small result summary.

Specify what crosses the boundary before choosing a transport

Write down what the product can create during a scan. Include the selected file, decoded pixels, landmarks, preview, ratios, and any label built from those ratios. Include the data that records whether the scan succeeded. Decide where each item can go and how long the application needs it. That list makes it easier to see what a worker message, performance event, or error report should contain.

In a strict local-only scan, the photo and the coordinates stay in memory while the result is open. The same policy can cover the ratios. Model and runtime downloads may still produce requests, and their host still sees normal connection metadata. If you offer a save button, a local download can keep the decision with the reader. Explain that a downloaded file remains on the device after the page is closed. Give it a filename that reveals as little about the person as practical.

A second product may offer a saved report that can be reached from another device. For that feature, decide what the service can accomplish with a small summary and what it would need the original photo for. If a handful of ratios is sufficient, build a new object from that explicit list at the point a user enables the feature. Precision affects how much detail you retain. Labels and rounded values are still information about someone's face, particularly if you associate them with an account. Put what gets shared and how long it stays next to the action that sends it. A disclosure about photo upload alone leaves that question open.

The reference design gives each kind of data a place to go.

  • Photo and preview. Hold them in the page or processing worker. Drop application references and revoke any preview object URL when the user clears the scan.

  • Landmarks and ratios. Keep them in memory. Remove the result on clear, including the copy used to draw it.

  • Model and runtime. Download these as versioned static assets. The cache can remain for another scan.

  • Local export. Create it when the user asks. The person who saved the file controls that copy.

Treat the mesh as a versioned input

Select a MediaPipe Face Landmarker build and a matching model. Confirm that your chosen combination returns 478 landmarks on a supported single-face input. Keep the point indices and their meanings beside the model version in your test fixtures. A valid length checks the shape of the result. Fixed example inputs are useful for checking whether the points you use still identify the same parts of the face after an upgrade. The browser should have a clear inability-to-measure state when the contract fails.

Pass upright pixels to the model and keep the inference image dimensions with each result. When you calculate a horizontal span, multiply the difference between normalized x positions by the inference width. For a vertical span, use the y difference and the height. Suppose a horizontal normalized difference is 0.20 and the image is 1,000 pixels wide. A vertical difference of 0.15 on a 1,500-pixel-tall image yields spans of 200 and 225 pixels. The height-to-width ratio is 1.125. Dividing the two normalized differences directly gives 0.75, an error caused by comparing fractions of different axes.

Report only the precision the input can support. A face turned slightly away from the camera can give stable-looking coordinates for a different projected shape. Try a centered example, then a turned example of the same subject to see how your results respond. If the photo is too angled for a frontal measurement, say what view would work. Relative depth in a mesh does not supply a physical scale for a haircut, and a point near the top of the forehead may be a poor proxy for a visible hairline. Let the result label refer to the span you can actually measure.

Give the worker a short job and the page a clear result

Use a worker for synchronous inference where your runtime and device support it. Let the page own the selected input and the current result. The worker can own the pixels it receives and hand back the data needed to render the ratios. If the display includes a mesh, the page may need the point array, too. Otherwise a small set of derived values can serve the interface, and the points can stay within the lifetime of the worker job. A replacement photo should clear the old result and invalidate any older job response.

Watch what happens on first use. The initial model download and startup can take longer than several warm scans combined, particularly on a cold mobile connection. Show a distinct preparing state and a retry action when a required asset fails to load. If you support a main-thread fallback on a device, measure whether inference makes the controls unresponsive. An error with instructions to retry can be preferable to waiting indefinitely on that path.

Keep diagnostics useful with a short set of outcomes such as model unavailable, photo unreadable, and face outside the measured range. An error handler needs enough context to tell those cases apart. Leave out previews, geometry, user filenames, and model input from automatic diagnostics. A support operator can often help from the reported outcome and device details. Any request for a sample should happen through a separate interaction with clear permission.

Verify the policy on a full scan journey

Use a synthetic or licensed test photo and capture requests from before the scan through after the result is cleared. Include the worker and any background page activity in the capture. Compare each request with your permitted destinations, methods, and payload fields. Check the address and request headers as well as the body. Data can leave in a query parameter even when there are no form submissions. If you block connections in the test, inspect attempted requests so a rejected call cannot masquerade as a passed privacy check.

Exercise at least these cases before release:

  • Start cold and account for the model and runtime requests. Repeat warm and confirm the scan works with its static assets already available.
  • Replace a photo while inference is still running. Verify the old result never overrides the new one and that clearing leaves no scan data in application storage.
  • Force a decode failure and capture the diagnostics. Check that the outgoing fields contain the permitted outcome and nothing taken from the photo.
  • If a user can share a summary, test the declined and accepted paths. In the accepted path, compare the actual payload against the allowed fields and inspect the result after the share is revoked or expires.
  • Spot-check the same journey on a mobile device and after a model update. Both changes can select a different inference or error path.

Give the policy a negative control. In a test build, deliberately emit an extra innocuous field on a synthetic scan event and verify that the request test fails. Then remove it and run the same fixture again. A test that only counts successful responses could pass both runs if the receiver drops unfamiliar fields. Record the outbound field names and assertions in the test output, leaving the synthetic image and full request bodies out of routine logs. An engineer can then read the failure and see that the boundary changed without opening a file full of scan data.

The HaloRater browser experience offers a public example of on-device face landmark inference. Its golden ratio mask comparison and Umax alternative overview give readers two ways to evaluate what face tools measure and what they ask users to provide. Treat photo processing and result handling as two separate checks when comparing products. If you're building your own, start with one test scan and write down every request you expect to see. The remaining requests are where you should read the payload before making a privacy claim.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.