▩ Chilkat.Formats · New in v11.8.0

Reading QR Codes
read · detect

Find and decode every QR code in a PNG, a JPEG or a raw pixel buffer — rotated, tilted, mirrored, inverted or damaged — and get the text, the bytes, the position and the encoding details back as JSON.

read

Decode every symbol in an image

read finds and decodes every QR Code (Model 2, versions 1–40) in one image. The request names the image in source; everything else is optional. The response has one entry of results[] for each symbol. An image without a symbol is not an error: the method returns true and results[] is empty.

Read the QR codes in an image — C#
// Read every QR code in an image file
Chilkat.JsonObject jsonIn = new Chilkat.JsonObject();
jsonIn.UpdateString("source.path", "photo.jpg");

Chilkat.JsonObject jsonOut = new Chilkat.JsonObject();
Chilkat.Formats fmt = new Chilkat.Formats();
bool success = fmt.QrCode("read", jsonIn, jsonOut);
if (!success) {
    Console.WriteLine(jsonOut.StringOf("errors[0].code") + ": " + jsonOut.StringOf("errors[0].message"));
    Console.WriteLine(fmt.LastErrorText);
    return;
}

// One entry of results[] per symbol.  Finding none is not an error: the array is empty.
int n = jsonOut.SizeOfArray("results");
for (int i = 0; i < n; i++) {
    jsonOut.I = i;
    Console.WriteLine(jsonOut.StringOf("results[i].text"));
    Console.WriteLine("  version " + jsonOut.IntOf("results[i].metadata.version")
        + ", level " + jsonOut.StringOf("results[i].metadata.errorCorrection")
        + ", turned " + jsonOut.IntOf("results[i].geometry.rotation") + " degrees"
        + ", first corner at " + jsonOut.StringOf("results[i].geometry.polygon[0].x")
        + ", " + jsonOut.StringOf("results[i].geometry.polygon[0].y"));
}
Read the QR codes in an image — C++
// Read every QR code in an image file
CkJsonObject jsonIn;
jsonIn.UpdateString("source.path", "photo.jpg");

CkJsonObject jsonOut;
CkFormats fmt;
bool success = fmt.QrCode("read", jsonIn, jsonOut);
if (!success) {
    std::cout << jsonOut.stringOf("errors[0].code") << ": " << jsonOut.stringOf("errors[0].message") << "\r\n";
    std::cout << fmt.lastErrorText() << "\r\n";
    return;
}

// One entry of results[] per symbol.  Finding none is not an error: the array is empty.
int n = jsonOut.SizeOfArray("results");
for (int i = 0; i < n; i++) {
    jsonOut.put_I(i);
    std::cout << jsonOut.stringOf("results[i].text") << "\r\n";
    std::cout << "  version " << jsonOut.IntOf("results[i].metadata.version");
    std::cout << ", level " << jsonOut.stringOf("results[i].metadata.errorCorrection");
    std::cout << ", turned " << jsonOut.IntOf("results[i].geometry.rotation") << " degrees";
    std::cout << ", first corner at " << jsonOut.stringOf("results[i].geometry.polygon[0].x");
    std::cout << ", " << jsonOut.stringOf("results[i].geometry.polygon[0].y") << "\r\n";
}
Read the QR codes in an image — Python
import chilkat2

# Read every QR code in an image file
jsonIn = chilkat2.JsonObject()
jsonIn.UpdateString("source.path", "photo.jpg")

jsonOut = chilkat2.JsonObject()
fmt = chilkat2.Formats()
success = fmt.QrCode("read", jsonIn, jsonOut)
if not success:
    print(jsonOut.StringOf("errors[0].code") + ": " + jsonOut.StringOf("errors[0].message"))
    print(fmt.LastErrorText)
    exit()

# One entry of results[] per symbol.  Finding none is not an error: the array is empty.
n = jsonOut.SizeOfArray("results")
for i in range(n):
    jsonOut.I = i
    print(jsonOut.StringOf("results[i].text"))
    print("  version", jsonOut.IntOf("results[i].metadata.version"),
          "level", jsonOut.StringOf("results[i].metadata.errorCorrection"),
          "turned", jsonOut.IntOf("results[i].geometry.rotation"), "degrees,",
          "first corner at", jsonOut.StringOf("results[i].geometry.polygon[0].x"),
          jsonOut.StringOf("results[i].geometry.polygon[0].y"))
Not using C#, C++ or Python? The example is shown in three languages only to give a feel for the code. The Chilkat classes, including Formats, have the same methods and the same JSON requests in every supported language: C, C++, C#, VB.NET, Java, Objective-C, Swift, Python, PHP, Perl, Ruby, Node.js, Electron, React Native, Dart / Flutter, Go, Rust, Zig, Delphi, C++Builder, Free Pascal / Lazarus, Classic ASP, VB6, VBScript, FoxPro, DataFlex, PowerBuilder, Xojo, Xbase++, PureBasic, AutoIt, B4A / B4J, LabVIEW, SQL Server and Tcl. See Chilkat Downloads for Every Language.

The request, as JSON

A read request has no symbology and no payload. Its groups are source, reader, results, parse and limits; unknown members are rejected with unknownOption.

request
{ "source": { "path": "photo.jpg" } }

The response

This is the complete response for the image above. The symbol was located through the perspective, and its content, version, error-correction level and mask were recovered.

response
{
  "image": { "width": 640, "height": 480, "format": "jpeg" },
  "results": [
    {
      "symbology": "qr", "frame": 0, "id": 0, "byteCount": 52,
      "text": "https://www.chilkatsoft.com/refdoc/csFormatsRef.html", "textStatus": "valid",
      "charset": "utf-8", "charsetSource": "utf8Detected",
      "bytesBase64": "aHR0cHM6Ly93d3cuY2hpbGthdHNvZnQuY29tL3JlZmRvYy9jc0Zvcm1hdHNSZWYuaHRtbA==",
      "geometry": {
        "bounds": { "x": 193.63, "y": 97.03, "width": 263.94, "height": 226.8 },
        "polygon": [
          { "x": 243.25, "y": 97.03 }, { "x": 457.57, "y": 142.47 },
          { "x": 418, "y": 323.83 }, { "x": 193.63, "y": 269.49 }
        ],
        "rotation": 12, "moduleSize": 5.53, "mirrored": false, "inverted": false
      },
      "metadata": { "version": 5, "errorCorrection": "Q", "mask": 6 }
    }
  ],
  "errors": [], "warnings": []
}
GroupPurposeDocumented
sourceThe image: a PNG or JPEG file, the bytes of one, or raw pixels.Sources
readerHow hard to look, where, and how many symbols to return.Reader options
resultsWhat each result carries: bytes, geometry, metadata, segments, diagnostics, crops.Results
parseInterpret the content of each symbol as a URL, Wi-Fi configuration, email, …Structured Payloads
limitstimeoutMs and maxPixels.Limits and errors

source

Where the image comes from

Exactly one of source.path, source.base64 and source.pixels says where the image is. The same source group is used by read, detect and extract.

MemberValuesDefaultNotes
source.pathstring—The path of a PNG or JPEG file. A file that is missing, empty or cannot be read fails with inputFailed at /source/path.
source.base64base64 string—The bytes of a PNG or JPEG file (up to 256 MiB decoded).
source.pixelsobject—Raw pixels: base64, width, height (1–32,768) and format are required; stride (bytes per row) is optional. Rows run top to bottom, and the data must be exactly height × stride bytes.
source.pixels.format"gray8" · "rgb24" · "rgba32" · "bgra32"requiredOne, three or four bytes per pixel. Alpha is straight (not premultiplied).
source.pixels.strideintegerwidth × bytes per pixelGive it when rows are padded. Absent or 0 means the rows are tight.
source.format"auto" · "png" · "jpeg""auto"For a file or base64 source. auto goes by the first bytes of the data. Naming a format asserts it: data that is something else is invalidImage. Not applicable to raw pixels.
source.alphaBackground"#RRGGBB""#FFFFFF"The color placed under transparent pixels before the image is searched.
source.applyExifOrientationbooltrueTurn a JPEG as its Exif Orientation tag says before searching it. See Exif orientation.
source.frames——Reserved for multi-frame images (unsupportedFeature).
the bytes of an image file
{ "source": { "base64": "iVBORw0KGgoAAAANSUhEUgAAAJQAAACU..." } }
raw pixels
{ "source": { "pixels": { "base64": "/////////////////////w...",
                          "width": 148, "height": 148, "format": "gray8" } } }
Read an image held in memory — C#
// The image file is already in memory (downloaded, read from a database, ...)
Chilkat.BinData image = new Chilkat.BinData();
image.LoadFile("photo.jpg");

Chilkat.JsonObject jsonIn = new Chilkat.JsonObject();
jsonIn.UpdateString("source.base64", image.GetEncoded("base64"));

// Or: raw pixels.  Here frame holds an 8-bit gray camera image of 640 x 480 (307,200 bytes).
Chilkat.JsonObject jsonIn2 = new Chilkat.JsonObject();
jsonIn2.UpdateString("source.pixels.base64", frame.GetEncoded("base64"));
jsonIn2.UpdateInt("source.pixels.width", 640);
jsonIn2.UpdateInt("source.pixels.height", 480);
jsonIn2.UpdateString("source.pixels.format", "gray8");

Chilkat.JsonObject jsonOut = new Chilkat.JsonObject();
bool success = fmt.QrCode("read", jsonIn, jsonOut);
Read an image held in memory — C++
// The image file is already in memory (downloaded, read from a database, ...)
CkBinData image;
image.LoadFile("photo.jpg");

CkJsonObject jsonIn;
jsonIn.UpdateString("source.base64", image.getEncoded("base64"));

// Or: raw pixels.  Here frame holds an 8-bit gray camera image of 640 x 480 (307,200 bytes).
CkJsonObject jsonIn2;
jsonIn2.UpdateString("source.pixels.base64", frame.getEncoded("base64"));
jsonIn2.UpdateInt("source.pixels.width", 640);
jsonIn2.UpdateInt("source.pixels.height", 480);
jsonIn2.UpdateString("source.pixels.format", "gray8");

CkJsonObject jsonOut;
bool success = fmt.QrCode("read", jsonIn, jsonOut);
Read an image held in memory — Python
# The image file is already in memory (downloaded, read from a database, ...)
image = chilkat2.BinData()
image.LoadFile("photo.jpg")

jsonIn = chilkat2.JsonObject()
jsonIn.UpdateString("source.base64", image.GetEncoded("base64"))

# Or: raw pixels.  Here frame holds an 8-bit gray camera image of 640 x 480 (307,200 bytes).
jsonIn2 = chilkat2.JsonObject()
jsonIn2.UpdateString("source.pixels.base64", frame.GetEncoded("base64"))
jsonIn2.UpdateInt("source.pixels.width", 640)
jsonIn2.UpdateInt("source.pixels.height", 480)
jsonIn2.UpdateString("source.pixels.format", "gray8")

jsonOut = chilkat2.JsonObject()
success = fmt.QrCode("read", jsonIn, jsonOut)
Not using C#, C++ or Python? The example is shown in three languages only to give a feel for the code. The Chilkat classes, including Formats, have the same methods and the same JSON requests in every supported language: C, C++, C#, VB.NET, Java, Objective-C, Swift, Python, PHP, Perl, Ruby, Node.js, Electron, React Native, Dart / Flutter, Go, Rust, Zig, Delphi, C++Builder, Free Pascal / Lazarus, Classic ASP, VB6, VBScript, FoxPro, DataFlex, PowerBuilder, Xojo, Xbase++, PureBasic, AutoIt, B4A / B4J, LabVIEW, SQL Server and Tcl. See Chilkat Downloads for Every Language.

The response names what was read in image: width, height, format (png, jpeg or pixels) and, when the file states a resolution (a PNG pHYs chunk in metres, a JFIF density), dpi.

PNG

Every color type and bit depth is read: grayscale, truecolor and palette images, with or without alpha or a transparency chunk, 1 to 16 bits per sample. Reading is strict. A file with a wrong signature, a failed CRC, chunks out of order or damaged image data is refused with invalidImage at /source, and so is a file with data after its end. Interlaced PNG, animated PNG (APNG) and a file with an unknown critical chunk are refused with unsupportedFeature.

JPEG

Baseline, extended sequential and progressive JPEG with 8-bit samples are read, in grayscale or YCbCr color, with any chroma subsampling in which every component's sampling factor divides the largest (4:4:4, 4:2:2, 4:2:0, 4:4:0, 4:1:1 and others), with or without restart intervals.

ResponseWhen
unsupportedFeature at /sourceA valid JPEG outside that subset: 12-bit samples, arithmetic coding, lossless or hierarchical JPEG, two or four components (CMYK, YCCK), RGB stored without a color transform, sampling factors that are not whole multiples of each other.
invalidImage at /sourceAnything malformed or truncated. The decoder is strict and never returns a partial image. One deliberate leniency: bytes after the end-of-image marker are ignored, because cameras and phones append data there.

Exif orientation

A camera often stores a portrait photograph as landscape pixels plus an Exif Orientation tag that tells a viewer how to turn it. With source.applyExifOrientation true (the default) and a tag of 2 to 8, the image is turned first, so that image.width and image.height, reader.region and every coordinate in the response refer to the image as it is shown. The response reports the tag in image.exifOrientation and what was done in image.orientationApplied.

a JPEG stored on its side (orientation 6), read with the defaults
{
  "image": { "width": 640, "height": 480, "format": "jpeg", "exifOrientation": 6, "orientationApplied": true },
  "results": [ { ..., "geometry": { ..., "rotation": 12, ... } } ],
  ...
}
the same file with "applyExifOrientation": false — the coordinates are those of the stored pixels
{
  "image": { "width": 480, "height": 640, "format": "jpeg", "exifOrientation": 6, "orientationApplied": false },
  "results": [ { ..., "geometry": { ..., "rotation": 282, ... } } ],
  ...
}

Orientations 2, 4, 5 and 7 show a mirror image, so a symbol in such a file is reported with mirrored: true. An Exif block that cannot be parsed, or an orientation outside 1 to 8, is ignored: there is then no exifOrientation member, and no error. PNG files and raw pixels carry no orientation.

Size limit: limits.maxPixels (default 16,777,216) bounds the width × height of the decoded image, and it is checked before memory is allocated. A larger image fails with resourceLimit at /source. See Limits and errors.

reader

How hard to look, and where

The reader group controls the search. The defaults suit most images: the reader looks for dark-on-light and light-on-dark symbols, upright or turned, mirrored or not, at full size and on reduced copies of large images.

MemberValuesDefaultNotes
reader.symbologiesarray of symbology IDsall that can be readOnly "qr" can be read in v11.8.0. An unknown ID is invalidEnum; a known symbology that cannot be read yet ("microQr") is unsupportedFeature; a symbology outside the QR family given to QrCode is optionNotApplicable. The path names the entry: /reader/symbologies/0.
reader.profile"fast" · "balanced" · "thorough""balanced"fast uses one global threshold. balanced adds a local (adaptive) threshold and, for images of 1000 px or more, copies reduced to a half and a quarter. thorough adds a second local window and always tries the reduced copies.
reader.region{ x, y, width, height, units }the whole imageSearch only this rectangle. units is "pixels" (default) or "normalized" (fractions of the image, 0 to 1). The rectangle must lie inside the image (outOfRange otherwise). Coordinates in the response stay those of the full image.
reader.maxResults1–4096100Stop after this many symbols. Reaching it is success, with "stopReason": "maxResults" in the response.
reader.expectedCount1–maxResults—Stop as soon as this many symbols are decoded: the fastest way to read an image known to hold one symbol. Also reported as "stopReason": "maxResults".
reader.tryInvertbooltrueAlso read light-on-dark symbols.
reader.tryMirrorbool · "auto""auto"Also try the mirror image of each candidate. auto is the same as true.
reader.tryDownscalebooltrueAllow the reduced copies of the profile.
reader.tryRotatebooltrueAccepted for uniformity with other symbologies. QR Codes are found at any angle whatever its value.
reader.allowDamagedbooltruefalse keeps only the symbols that needed no error correction at all.
reader.fallbackCharsetcharset name"iso-8859-1"The charset of byte data that is not UTF-8 and has no ECI. See Text and bytes.
reader.assembleStructuredAppendbooltrueCombine the symbols of a structured-append set in assemblies[].
reader.pureSymbol
reader.dpm
reader.checksum
false
"off"
"require"
as shownReserved. Only the values shown are accepted.

Several symbols, in any state

An image may hold many symbols, and they need not look alike. The four below are read with the default settings:

idtextbounds x, yrotationmirroredinverted
0https://www.chilkatsoft.com44, 360°falsefalse
1WIFI:T:WPA;S:Chilkat Guest;P:correct\;horse;;240, 360°falsefalse
2INVERTED: light on dark52, 2400°falsetrue
3tel:+1-202-555-0143256, 240270°truefalse

Results are in position order: by the top edge of the bounding box, then by its left edge, so symbols printed in one row stay in left-to-right order. id is the index in that order. With "tryInvert": false and "tryMirror": false the same image gives 2 results: the light-on-dark and the mirrored symbol are no longer looked for.

Reading part of an image

reader.region restricts the search, which is faster and lets you address one area of a form or a label. This request reads the top right quarter of the sheet:

request
{
  "source": { "path": "sheet.png" },
  "reader": {
    "region": { "x": 0.5, "y": 0, "width": 0.5, "height": 0.5, "units": "normalized" }
  }
}

It returns one result, WIFI:T:WPA;S:Chilkat Guest;P:correct\;horse;;, with its bounds at x: 240, y: 36 — full-image coordinates, not coordinates within the region.

Stopping early

When you know how many symbols the image holds, say so. The search ends as soon as that many are decoded:

request
{ "source": { "path": "sheet.png" }, "reader": { "expectedCount": 1 } }
response (abridged)
{
  "image": { "width": 408, "height": 408, "format": "png" },
  "results": [ { "symbology": "qr", "frame": 0, "id": 0, "text": "https://www.chilkatsoft.com", ... } ],
  "stopReason": "maxResults",
  "errors": [], "warnings": []
}
Many symbols on one image: a sheet of labels is read in one call. The search keeps up to 1024 finder patterns per pass, which is about 320 symbols; to read more than about 300 from one image, read it in parts with reader.region. Remember to raise reader.maxResults above its default of 100.

results

What each result carries

The results group selects what each entry of results[] carries. Leave out what you do not need: a response without bytes and geometry is smaller and quicker to walk.

MemberDefaultAdds to each result
results.includeBytestruebytesBase64: the payload bytes.
results.includeGeometrytruegeometry: where the symbol is.
results.includeMetadatatruemetadata: version, error-correction level, mask, ECI, FNC1, structured append.
results.includeSegmentsfalsesegments[]: how the data was encoded, segment by segment.
results.includeDiagnosticsfalsediagnostics: how much error correction was needed.
results.includeCropsfalsecrop: a PNG image of the symbol, cut from the source. See Extract.
results.order"position"The order of results[]. position is the only value.

The members of a result

MemberMeaning
symbologyAlways "qr" in v11.8.0.
idThe index of the result, in position order. Other parts of the response refer to a symbol by it.
frameAlways 0 (reserved for multi-frame sources).
byteCountThe number of payload bytes.
text
textStatus
The payload as text (UTF-8 in the JSON), when textStatus is "valid". See Text and bytes.
charset
charsetSource
The charset the bytes were taken to be in, and how that was decided.
bytesBase64The payload bytes: the logical content, never raw codewords. Kanji and Hanzi characters are their Shift-JIS and GB2312 byte pairs.
geometry.bounds{ x, y, width, height }: the upright bounding box of the symbol, without quiet zone.
geometry.polygonThe four corners of the symbol, without quiet zone, in the symbol's own order: the corners at its top-left, top-right and bottom-right, then bottom-left, as the symbol was printed. For a turned or mirrored symbol they are therefore not in the image's clockwise-from-top-left order.
geometry.rotationThe clockwise angle of the symbol's top edge, 0 to 359 degrees.
geometry.moduleSizePixels per module.
geometry.mirrored
geometry.inverted
Whether the symbol is a mirror image; whether it is light on dark.
metadata.version
metadata.errorCorrection
metadata.mask
The QR version (1–40), the level ("L", "M", "Q", "H") and the mask pattern (0–7) of the symbol.
metadata.eciWhen the symbol has ECI designators: their values, in the order they occur.
metadata.fnc1
metadata.fnc1ApplicationIndicator
When the symbol is in FNC1 mode: "first" (GS1) or "second" (with the application indicator).
metadata.structuredAppendWhen the symbol is part of a set: { index, total, parity }. See structured append.
parseStatus
parsed
With "parse": { "enabled": true }: the content interpreted as a structured payload.
Coordinates are in pixels of the source image, measured from its top-left corner, with x to the right and y down. They are positions of pixel edges, so a symbol whose first dark pixel is in column 24 starts at x: 24. Values are written with at most two decimals.

Text and bytes

A QR symbol holds bytes; whether they are text, and in which charset, is partly a matter of convention. The reader always returns the bytes, and returns text when it can be sure of it. A failure to make text is never a failure to decode.

charsetSourceHow the charset was decided
"eci"The symbol states its charset with an ECI designator.
"utf8Detected"No ECI, and the bytes are well-formed UTF-8: they are taken as UTF-8. This is what nearly every QR code in use today holds.
"fallback"No ECI, and the bytes are not UTF-8: they are read in reader.fallbackCharset (default ISO-8859-1, the default of the QR standard).
"mixed"Different parts of the symbol are in different charsets.
"none"Digits or alphanumeric data only: no charset is involved.
textStatusMeaning
"valid"text is present.
"invalid"The bytes are not valid in their stated or assumed charset. There is no text.
"unavailable"The symbol declares binary data or an unknown ECI, or the text would contain the character U+0000. There is no text.
a symbol holding "Café Zürich" in ISO-8859-1, without an ECI
{
  "symbology": "qr", "frame": 0, "id": 0, "byteCount": 11, "text": "Café Zürich",
  "textStatus": "valid", "charset": "iso-8859-1", "charsetSource": "fallback",
  "bytesBase64": "Q2Fm6SBa/HJpY2g="
}
the same kind of text, declared as UTF-8 with ECI 26 (results.includeSegments is on)
{
  "symbology": "qr", "frame": 0, "id": 0, "byteCount": 17, "text": "Grüße aus Köln",
  "textStatus": "valid", "charset": "utf-8", "charsetSource": "eci",
  "metadata": { "version": 2, "errorCorrection": "M", "mask": 0, "eci": [ 26 ] },
  "segments": [ { "mode": "byte", "byteOffset": 0, "byteCount": 17, "eci": 26 } ]
}
nine arbitrary bytes, among them a zero byte
{
  "symbology": "qr", "frame": 0, "id": 0, "byteCount": 9, "textStatus": "unavailable",
  "charset": "iso-8859-1", "charsetSource": "fallback", "bytesBase64": "AAEC+vv8/f7/"
}

reader.fallbackCharset accepts utf-8, us-ascii, iso-8859-1 to iso-8859-16, windows-1250 to windows-1258, shift_jis, gb2312, big5, euc-kr and cp437. The ECI values understood are 0 to 13, 15 to 18 and 20 to 30 (character sets) and 899 (binary).

Segments and diagnostics

segments[] lists the data segments of the symbol in order: mode (numeric, alphanumeric, byte, kanji or hanzi), the byteOffset and byteCount of its bytes within the payload, and its eci when one applies. diagnostics reports correctedCodewords (the number of codewords the Reed-Solomon error correction had to repair) and formatBitErrors (the number of wrong bits in the format information): a simple measure of how clean the symbol was.

"results": { "includeSegments": true, "includeDiagnostics": true } — the photograph above
{
  "segments": [ { "mode": "byte", "byteOffset": 0, "byteCount": 52 } ],
  "diagnostics": { "correctedCodewords": 0, "formatBitErrors": 0 }
}

structured append

Messages split across several symbols

A structured-append set is one message split across up to 16 symbols. Each symbol is an ordinary result, with metadata.structuredAppend giving its index (from 0), the total and the parity byte of the whole message. When all the symbols of a set are in the image, assemblies[] gives the message whole.

response (geometry and bytes left out)
{
  "image": { "width": 436, "height": 152, "format": "png" },
  "results": [
    {
      "symbology": "qr", "frame": 0, "id": 0, "byteCount": 23,
      "text": " back together by read.", "textStatus": "valid", "charset": "utf-8",
      "charsetSource": "utf8Detected",
      "metadata": {
        "version": 2, "errorCorrection": "M", "mask": 6,
        "structuredAppend": { "index": 2, "total": 3, "parity": 89 }
      }
    },
    {
      "symbology": "qr", "frame": 0, "id": 1, "byteCount": 24,
      "text": "One message, split acros", "textStatus": "valid", "charset": "utf-8",
      "charsetSource": "utf8Detected",
      "metadata": {
        "version": 2, "errorCorrection": "M", "mask": 1,
        "structuredAppend": { "index": 0, "total": 3, "parity": 89 }
      }
    },
    {
      "symbology": "qr", "frame": 0, "id": 2, "byteCount": 24,
      "text": "s three QR codes and put", "textStatus": "valid", "charset": "utf-8",
      "charsetSource": "utf8Detected",
      "metadata": {
        "version": 2, "errorCorrection": "M", "mask": 2,
        "structuredAppend": { "index": 1, "total": 3, "parity": 89 }
      }
    }
  ],
  "assemblies": [
    {
      "id": 0, "total": 3, "parity": 89, "complete": true, "componentIds": [ 1, 2, 0 ],
      "association": "inferred", "byteCount": 71,
      "text": "One message, split across three QR codes and put back together by read.",
      "textStatus": "valid"
    }
  ],
  "errors": [], "warnings": []
}
Member of an assemblyMeaning
total
parity
What the symbols of the set state.
componentIds[]The ids of the results that make up the message, in message order.
completeTrue when every index is present exactly once and the parity byte matches the assembled bytes.
byteCount
text, textStatus
bytesBase64
The whole message, for a complete set. A character split between two symbols comes out intact.
association"inferred": the symbols were grouped by their total and parity, which is all a QR symbol says about its set.
missingIndexes[]
conflicts[]
For an incomplete set: the parts that were not found, and the indexes found more than once with different content. There is then no combined message.

The parts always stay in results[]. "assembleStructuredAppend": false in reader leaves out assemblies[].

Use the assembled messages — C#
// After a successful read: the messages that were split across several symbols
int n = jsonOut.SizeOfArray("assemblies");
for (int i = 0; i < n; i++) {
    jsonOut.I = i;
    if (jsonOut.BoolOf("assemblies[i].complete")) {
        Console.WriteLine(jsonOut.StringOf("assemblies[i].text"));
    } else {
        Console.WriteLine(jsonOut.SizeOfArray("assemblies[i].missingIndexes") + " of "
            + jsonOut.IntOf("assemblies[i].total") + " symbols are missing");
    }
}
Use the assembled messages — C++
// After a successful read: the messages that were split across several symbols
int n = jsonOut.SizeOfArray("assemblies");
for (int i = 0; i < n; i++) {
    jsonOut.put_I(i);
    if (jsonOut.BoolOf("assemblies[i].complete")) {
        std::cout << jsonOut.stringOf("assemblies[i].text") << "\r\n";
    } else {
        std::cout << jsonOut.SizeOfArray("assemblies[i].missingIndexes") << " of "
            << jsonOut.IntOf("assemblies[i].total") << " symbols are missing\r\n";
    }
}
Use the assembled messages — Python
# After a successful read: the messages that were split across several symbols
n = jsonOut.SizeOfArray("assemblies")
for i in range(n):
    jsonOut.I = i
    if jsonOut.BoolOf("assemblies[i].complete"):
        print(jsonOut.StringOf("assemblies[i].text"))
    else:
        print(jsonOut.SizeOfArray("assemblies[i].missingIndexes"), "of",
              jsonOut.IntOf("assemblies[i].total"), "symbols are missing")

detect

Locate symbols without decoding them

detect runs the search of read and stops before decoding. It reports where the QR symbols are and what speaks for each being one, and never their content. A symbol that cannot be decoded — damaged beyond the error correction, or too blurred — is still reported, which makes detect the way to tell "there is no code here" from "there is a code here that cannot be read".

request
{ "source": { "path": "damaged.png" } }
response: detect finds both (read finds 1)
{
  "image": { "width": 360, "height": 185, "format": "png" },
  "candidates": [
    {
      "symbology": "qr", "frame": 0, "id": 0, "decodeStatus": "notAttempted",
      "geometry": {
        "bounds": { "x": 30, "y": 30, "width": 125, "height": 125 },
        "polygon": [
          { "x": 30, "y": 30 }, { "x": 155, "y": 30 }, { "x": 155, "y": 155 },
          { "x": 30, "y": 155 }
        ],
        "rotation": 0, "moduleSize": 5, "mirrored": false, "inverted": false
      },
      "evidence": {
        "finderPatterns": 3, "functionPatternMatch": 1, "timingPatternMatch": 1,
        "alignmentPattern": true, "formatInformation": "valid", "formatBitErrors": 0,
        "estimatedVersion": 2
      }
    },
    {
      "symbology": "qr", "frame": 0, "id": 1, "decodeStatus": "notAttempted",
      "geometry": {
        "bounds": { "x": 205, "y": 30, "width": 125, "height": 125 },
        "polygon": [
          { "x": 205, "y": 30 }, { "x": 330, "y": 30 }, { "x": 330, "y": 155 },
          { "x": 205, "y": 155 }
        ],
        "rotation": 0, "moduleSize": 5, "mirrored": false, "inverted": false
      },
      "evidence": {
        "finderPatterns": 3, "functionPatternMatch": 0.93, "timingPatternMatch": 1,
        "alignmentPattern": false, "formatInformation": "valid", "formatBitErrors": 0,
        "estimatedVersion": 2
      }
    }
  ],
  "errors": [], "warnings": []
}
MemberMeaning
candidates[]Always present, in position order; empty when nothing is found (which is success). There is no results[] and no assemblies[].
decodeStatusAlways "notAttempted".
geometryAs for read: the same corner order, units and rounding.
evidence.finderPatternsThe number of finder patterns the candidate was built from (3).
evidence.functionPatternMatch0 to 1: the share of the function-pattern modules — finder patterns and separators, timing patterns, alignment patterns, the dark module, version information — that look as the estimated version draws them. A candidate is reported only at 0.85 or more.
evidence.timingPatternMatchThe same for the timing patterns alone.
evidence.alignmentPatternWhether the alignment pattern near the fourth corner was found. Absent for version 1, which has none.
evidence.formatInformation
evidence.formatBitErrors
"valid" (read without correction), "corrected" (1 to 3 bits corrected; formatBitErrors says how many) or "unreadable".
evidence.estimatedVersionThe QR version that the number of modules gives.

A detect request takes source and limits as read does. From reader it takes symbologies, profile, region, tryRotate, tryInvert, tryMirror, tryDownscale and maxDetected (1–4096, default 100: reaching it is success with "stopReason": "maxDetected"). From results it takes includeGeometry and order. Everything that concerns decoding is optionNotApplicable — parse, reader.maxResults, expectedCount, allowDamaged, fallbackCharset, assembleStructuredAppend, and the other members of results — as is reader.maxDetected for read.

To get an image of a symbol that cannot be decoded, use extract with includeUndecoded.

What is read

The scope of the reader

What the reader of v11.8.0 handles, and where it stops.

Symbols

QR Code Model 2, versions 1–40, levels L/M/Q/H, all eight masks. Numeric, alphanumeric, byte, Kanji and Hanzi (GB/T 18284) data in any mix, ECI, FNC1 in first and second position, structured append.

Appearance

Any rotation, perspective (a symbol seen at an angle), mirror images, light on dark, several symbols per image, uneven lighting, moderate blur and noise. Modules of two pixels or more in a photograph; one pixel per module in a cleanly rendered image.

Damage

Reed-Solomon error correction to the limits of the standard, and format and version information with up to three wrong bits. diagnostics tells you how much was repaired.

Not read in v11.8.0: Micro QR, rMQR and QR Code Model 1; every other symbology (linear barcodes, Data Matrix, PDF417, Aztec). Known limits: heavy defocus (a blur of about half a module or more) defeats the reader; a symbol on a curved or creased surface is read only as far as one perspective mapping fits it; two overlapping symbols with different content are not flagged.

Limits and errors

Stopping, limits and failures

The two limits of every operation apply to reading as well, and a read can end in three ways short of a full search.

MemberRangeDefaultFor read, detect and extract
limits.timeoutMs1–600,00010,000A deadline for the whole call, including the decoding of the image file.
limits.maxPixels1–67,108,86416,777,216The largest width × height of the source image (each side is also limited to 32,768). Checked before the image is decoded.
stopReasonReturnsMeaning
"maxResults"trueThe search stopped at reader.maxResults or reader.expectedCount. results[] holds what was found.
"maxDetected"truedetect stopped at reader.maxDetected.
"timeout"
"cancelled"
falseThe deadline passed, or the application aborted the call. For read, results[] is still in the response, next to errors[], with the symbols decoded before the stop; for detect, candidates[] likewise. read and detect are the only operations whose failure response holds more than the error.

Errors of reading

A failed call returns false with one entry in errors[], as every operation does. The request-rejection codes are those of the other operations; these are the ones specific to an image source. The messages shown are the real ones.

CodePathMessageWhen
inputFailed/source/paththe source file does not exist, is empty or cannot be readThe file of source.path is missing, empty or unreadable.
invalidImage/sourcethe source is not a recognized image (PNG and JPEG are the supported encoded formats)The data is not a well-formed PNG or JPEG: a wrong signature, a failed CRC, truncated or corrupt image data.
unsupportedFeature/source—A valid image that is outside what is decoded: interlaced or animated PNG, a JPEG outside the supported subset.
resourceLimit/sourcethe image has more pixels than limits.maxPixels allowsThe image is larger than limits.maxPixels.
missingOption/sourcea source image is requiredThe request has no source.
unknownOption/symbologyunknown optionA read request carries a member of the generate vocabulary (symbology, payload, render, …).
optionNotApplicable/reader/maxResultsthis option applies to read; detect does not decodeAn option of one read operation given to another.