| 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.
- For Windows x86 64-bit
Extract the engine file to the
examples/bin/windows-x86_64directory7z x tsanpr*-windows-x86_64.7z - For Windows x86 32-bit
Extract the engine file to the
examples/bin/windows-x86directory7z x tsanpr*-windows-x86.7z - For Linux x86 64-bit
Extract the engine file to the
examples/bin/linux-x86_64directorytar xvf tsanpr-linux-x86_64.tar.xz - For Linux arm 64-bit
Extract the engine file to the
examples/bin/linux-aarch64directorytar xvf tsanpr-linux-aarch64.tar.xz - Directory structure
examples ├── bin │ ├─── windows-x86_64 # engine directory for Windows (x86_64) │ │ ├── tsanpr.dll │ │ ├── tsanpr-2505M.eon │ │ └── tshelper.exe │ ├─── windows-x86 # engine directory for Windows (x86) │ │ ├── tsanpr.dll │ │ ├── tsanpr-2505M.eon │ │ └── tshelper.exe │ ├── linux-x86_64 # engine directory for Linux (x86_64) │ │ ├── libtsanpr.so │ │ ├── tsanpr-2505M.eon │ │ └── tshelper │ └── linux-aarch64 # engine directory for Linux (arm64) │ ├── libtsanpr.so │ ├── tsanpr-2505M.eon │ └── tshelper ├── img # image directory └── PHP └── anpr # source directory ├── anpr.php ├── TSANPR.php └── composer.json
2. Prerequisites
-
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.iniCentOS/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.inimacOS:
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
-
Verify installation
php --version php -m | grep -E "(FFI|imagick)"
3. How to Run
cd examples/PHP/anpr
php anpr.php
4. Features
- readImageFile: Process image files directly using
anpr_read_file() - readEncodedImage: Process encoded image data (JPEG, PNG, etc.) using
anpr_read_pixels()with ‘encoded’ format - readPixelBuffer: Process raw pixel data using Imagick extension
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