---
title: "How To: Read a Data Matrix Code from a Camera Image"
description: "From a camera image to the decoded text - point LumiScan DMC Reader at LumiScan Cam Driver, run it, read the result and check it in LumiScan Cockpit."
product: "LumiScan DMC Reader"
component: "lumiscan-dmc-reader"
version: "1.1.0"
display_version: "1.1.0.6"
latest_version: true
language: "en"
url: "https://docs.hdvisionsystems.com/en/lumiscan-dmc-reader/1.1.0/how-tos/read-a-code-from-a-camera-image.html"
---

# How To: Read a Data Matrix Code from a Camera Image – LumiScan DMC Reader

This guide reads the Data Matrix codes in an image of LumiScan Cam Driver with LumiScan DMC Reader and shows where to find the decoded text and position.

When you have finished, one write to the reader’s `execute` method reads every Data Matrix code in the current camera image.

The same steps apply to LumiScan QR Code Reader, LumiScan Aztec Code Reader and LumiScan Barcode Reader: replace `lumiscan-dmc-reader` in the addresses with the name of that application.

## Before you start {#prerequisites}

- LumiScan DMC Reader and LumiScan Cam Driver run on the same device - the same ctrlX CORE or ctrlX IPC, or the same PC. Reading an image from another device is not supported.
- The camera module of LumiScan Cam Driver is connected and can capture images.
- Optional: LumiScan Cockpit, to see the codes on the image.

> [!TIP]
> Without a camera, use a simulated camera of LumiScan Cam Driver with example images, for example the image below. See [LumiScan Cam Driver: How does simulation mode work?](https://docs.hdvisionsystems.com/en/lumiscan-cam-driver/2.2.1/faq.html#faq-simulation-mode).

![Data Matrix code printed on paper in front of a perforated metal plate](https://docs.hdvisionsystems.com/en/lumiscan-dmc-reader/1.1.0/_images/howto-dmc-example-code.png)

*Figure 1. Example image with a Data Matrix code*

## How it fits together {#overview}

LumiScan DMC Reader needs no template and no configuration. It reads the image node whose address you give it, searches the whole image for ECC 200 Data Matrix codes, and writes every code it finds to `output/results`.

All addresses below are relative to `hdvisionsystems/lumiscan-dmc-reader`. On ctrlX OS, values can be set in the ctrlX web interface under **Settings > Data Layer**, or by another application, for example a PLC program.

## Step 1 - Point the reader at the camera image {#step-1-image-address}

Write the address of the camera’s image node to `input/image-address`. For the camera module `camera1`:

```
hdvisionsystems/lumiscan-cam-driver/camera1/output/image
```

Use the address of the image node itself, not of its `data` child. The address is kept, so you set it again only when the image source changes.

## Step 2 - Capture an image {#step-2-capture}

Capture an image with LumiScan Cam Driver, for example with a write to `hdvisionsystems/lumiscan-cam-driver/camera1/control/capture/execute`.

For a reliable read, the code should be sharp, have good contrast, and its modules - the black and white squares - should be several pixels wide in the image.

## Step 3 - Read the codes {#step-3-execute}

Write an empty value to `execute`.

The call returns when the search has finished.

## Step 4 - Check the result {#step-4-result}

Read `output/results`. It holds one entry per code found:

- `text` - the decoded content,
- `center` - the centre of the code in the image, in pixels,
- `score` - how confident the read is,
- `polygons` - the corner points of the code, if given.

An empty list means that the image was read and contained no Data Matrix code. The fields are described in [The Result](https://docs.hdvisionsystems.com/en/lumiscan-dmc-reader/1.1.0/lumiscan-dmc-reader/the-result.html).

> [!IMPORTANT]
> A failed run - for example when the image address is wrong or the image cannot be read - leaves `output/results` unchanged, with the codes of the previous run. The reason is written to the application log. If your program has to know that the result is fresh, compare the result before and after the run, or check the log.

To see the codes on the image, open LumiScan Cockpit and select the view `datamatrix-code` of `lumiscan-dmc-reader`. Each code is framed and labelled with its text and score.

## Result {#result}

- LumiScan DMC Reader reads the current image of the camera.
- One write to `execute` reads every Data Matrix code in the image.
- The decoded text and the position of each code are on `output/results`.

In production, a cycle is: capture with LumiScan Cam Driver, write to `execute` of the reader, read `output/results`. To have every frame of a camera stream read without a call per image, see [Reading Codes on an Image Stream (Experimental)](https://docs.hdvisionsystems.com/en/lumiscan-dmc-reader/1.1.0/lumiscan-dmc-reader/reading-codes-on-an-image-stream.html). Problems are described in [Troubleshooting](https://docs.hdvisionsystems.com/en/lumiscan-dmc-reader/1.1.0/troubleshooting.html).
