Render 2d (Visualization)

The 2d visualization module for the Node SDK Render 2d Node Module

This Node Module provides convenient 2d rendering functions for predictions returned by to the's inference API from applications written in the TypeScript or JavaScript language.

The module requires the EyePop Node SDK



npm install --save


<script src=""></script>
<script src=""></script>

Usage example


This EyePop Node Module provides 2d rendering for predictions using canvas.CanvasRenderingContext2D.

import { EyePop } from '';
import { Render2d } from '';

import {createCanvas, loadImage} from "canvas";
import {open} from 'openurl';
import { mkdtempSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';

const example_image_path = 'examples/example.jpg';
(async() => {
    const image = await loadImage(example_image_path)
    const canvas = createCanvas(image.width, image.height)
    const context = canvas.getContext("2d")
    const renderer = Render2d.renderer(context)
    context.drawImage(image, 0, 0)

    const endpoint = await EyePop.endpoint().connect()
    try {
        let results = await endpoint.process({path: example_image_path})
        for await (let result of results) {
    } finally {
        await endpoint.disconnect()
    const tmp_dir = mkdtempSync(join(tmpdir(), 'ep-demo-'))
    const temp_file = join(tmp_dir, 'out.png')
    console.log(`creating temp file: ${temp_file}`)

    const buffer = canvas.toBuffer('image/png')
    writeFileSync(temp_file, buffer)



<!DOCTYPE html>
<html lang="en">
    <script src=""></script>
    <script src=""></script>
<!-- ... -->
    <input type="file" id="my-file-chooser">
<!-- ... -->
    <canvas id="my-canvas"></canvas>
<!-- ... -->
    async uploadFile(event) {
        const fileChooser = document.getElementById('my-file-chooser');
        const context = document.getElementById('my-canvas').getContext("2d");
        const renderer = Render2d.renderer(context);
        const endpoint = await EyePop.endpoint({ auth: { oAuth2: true }, popId: '< Pop Id>' }).connect();
        endpoint.process({file: fileChooser.files[0]}).then(async (results) => {
            for await (let result of results) {
        await endpoint.disconnect();

Rendering Rules

By default, the 2d renderer renders boxes and class-labels for every top level object in the prediction. Change this rendering behaviour by passing in rendering rule(s), e.g.:

// ...
// ...

Each rule has a render object and a target attribute. All prebuild render classes accept a JSONPath expression as target parameter to select which elements should be rendered from predictions. See JSONPath expression

Most prebuild render classes provide a reasonable default target.

Rendering Bounding Boxes and Class Labels

Render2d.renderBox(target = '$.objects.*')
// or

Render Human Body Poses (2d or 3d)

Render2d.renderPose(target = '$..objects[?(@.category=="person")]')
// or

Render Human Hand Details

Render2d.renderHand(target = '$..objects[?(@.classLabel=="hand circumference")]')
// or 

Render Human Faces

Render2d.renderFace(target = '$..objects[?(@.classLabel=="face")]') 
// or 

Render Segmentation Masks

Render2d.renderMask(target = '$..objects[?(@.mask)]') 
// or 

Render Segmentation Contours

Render2d.renderContour(target = '$..objects[?(@.contours)]') 
// or 

Blur an Object (TODO does black-put instead of blur)

Render2d.renderBlur(target = '$..objects[?(@.classLabel=="face")]')

Render a Trail of a traced object over time

Render2d.renderTrail(1.0, target = '$..objects[?(@.traceId)]')
// or

By default, this traces the mid-point of the object's bounding box. Instead, one can also draw trails of sub-objects or key points of the traced object. Use the optional parameter traceDetails for this purpose. E.g. trail the nose of every traced person:

Render2d.renderTrail(1.0, '$..keyPoints[?(@.category=="3d-body-points")].points[?(@.classLabel.includes("nose"))]')

Custom render implementation

To implement custom rendering rules, implement the Render interface and create your own RenderRule objects:

export interface Render {
    start(context: CanvasRenderingContext2D, style: Style): void
    draw(element: any, xOffset: number, yOffset: number, xScale: number, yScale: number, streamTime: StreamTime): void

export interface RenderRule {
    readonly render: Render
    readonly target : string

Last updated