Skip to the content.
English 한국어 日本語 Tiếng Việt

Ví dụ Erlang

https://github.com/bobhyun/TS-ANPR/tree/main/examples/Erlang/anpr

1. Sao chép các tệp Engine

[Lưu ý] Trong ví dụ này, tệp engine được giải nén vào thư mục examples/bin/ để chia sẻ với các ví dụ khác. Tuy nhiên, đối với triển khai thực tế, tệp engine thường được sao chép vào thư mục nơi tệp thực thi của ứng dụng được đặt.

2. Yêu cầu tiên quyết

  1. Cài đặt Erlang/OTP (khuyến nghị phiên bản 24 trở lên)

    Windows:

    # Tải từ https://www.erlang.org/downloads
    # Hoặc sử dụng Chocolatey
    choco install erlang
    

    Linux:

    # Ubuntu/Debian
    sudo apt-get update
    sudo apt-get install -y erlang
    
    # Oracle Linux / RHEL / CentOS (8/9+)
    sudo dnf install -y erlang || sudo yum install -y erlang
    # Gợi ý: Nếu không tìm thấy gói, hãy bật EPEL hoặc dùng repo Erlang Solutions:
    # https://www.erlang.org/downloads
    
    # Hoặc dùng kerl (khuyến nghị)
    curl -O https://raw.githubusercontent.com/kerl/kerl/master/kerl
    chmod a+x kerl
    ./kerl build 24.3 24.3
    ./kerl install 24.3 ~/erlang/24.3
    # Kích hoạt trong shell hiện tại
    . ~/erlang/24.3/activate
    # Hủy kích hoạt: deactivate
    
  2. Cài đặt rebar3

    Windows:

    Tải xuống rebar3 escript mới nhất từ GitHub:

    # Tải xuống rebar3 mới nhất (tương thích với Erlang/OTP 28+)
    Invoke-WebRequest -Uri "https://github.com/erlang/rebar3/releases/latest/download/rebar3" -OutFile "rebar3"
       
    # Đặt rebar3 trong thư mục dự án hoặc di chuyển vào thư mục trong PATH
    

    Lưu ý: Trên Windows, rebar3 phải được chạy với escript rebar3 <lệnh> (không phải chỉ rebar3 <lệnh>).

    Linux:

    # Ubuntu/Debian
    sudo apt-get install rebar3
       
    # Hoặc tải phiên bản mới nhất từ GitHub
    wget https://github.com/erlang/rebar3/releases/latest/download/rebar3
    chmod +x rebar3
    sudo mv rebar3 /usr/local/bin/
    
  3. Cài đặt trình biên dịch C (cần thiết cho việc build NIF)

    Windows:

    • Cài đặt Visual Studio với công cụ phát triển C++, hoặc
    • Cài đặt MinGW-w64: choco install mingw

    Linux:

    # Ubuntu/Debian
    sudo apt-get install build-essential
    
    # Fedora/CentOS
    sudo yum groupinstall "Development Tools"
    
  4. Xác minh cài đặt

    erl -version
    rebar3 version
    gcc --version  # cl.exe trên Windows khi sử dụng Visual Studio
    

3. Build và chạy

  1. Chuyển đến thư mục ví dụ Erlang

    cd examples/Erlang/anpr
    
  2. Build thư viện NIF (Native Implemented Function)

    Windows:

    Mở “x64 Native Tools Command Prompt for VS” (hoặc chạy vcvars64.bat), sau đó:

    build_nif.bat
    

    Sẽ thực hiện:

    • Tự động phát hiện cài đặt Erlang
    • Biên dịch c_src/tsanpr_nif.c bằng MSVC
    • Tạo priv/tsanpr_nif.dll

    Linux:

    make priv/tsanpr_nif.so
    

    Sẽ thực hiện:

    • Biên dịch c_src/tsanpr_nif.c bằng gcc
    • Tạo priv/tsanpr_nif.so với liên kết libdl thích hợp
  3. Build ứng dụng Erlang

    Windows (sử dụng lệnh escript):

    escript rebar3 compile
    

    Linux:

    rebar3 compile
    

    Sẽ thực hiện:

    • Biên dịch các module Erlang (anpr.erl, tsanpr.erl) vào _build/default/lib/anpr/ebin/
    • Sao chép thư viện NIF từ priv/ sang _build/default/lib/anpr/priv/
  4. Chạy ứng dụng

    # Chế độ không tương tác
    erl -pa _build/default/lib/anpr/ebin -noshell -eval "anpr:main()" -s init stop
    
    # Chế độ tương tác
    erl -pa _build/default/lib/anpr/ebin
    1> anpr:main().
    

4. Ghi chú

5. Tính năng

6. Tham khảo API

Module tsanpr

Module tsanpr cung cấp các hàm sau:

Khởi tạo:

Hàm cốt lõi:

Tùy chọn nhận dạng

Định dạng đầu ra

7. Khắc phục sự cố

Vấn đề tải thư viện:

Vấn đề NIF:

Vấn đề cụ thể theo nền tảng: