# User Guide for MRZ Scanner with C++

In this guide, you will learn step by step on how to build a MRZ Scanner solution with Dynamsoft Capture Vision SDK using c++.

<span style="font-size:20px">Table of Contents</span>

- [User Guide for MRZ Scanner with C++](#user-guide-for-mrz-scanner-with-c)
  - [About the Solution](#about-the-solution)
  - [System Requirements](#system-requirements)
  - [Installation](#installation)
  - [Build Your Own Application](#build-your-own-application)
    - [Create A New Project](#create-a-new-project)
      - [For Windows](#for-windows)
      - [For Linux](#for-linux)
    - [Include the Library](#include-the-library)
    - [Initialize the License Key](#initialize-the-license-key)
    - [Create a CaptureVisionRouter Instance](#create-a-capturevisionrouter-instance)
    - [Invoke the Capturing](#invoke-the-capturing)
    - [Filter and Get MRZ Details](#filter-and-get-mrz-details)
    - [Release the Allocated Memory](#release-the-allocated-memory)
    - [Build and Run the Project](#build-and-run-the-project)
      - [On Windows](#on-windows)
      - [On Linux](#on-linux)

## About the Solution

With the MRZ Scanner, you can extract the MRZ string from an image of a passport, visa, or ID card, and then parse it to retrieve data such as the first name, last name, document number, nationality, date of birth, expiration date, and personal number, converting them into human-readable fields.

## System Requirements

To find out whether your environment is supported, please read the [System Requirements](https://www.dynamsoft.com/capture-vision/docs/server/programming/cplusplus/index.md#system-requirements).

## Installation

If you haven't downloaded the SDK yet, <a href="https://download2.dynamsoft.com/dcv/dynamsoft-capture-vision-cpp-3.6.3000.260820.zip" target="_blank">download the `C/C++ Package`</a> now and unpack the package into a directory of your choice.

> [!IMPORTANT]
> For this tutorial, we unpack it to a pseudo directory `[INSTALLATION FOLDER]`, change it to your unpacking path for the following content.

## Build Your Own Application

In this section, we’ll walk through the key steps needed to build an application that reads the machine-readable zone (MRZ) from an image file.

> [!TIP]
>You can download the complete source code from [here](https://github.com/Dynamsoft/capture-vision-cpp-samples/tree/main/Samples/MRZScanner).

### Create A New Project

#### For Windows

1. Open Visual Studio. Go to File > New > Project, select Empty App and enter `MRZScanner` in the `name` text box.

2. Add a new source file named `MRZScanner.cpp` into the project.

#### For Linux

1. Create a new source file named `MRZScanner.cpp` and place it into the folder `[INSTALLATION FOLDER]\Samples\MRZScanner`.

2. Create a file named `Makefile` and put it in the same directory as the file `MRZScanner.cpp`. The content of `Makefile` is as follows:

    ```makefile
    CC=gcc
    CCFLAGS=-c -std=c++11

    DLRMODEL_PATH=../../Dist/Models
    DCPRES_PATH=../../Dist/ParserResources
    CONFUSABLE_CHARS_PATH=../../Dist/ConfusableChars.data
    OVERLAPPING_CHARS_PATH=../../Dist/OverlappingChars.data
    DS_JSON_PATH=../../Dist/Templates
    DS_LIB_PATH=../../Dist/Lib/Linux/x64
    LDFLAGS=-L $(DS_LIB_PATH) -Wl,-rpath=$(DS_LIB_PATH) -Wl,-rpath=./
    DS_LIB=-lDynamsoftCaptureVisionRouter -lDynamsoftCore -lDynamsoftUtility -lDynamsoftLicense

    STDLIB=-lstdc++

    TARGET=MRZScanner
    OBJECT=MRZScanner.o
    SOURCE=MRZScanner.cpp

    # build rule for target.
    $(TARGET): $(OBJECT)
        $(CC) -o $(TARGET) $(OBJECT) $(STDLIB) $(DS_LIB) $(LDFLAGS)
        cp -r $(DLRMODEL_PATH) $(DS_LIB_PATH)
        cp -r $(DCPRES_PATH) $(DS_LIB_PATH)
        cp $(CONFUSABLE_CHARS_PATH) $(DS_LIB_PATH)
        cp $(OVERLAPPING_CHARS_PATH) $(DS_LIB_PATH)
        cp -r $(DS_JSON_PATH) $(DS_LIB_PATH)

    # target to build an object file
    $(OBJECT): $(SOURCE)
        $(CC) $(CCFLAGS) $(SOURCE)

    # the clean target
    .PHONY : clean
    clean: 
        rm -f $(OBJECT) $(TARGET) $(DS_LIB_PATH)/ConfusableChars.data $(DS_LIB_PATH)/OverlappingChars.data -r $(DS_LIB_PATH)/Models $(DS_LIB_PATH)/ParserResources $(DS_LIB_PATH)/Templates
    ```

### Include the Library

Add headers and libs in `MRZScanner.cpp`.

```cpp
#include <iostream>
#include <string>
#include "[INSTALLATION FOLDER]/Include/DynamsoftCaptureVisionRouter.h"
#include "[INSTALLATION FOLDER]/Include/DynamsoftUtility.h"

using namespace std;
using namespace dynamsoft::cvr;
using namespace dynamsoft::dlr;
using namespace dynamsoft::dcp;
using namespace dynamsoft::license;
using namespace dynamsoft::utility;

// The following code only applies to Windows.
#if defined(_WIN64) || defined(_WIN32)
    #ifdef _WIN64
        #pragma comment(lib, "[INSTALLATION FOLDER]/Dist/Lib/Windows/x64/DynamsoftCaptureVisionRouterx64.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Dist/Lib/Windows/x64/DynamsoftCorex64.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Dist/Lib/Windows/x64/DynamsoftLicensex64.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Dist/Lib/Windows/x64/DynamsoftUtilityx64.lib")
    #else
        #pragma comment(lib, "[INSTALLATION FOLDER]/Dist/Lib/Windows/x86/DynamsoftCaptureVisionRouterx86.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Dist/Lib/Windows/x86/DynamsoftCorex86.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Dist/Lib/Windows/x86/DynamsoftLicensex86.lib")
        #pragma comment(lib, "[INSTALLATION FOLDER]/Dist/Lib/Windows/x86/DynamsoftUtilityx86.lib")
    #endif
#endif
```

### Initialize the License Key

If this is your first time using the library, you will need to obtain a trial license key. We recommend getting your own 30-day trial license through the following modal:

<link href="/webres/wwwroot/css/intlTelInput.min.css" rel="stylesheet" />
<script src="/webres/wwwroot/js/intlTelInput.min.js"></script>
<script src="/webres/wwwroot/js/docs/dayjs.min.js"></script>
<link rel="stylesheet" href="/webres/wwwroot/fontawesome-free-5.13.0-web/css/all.min.css" />
<link rel="stylesheet" href="/webres/wwwroot/css/docs/trialLicense.css" />

<div class="trial-license-wrap" style="display: none;">
  <div class="not-logged-in hide">
    <p class="title">Request a Trial License</p>
    <div class="result">
      <div class="key">Demo: DLS2eyJvcmdhbml6YXeyJo34567AwMDAxLTEwM34XphdGlvbk812345AxIn0= </div>
      <div type="button" class="d-btn orange-btn reveal-btn">Reveal</div>
    </div>
  </div>
  <div class="had-license hide">
    <p class="title">Your Trial License <span class="expiredTime"></span></p>
    <div class="result">
      <div class="key">
        DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9DLS2eyJoYW5kc2hha2VDb2RlIjoiMjAwMDAxLTEwMTIwMDkzNiIsIm9yZ2FuaXphdGlvbklEIjoiMjAwMDAxIn0=
      </div>
      <i class="fa fa-copy"></i>
      <div type="button" class="d-btn orange-btn copy-btn">Copy</div>
      <div type="button" class="d-btn orange-btn extend-btn" style="display: none;">Extend</div>
    </div>
    <p class="note" style="display: none;color: #ec403d;">You've reached the limit for trial requests. Please <a href="/contact/">contact our support team</a>, and we will be happy to extend additional time for you.​</p>
    <span class="copyied">Copied!</span>
  </div>
  <div class="request-success hide">
    <p class="title">Request a Trial License - Successful</p>
    <div class="desc">
      <i class="icon-send"></i>
      <p>The license will be sent to your email immediately. If you don't see it in your inbox, please check your
        junk/spam folder as well.</p>
    </div>
  </div>
</div>

<div class="modal trial-license-request-modal" tabindex="-1">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <i class="icon-close"></i>
      <div class="modal-body">
        <div class="loading" id="loadingLogin" style="display: none;">
          <div class="lds-ring">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
          </div>
        </div>
        <div class="emailErrorAlert off">
          <div class="ds-alert error">
            <p>We are unable to deliver to the email address provided. Please try a different one.</p>
            <div class="ds-alert-close-btn"></div>
          </div>
        </div>
        <div class="third-party-request">
          <p>One Click to Request a 30-Day Trial License</p>
          <div class="login-btns">
            <div type="button" class="third-party-btn github-btn"><i class="fab fa-github"></i>Github</div>
            <div type="button" class="third-party-btn microsoft-btn"><i class="fab fa-microsoft"></i>Microsoft</div>
            <div type="button" class="third-party-btn google-btn">
              <div class="gsi-material-button-icon">
                  <svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" xmlns:xlink="http://www.w3.org/1999/xlink" style="display: block;">
                      <path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"></path>
                      <path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"></path>
                      <path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"></path>
                      <path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"></path>
                      <path fill="none" d="M0 0h48v48H0z"></path>
                  </svg>
              </div>
              Google
            </div>
          </div>
        </div>
        <p class="devide">or continue with a work email</p>
        <div class="dynamsoft-request">
          <div class="basicForm">
            <div class="basicFormGroup" style="grid-area: a">
              <input type="email" id="Email" name="email" class="basicFormInput" autofocus placeholder=" " />
              <div class="placeholder"><span>*</span> Business Email Address</div>
            </div>
            <div class="clearfix" style="grid-area: b">
              <div class="basicFormGroup fl" style="width: 49.5%">
                <input type="text" id="FirstName" class="basicFormInput" placeholder=" ">
                <div class="placeholder"><span>*</span> First Name</div>
              </div>
              <div class="basicFormGroup fr" style="width: 49.5%">
                <input type="text" id="LastName" class="basicFormInput" placeholder=" ">
                <div class="placeholder"><span>*</span> Last Name</div>
              </div>
            </div>
            <div class="basicFormGroup companyField" style="grid-area: c">
              <input type="text" id="CompanyName" class="basicFormInput" placeholder=" ">
              <div class="placeholder"><span>*</span> Company Name</div>
            </div>
            <div class="basicFormGroup phoneNumberField" style="grid-area: d">
              <input type="tel" id="PhoneNumber" class="basicFormInput" autocomplete="new-password" placeholder=" ">
              <div class="placeholder"><span>*</span> Phone Number</div>
            </div>
          </div>
          <div class="generateLine">
            <div type="button" class="generateLicense" value="Generate a License">Generate a License</div>
            <p>The license will be sent to your email immediately.</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="modal trial-license-extend-modal" tabindex="-1">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <i class="icon-close"></i>
      <div class="modal-body">
        <div class="businessEmailFormGroup">
          <div class="basicForm tc businessEmailForm" style="position: relative;">
            <div class="businessEmailErrorAlert off">
              <div class="ds-alert error">
                <p>We are unable to deliver to the email address provided. Please try a different one.</p>
                <div class="ds-alert-close-btn"></div>
              </div>
            </div>
            <div class="businessEmailStep">
              <h3 class="title mb20 tl">Link your business email</h3>
              <p class="mb20 tl desc">To extend your trial, please link your business email. We use it to keep your license and account records together.</p>
              <div class="collectUserInfo">
                <div class="basicFormGroup">
                  <input name="businessEmail" id="businessEmail" type="email" class="basicFormInput" placeholder=" " required>
                  <div class="placeholder"><span>*</span> Business Email</div>
                </div>
              </div>
              <p class="businessEmailLockedNote tl" style="display: none;">This business email cannot be changed. If you need to update it, please contact our sales team.</p>
              <button class="d-btn border-btn verifyBusinessEmailBtn fontOswald">Verify &amp; extend my trial</button>
            </div>
            <div class="businessEmailCodeStep" style="display: none;">
              <h3 class="title mb20 tl">Enter verification code</h3>
              <p class="mb20 tl desc">We've sent a 6-digit verification code to <span class="businessEmailCodeTarget"></span>. Enter it below to link your business email and extend your trial.</p>
              <div class="collectUserInfo">
                <div class="basicFormGroup">
                  <input type="text" id="businessEmailVerifyCode" class="basicFormInput" placeholder=" " maxlength="6" inputmode="numeric" autocomplete="one-time-code" required>
                  <div class="placeholder"><span>*</span> Verification Code</div>
                </div>
              </div>
              <button class="d-btn border-btn confirmBusinessEmailCodeBtn fontOswald">Confirm &amp; extend my trial</button>
              <div class="resendBusinessEmailCodeLine">
                <a href="javascript:;" class="orangeLink resendBusinessEmailCode">Resend verification code</a>
              </div>
            </div>
            <div class="businessEmailPasswordStep" style="display: none;">
              <h3 class="title mb20 tl">Verify ownership</h3>
              <p class="mb20 tl desc">This business email is associated with an existing account. Enter the password of <span class="businessEmailPasswordTarget"></span> to verify ownership and extend your trial.</p>
              <div class="collectUserInfo">
                <div class="basicFormGroup">
                  <input type="password" id="businessEmailPassword" class="basicFormInput" placeholder=" " autocomplete="current-password" required>
                  <div class="placeholder"><span>*</span> Password</div>
                </div>
              </div>
              <button class="d-btn border-btn confirmBusinessEmailPasswordBtn fontOswald">Verify &amp; extend my trial</button>
              <div class="resetBusinessEmailPasswordLine">
                <a href="javascript:;" class="orangeLink resetBusinessEmailPassword">Forgot password?</a>
              </div>
            </div>
          </div>
        </div>
        <div class="extensionSurvey">
          <div class="survey survey1">
            <div class="form-group">
              <label class="control-label">Are you building an app for your own company or for a client? <span
                  class="fontOrange">*</span></label>
              <div class="radio-group">
                <div class="radio">
                  <label class="radio">
                    <input name="BuildingAppUser" id="BuildingAppUser1" type="radio" value="Own Company" required>
                    <label for="BuildingAppUser1"><span>Own Company</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="BuildingAppUser" id="BuildingAppUser2" type="radio" value="A Client">
                    <label for="BuildingAppUser2"><span>A Client</span></label>
                  </label>
                </div>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label">Which one of the following deployment types best describes your <span
                  class="showQ1A2" style="display: none;">client's</span> usage scenario? <span
                  class="fontOrange">*</span></label>
              <div class="radio-group">
                <div class="radio">
                  <label class="radio">
                    <input name="UsageScenario" data-businessType="100000000" id="UsageScenario1" type="radio"
                      value="Internal use by employees and contractors of my company only" required>
                    <label for="UsageScenario1"><span>Internal use by employees and contractors of my <span
                          class="showQ1A2" style="display: none;">client's</span> company only</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="UsageScenario" data-businessType="100000002" id="UsageScenario2" type="radio"
                      value="Hosted software/service for consumption by customers (e.g., SaaS)">
                    <label for="UsageScenario2"><span>Hosted software/service for consumption by customers (e.g.,
                        SaaS)</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="UsageScenario" data-businessType="100000001" id="UsageScenario3" type="radio"
                      value="Product for sale to customers for on-premises use">
                    <label for="UsageScenario3"><span>Product for sale to customers for on-premises use</span></label>
                  </label>
                </div>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label">When do you need to release your application with the SDK feature integrated?
                <span class="fontOrange">*</span></label>
              <div class="radio-group">
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTime" id="ReleaseTime1" type="radio" value="Less than a week" required>
                    <label for="ReleaseTime1"><span>Less than a week</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTime" id="ReleaseTime2" type="radio" value="Less than a month">
                    <label for="ReleaseTime2"><span>Less than a month</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTime" id="ReleaseTime3" type="radio" value="1 to 3 months">
                    <label for="ReleaseTime3"><span>1 to 3 months</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTime" id="ReleaseTime4" type="radio" value="3 to 6 months">
                    <label for="ReleaseTime4"><span>3 to 6 months</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTime" id="ReleaseTime5" type="radio" value="More than 6 months">
                    <label for="ReleaseTime5"><span>More than 6 months</span></label>
                  </label>
                </div>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label">How many end users (persons) will need the SDK feature in your application?
                <span class="fontOrange">*</span></label>
              <div class="radio-group">
                <div class="radio">
                  <label class="radio">
                    <input name="CompanySize" id="CompanySize1" type="radio" value="Less than 30" required>
                    <label for="CompanySize1"><span>Less than 30</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="CompanySize" id="CompanySize2" type="radio" value="31 - 100">
                    <label for="CompanySize2"><span>31 - 100</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="CompanySize" id="CompanySize3" type="radio" value="101 - 500">
                    <label for="CompanySize3"><span>101 - 500</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="CompanySize" id="CompanySize4" type="radio" value="501 - 1000">
                    <label for="CompanySize4"><span>501 - 1000</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="CompanySize" id="CompanySize5" type="radio" value="More than 1000">
                    <label for="CompanySize5"><span>More than 1000</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="CompanySize" id="CompanySize6" type="radio" value="I don't know">
                    <label for="CompanySize6"><span>I don't know</span></label>
                  </label>
                </div>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label">So far, does our SDK meet your need well? <span
                  class="fontOrange">*</span></label>
              <div class="radio-group">
                <div class="radio">
                  <label class="radio">
                    <input name="CustomerReviews" id="CustomerReviews1" type="radio" value="Yes, I am satisfied."
                      required>
                    <label for="CustomerReviews1"><span>Yes, I am satisfied.</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="CustomerReviews" id="CustomerReviews2" type="radio"
                      value="Yes, I just need more time to complete the development.">
                    <label for="CustomerReviews2"><span>Yes, I just need more time to complete the
                        development.</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="CustomerReviews" id="CustomerReviews3" type="radio"
                      value="I haven't tried the SDK yet.">
                    <label for="CustomerReviews3"><span>I haven't tried the SDK yet.</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="CustomerReviews" id="CustomerReviews4" type="radio"
                      value="No, I need some technical help.">
                    <label for="CustomerReviews4"><span>No, I need some technical help.</span></label>
                  </label>
                  <textarea id="MyTechnicalHelp" rows="2" name="MyTechnicalHelp" placeholder=""></textarea>
                </div>
              </div>
            </div>
          </div>
          <div class="survey survey2">
            <div class="form-group">
              <label class="control-label">Based on your current estimation, how soon will you release the application
                with the SDK features? <span class="fontOrange">*</span></label>
              <div class="radio-group">
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTimeB" id="ReleaseTimeB1" type="radio" value="Less than a week" required>
                    <label for="ReleaseTimeB1"><span>Less than a week</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTimeB" id="ReleaseTimeB2" type="radio" value="Less than a month">
                    <label for="ReleaseTimeB2"><span>Less than a month</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTimeB" id="ReleaseTimeB3" type="radio" value="1 to 3 months">
                    <label for="ReleaseTimeB3"><span>1 to 3 months</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTimeB" id="ReleaseTimeB4" type="radio" value="3 to 6 months">
                    <label for="ReleaseTimeB4"><span>3 to 6 months</span></label>
                  </label>
                </div>
                <div class="radio">
                  <label class="radio">
                    <input name="ReleaseTimeB" id="ReleaseTimeB5" type="radio" value="More than 6 months">
                    <label for="ReleaseTimeB5"><span>More than 6 months</span></label>
                  </label>
                </div>
              </div>
            </div>
            <div class="form-group">
              <label class="control-label">How has your experience been with the SDK during your trial period? <span
                  class="fontOrange">*</span></label>
              <div class="textarea-group">
                <textarea id="OtherInfo" rows="2" name="OtherRequiredOrSuggestion" placeholder=""></textarea>
              </div>
            </div>
          </div>
          <div class="submitSurvyLine">
            <span class="d-btn submit-btn fontOswald">Submit</span>
            <p>The license will be sent to your email immediately.</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="/webres/wwwroot/js/AesGcmHybridEncryptor.js"></script>
<script src="/webres/wwwroot/js/docs/trialLicense.js"></script>

Open the `MRZScanner.cpp` file and add the following code inside the `Main` method to initialize the license for using the SDK in the application:

```cpp
int errorcode = 0;
char error[512];
errorcode = CLicenseManager::InitLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9", error, 512);
if (errorcode != ErrorCode::EC_OK && errorcode != ErrorCode::EC_LICENSE_CACHE_USED)
{
    cout << "License initialization failed: ErrorCode: " << errorcode << ", ErrorString: " << error << endl;
}
else
{
    // codes from following steps...
}
```

> [!NOTE]
> The string "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" here is a free public trial license. Note that network connection is required for this license to work. Please replace it with your own 30-day trial license.

### Create a CaptureVisionRouter Instance

```cpp
CCaptureVisionRouter* router = new CCaptureVisionRouter();
```

### Invoke the Capturing

```cpp
string imageFile = "[PATH-TO-THE-IMAGE-FILE]";
CCapturedResult* result = router->Capture(imageFile.c_str(), "ReadPassportAndId");
```

> [!IMPORTANT]
> Please change the `[PATH-TO-THE-IMAGE-FILE]` to a real image file path.

### Filter and Get MRZ Details

```cpp
cout << "File: " << imageFile << endl;
if (result->GetErrorCode() != 0) {
    cout << "Error: " << result->GetErrorCode() << "," << result->GetErrorString() << endl;
}
CParsedResult* dcpResult = result->GetParsedResult();
if (dcpResult == NULL || dcpResult->GetItemsCount() == 0)
{
    cout << "No MRZ results." << endl;
}
else
{
    int lCount = dcpResult->GetItemsCount();
    cout << "Detected " << lCount << " MRZ Result(s)." << endl;
    for (int i = 0; i < lCount; i++)
    {
        const CParsedResultItem *item = dcpResult->GetItem(i);
        string docType = item->GetCodeType();
        cout << "DocumentType: " << docType << endl;
        if (docType == "MRTD_TD3_PASSPORT")
        {
            cout << "DocumentID: " << item->GetFieldValue("passportNumber") << endl;
        }
        else
        {
            cout << "DocumentID: " << item->GetFieldValue("documentNumber") << endl;
        }
        //get more field values
        //cout << "DocumentID: " << item->GetFieldValue("[FIELD-NAME]") << endl;
    }
}
```

### Release the Allocated Memory

```cpp
if (dcpResult)
    dcpResult->Release();
if (result)
    result->Release();
delete router, router = NULL;   
```

### Build and Run the Project

#### On Windows

1. Build the application through Visual Studio.

2. Copy the following items from `[INSTALLATION FOLDER]\Dist` to the same folder as the EXE file. 
   
   - All the DLL files from `.\Lib\Windows\[PLATFORMS]`
   - File `ConfusableChars.data`
   - File `OverlappingChars.data`
   - File `Models\MRZTextLineRecognition.data` (including folder `Models`)
   - File `Models\MRZCharRecognition.data` (including folder `Models`)
   - File `Templates\MRZScanner.json` (including folder `Templates`)
   - Folders `ParserResources`

3. Run the program `MRZScanner.exe`.

#### On Linux

1. Open a terminal and change to the target directory where `Makefile` located in. Build the sample:

    ```sh
    >make
    ```

2. Run the program `MRZScanner`.

    ```sh
    >./MRZScanner
    ```

> [!IMPORTANT]
> Please change all `[INSTALLATION FOLDER]` in above code snippet to your unpacking path.
