Container depots and terminals increasingly read container numbers with OCR cameras at the gate. OCR is fast, but it is not perfect: a smudged 8 becomes a B, a 0 becomes an O. The good news is that every shipping container number carries its own error check, defined in ISO 6346. You can catch most misreads with a few lines of code before they reach your yard system.
Anatomy of a container number
A container number like CSQU3054383 has four parts:
-
CSQ- the owner code (3 letters) -
U- the equipment category (Ufor freight containers) -
305438- the serial number (6 digits) -
3- the check digit
How the check digit works
- Give each letter a value starting at A = 10, skipping multiples of 11 (so 11, 22 and 33 are never used). Digits keep their own value.
- Multiply each of the first 10 characters by 2 to the power of its position (1, 2, 4, 8 ... 512).
- Add the results, take the remainder after dividing by 11, then take the last digit (a remainder of 10 becomes 0).
import re
def letter_values():
values, n = {}, 10
for ch in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
if n % 11 == 0:
n += 1
values[ch] = n
n += 1
return values
VALUES = letter_values()
PATTERN = re.compile(r"^[A-Z]{3}[UJZ][0-9]{7}$")
def check_digit(first10: str) -> int:
total = sum((VALUES[c] if c.isalpha() else int(c)) * 2 ** i
for i, c in enumerate(first10))
return total % 11 % 10
def is_valid(number: str) -> bool:
number = number.replace(" ", "").upper()
return bool(PATTERN.match(number)) and check_digit(number[:10]) == int(number[10])
print(is_valid("CSQU3054383")) # True
print(is_valid("CSQU3054388")) # False - OCR misread
Using it at the gate
- Reject or flag any OCR reading that fails the check, and ask the gate clerk to confirm only those trucks.
-
Try likely swaps (
O/0,B/8,I/1) on a failed read and accept a candidate only if exactly one passes. - Log both the raw OCR text and the corrected number, so you can measure camera accuracy over time.
This small check turns OCR from "usually right" into something a yard system can trust, which is what makes truly automated gates possible at depots and terminals.
For the bigger picture of how gates, weighbridges, yards and rail sidings work together at an inland depot, see this guide to the inland container depot (ICD).
Top comments (0)