Creating the Dockerfile
Let's take a look at an example Dockerfile for building a US-specific ANPR service:
ARG repository
ARG architecture
FROM ${repository}:base-x86-64 AS carmen-worker-x86-64
FROM ${repository}:base-arm64 AS carmen-worker-arm64
FROM carmen-worker-${architecture}
ENV PreProcessingAnprEngines='{"nam":["nam_frq_fpo","nam_pst_fpo"]}'
ENV LocalAnprEngines='{"US-CT":"usa_ne_local_plus_nam","US-ME":"usa_ne_local_plus_nam","US-MA":"usa_ne_local_plus_nam","US-NH":"usa_ne_local_plus_nam","US-RI":"usa_ne_local_plus_nam","US-VT":"usa_ne_local_plus_nam","US-NJ":"usa_ne_local_plus_nam","US-NY":"usa_ne_local_plus_nam","US-PA":"usa_ne_local_plus_nam","US-DE":"usa_sa_local_plus_nam","US-FL":"usa_sa_local_plus_nam","US-GA":"usa_sa_local_plus_nam","US-MD":"usa_sa_local_plus_nam","US-NC":"usa_sa_local_plus_nam","US-SC":"usa_sa_local_plus_nam","US-VA":"usa_sa_local_plus_nam","US-DC":"usa_sa_local_plus_nam","US-WV":"usa_sa_local_plus_nam","US-AL":"usa_sc_local_plus_nam","US-KY":"usa_sc_local_plus_nam","US-MS":"usa_sc_local_plus_nam","US-TN":"usa_sc_local_plus_nam","US-AR":"usa_sc_local_plus_nam","US-LA":"usa_sc_local_plus_nam","US-OK":"usa_sc_local_plus_nam","US-TX":"usa_sc_local_plus_nam","US-AZ":"usa_w_local_plus_nam","US-CO":"usa_w_local_plus_nam","US-ID":"usa_w_local_plus_nam","US-MT":"usa_w_local_plus_nam","US-NV":"usa_w_local_plus_nam","US-NM":"usa_w_local_plus_nam","US-UT":"usa_w_local_plus_nam","US-WY":"usa_w_local_plus_nam","US-AK":"usa_w_local_plus_nam","US-CA":"usa_w_local_plus_nam","US-HI":"usa_w_local_plus_nam","US-OR":"usa_w_local_plus_nam","US-WA":"usa_w_local_plus_nam","US-IL":"usa_mw_local_plus_nam","US-IN":"usa_mw_local_plus_nam","US-MI":"usa_mw_local_plus_nam","US-OH":"usa_mw_local_plus_nam","US-WI":"usa_mw_local_plus_nam","US-IA":"usa_mw_local_plus_nam","US-KS":"usa_mw_local_plus_nam","US-MN":"usa_mw_local_plus_nam","US-MO":"usa_mw_local_plus_nam","US-NE":"usa_mw_local_plus_nam","US-ND":"usa_mw_local_plus_nam","US-SD":"usa_mw_local_plus_nam"}'
ENV AnprRegions='{"nam":["nam","world"]}'
ENV MmrRegions='{"nam":["mmr-nam"]}'
#ENV AdrRegions='{"nam":["adr","nam","imoadr"]}'
#ENV OcrEngines='{"am-rail":"am_rail","eu-rail":"eu_rail","iso":"iso","truck":"truck"}'
ENV AnprEngineConfidenceSettings='{"default":{"normalized":{"minimum":10,"stopAt":90},"text":{"minimum":50,"stopAt":95},"custom":{"minimum":10,"stopAt":100}}}'
COPY gxsd.dat /var/gx/
COPY lib/ /usr/lib64/gx/
COPY dat/ /usr/share/gx/
This Dockerfile demonstrates how to configure the base image with a custom engine selection and configuration. Let's break down the key parts:
ARG repository
ARG architecture
FROM ${repository}:base-x86-64 AS carmen-worker-x86-64
FROM ${repository}:base-arm64 AS carmen-worker-arm64
FROM carmen-worker-${architecture}
This section uses multi-stage builds to support both x86-64 and arm64 architectures. It selects the appropriate base image based on the architecture build argument. The repository build arugment should normally be the URL of the public Carmen Worker repository:
public.ecr.aws/arcloud/carmen-worker
Next, several environment variables are set to configure the ANPR, MMR, and OCR engines:
ENV PreProcessingAnprEngines='{"nam":["nam_frq_fpo","nam_pst_fpo"]}'
ENV LocalAnprEngines='{"US-CT":"usa_ne_local_plus_nam","US-ME":"usa_ne_local_plus_nam",...}'
ENV AnprRegions='{"nam":["nam","world"]}'
ENV MmrRegions='{"nam":["mmr-nam"]}'
#ENV AdrRegions='{"nam":["adr","nam","imoadr"]}'
#ENV OcrEngines='{"am-rail":"am_rail","eu-rail":"eu_rail","iso":"iso","truck":"truck"}'
ENV AnprEngineConfidenceSettings='{"default":{"normalized":{"minimum":10,"stopAt":90},"text":{"minimum":50,"stopAt":95},"custom":{"minimum":10,"stopAt":100}}}'
The engine names (e.g., nam_frq_fp) need to match the XML tags used in the gxsd.dat file.
PreProcessingAnprEnginesspecifies the ANPR engines to use for pre-processing in each region. The keys of the object are regions the user will need to pass in the URL path parameter, the values are array of engine names (as defined ingxsd.dat).LocalAnprEnginesmaps location names to engine names defined ingxsd.dat. Locations are sent asmultipart/form-datafileds in the POST request made to the API.AnprRegionsandMmrRegionsdefine the ANPR and MMR regions and the engines to use for each of them.AdrRegionsandOcrEnginesare commented out but show how to configure ADR and OCR engines if needed.AnprEngineConfidenceSettingssets confidence thresholds for the ANPR results. If a given confidence value (normalized or text) is less than the minimum specified, the result is discarded. If it is greater than or equal to thestopAtvalue, it is immediately accepted. If no result from any engine reaches thestopAtvalue, the one with the greates confidence is accepted. For engines that do not yet support returning normalized and text confidence values, thecustomsetting is used in a similar way. If no settings are specified at all, all engines are called and the result with the best confidence is selected.
Finally, engine configuration and binaries are copied into the image:
COPY gxsd.dat /var/gx/
COPY lib/ /usr/lib64/gx/
COPY dat/ /usr/share/gx/
gxsd.datis copied to/var/gx/- Libraries from
lib/are copied to/usr/lib64/gx/ - Data files from
dat/are copied to/usr/share/gx/
By modifying this Dockerfile and providing the engines of your choice, and custom configuration, you can fully customize the Carmen Worker to suit your specific license plate and vehicle recognition requirements. Building a custom Docker image from this also allows easy deployment of your tailored solution.