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

Groovy Example

https://github.com/bobhyun/TS-ANPR/tree/main/examples/Groovy/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 Java JDK 8 or higher

    Ubuntu/Debian:

    sudo apt-get update
    sudo apt-get install -y openjdk-11-jdk
    

    CentOS/RHEL/Fedora:

    sudo dnf install java-11-openjdk-devel
    

    macOS:

    brew install openjdk@11
    

    Windows:

    • Download and install JDK from https://adoptium.net/ or https://www.oracle.com/java/technologies/downloads/
  2. Install Groovy

    Ubuntu/Debian:

    sudo apt-get install -y groovy
    

    CentOS/RHEL/Fedora:

    sudo dnf install groovy
    

    macOS:

    brew install groovy
    

    Windows:

    • Download from https://groovy.apache.org/download.html
    • Or use SDKMAN: sdk install groovy
  3. Verify installation

    java -version
    groovy --version
    

3. How to Run

cd examples/Groovy/anpr

# Run the ANPR example
groovy anpr.groovy

4. Features

5. API Reference

TSANPR Module

The TSANPR class provides the following methods:

// Load the TSANPR library
def tsanpr = new TSANPR(libraryPath)

// Initialize the ANPR engine
String error = tsanpr.initialize(mode)

// Read and process an image file
String result = tsanpr.readFile(imgFileName, outputFormat, options)

// Process pixel data directly
String result = tsanpr.readPixels(pixels, width, height, stride, pixelFormat, outputFormat, options)

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. Implementation Notes

This example uses JNA (Java Native Access) for dynamic library loading:

Dynamic Library Loading:

Groovy Features:

Pixel Buffer Processing: The readPixelBuffer function uses Java’s BufferedImage to load and decode images. It extracts raw pixel data and passes it to anpr_read_pixels() with the appropriate pixel format using JNA’s Memory class.

7. Troubleshooting

Groovy not found:

# Check if Groovy is installed
groovy --version

# Ubuntu/Debian: Install Groovy
sudo apt-get install groovy

# Or use SDKMAN
curl -s "https://get.sdkman.io" | bash
sdk install groovy

JNA dependency issues:

# Grape should automatically download JNA
# If issues persist, check network connectivity or proxy settings

# Clear Grape cache and retry
rm -rf ~/.groovy/grapes/net.java.dev.jna
groovy anpr.groovy

Library loading issues:

Runtime issues: