Defined under the namespace Scandit.Datacapture.Barcode

Coordinate Conversion Guide

Barcode location properties such as Barcode.location and TrackedBarcode.location return coordinates in image-space (also called frame coordinates). These correspond to actual pixel positions in the camera frame and cannot be used directly for on-screen rendering.

To display barcode locations in the UI, they must first be converted to view-space coordinates using the methods provided by DataCaptureView.

Coordinate Systems

Image-space (frame coordinates)

Pixel coordinates within the camera frame. The resolution matches the camera’s capture resolution (e.g. 1920x1080). This is the coordinate system used by the barcode detection engine and returned by all Location properties.

View-space (view coordinates)

Coordinates within the DataCaptureView. These account for preview scaling, device rotation and display density, and can be used directly for positioning UI elements on screen.

Conversion Methods

DataCaptureView provides two methods for converting from image-space to view-space:

Both methods are thread-safe and can be called from any thread.

Note

On Cordova, these methods return a Promise (or Future in Dart) due to the asynchronous nature of the bridge layer.

Corner Orientation

The corners of the Quadrilateral returned by Location always correspond to the physical corners of the barcode itself, regardless of how the barcode is oriented in the camera image. Quadrilateral.topLeft is always the top-left corner of the barcode as it would appear when read normally, and so on for the other corners.

Example

A common use case is determining the on-screen size of a barcode to decide whether to show an overlay. The following example converts a barcode’s location to view coordinates and calculates its width:

function shouldShowOverlay(barcode, dataCaptureView) {
    const viewLocation =
        dataCaptureView.viewQuadrilateralForFrameQuadrilateral(barcode.location);
    const width = Math.max(
        viewLocation.topRight.x - viewLocation.topLeft.x,
        viewLocation.bottomRight.x - viewLocation.bottomLeft.x
    );
    return width > window.innerWidth * 0.1;
}