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

PHP Example

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

1. Copying the Engine Files

[Note] In this example, the engine file is extracted to the examples/bin/ directory to share it with other examples. However, for actual deployment, the engine file is typically copied to the directory where the application’s executable file is located.

2. Prerequisites

  1. Install PHP 8.0 or higher with required extensions

    Ubuntu/Debian:

    # Add ondrej/php PPA for PHP packages
    sudo apt-get update
    sudo apt-get install -y software-properties-common
    sudo add-apt-repository -y ppa:ondrej/php
    sudo apt-get update
    
    # Install PHP with required extensions
    sudo apt-get install -y php8.2 php8.2-cli php8.2-imagick
    
    # Enable FFI in php.ini
    sudo sed -i 's/;ffi.enable.*/ffi.enable=true/' /etc/php/8.2/cli/php.ini
    

    CentOS/RHEL/Fedora:

    sudo dnf install php php-cli php-pecl-imagick
    
    # Enable FFI in php.ini
    sudo sed -i 's/;ffi.enable.*/ffi.enable=true/' /etc/php.ini
    

    macOS:

    brew install php imagemagick
    pecl install imagick
    
    # Enable FFI in php.ini
    echo "ffi.enable=true" >> $(php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||")
    

    Windows:

    • Download PHP from https://windows.php.net/download/
    • Install ImageMagick and php_imagick.dll
    • Enable in php.ini:
      ffi.enable=true
      extension=imagick
      
  2. Verify installation

    php --version
    php -m | grep -E "(FFI|imagick)"
    

3. How to Run

cd examples/PHP/anpr
php anpr.php

4. Features

5. API Reference

TSANPR Class

class TSANPR {
    public function __construct(string $libraryPath);
    public function anprInitialize(string $mode): string;
    public function anprReadFile(string $imgFileName, string $outputFormat, string $options): string;
    public function anprReadPixels(string $pixels, int $width, int $height, int $stride,
                                   string $pixelFormat, string $outputFormat, string $options): string;
}

Recognition Options

Option Description
"" Single license plate recognition (default)
"vm" Recognize multiple license plates attached to vehicles
"vmb" Recognize multiple license plates (including motorcycles)
"vms" Recognize with surround detection
"dms" Detect multiple surrounding objects (vehicles)
"dmsr" Detect objects and recognize license plates
"dmsri<coords>" Recognize within Region of Interest

Output Formats

"text", "json", "yaml", "xml", "csv"

6. Troubleshooting

FFI not loaded:

# Check FFI status
php -i | grep -i ffi

# Enable FFI in php.ini
ffi.enable=true

Imagick not available:

# Ubuntu/Debian
sudo apt-get install php8.2-imagick

# Verify
php -m | grep imagick