ALPR Tuning Tool - License Plate Recognition Optimization Tool
ALPR Tuning Tool is an academic project developed to facilitate the optimization of image processing parameters used in license plate recognition systems.
https://github.com/EtHeGeM/JavaCV developed with love by the ALPR Academic Project Team at Istanbul Isik University.
Personal thanks for E.Gemici and M.Ozbay for their overall and helps contributions.
This project is not a complete license plate recognition system . Its main purpose is to provide a tool for real-time testing and optimization of:
Image processing parameters (blur, canny, dilate etc.)
Detection algorithms (Haar Cascade, Geometric Detection)
OCR settings
used in license plate recognition systems.
The most challenging part when developing license plate recognition systems is finding optimal parameters for different lighting conditions, camera angles, and plate types. This tool:
Visual Feedback : Allows you to instantly see the effect of each parameter change
Dual Detection Comparison : Compares Haar Cascade and Geometric detection methods side by side
Automatic Saving : Automatically saves your settings so you can return to the best parameters
Debug Outputs : Saves images of each processing step
Method
Description
Color Code
Haar Cascade
Fast detection with pre-trained cascade classifier
Green
Geometric Detection
Contour analysis and aspect ratio filtering
Blue
High Confidence
Regions detected by both methods
Red
Bilateral Filter Kernel : Image smoothing
Canny Threshold 1 & 2 : Edge detection sensitivity
Dilate Kernel & Iterations : Morphological dilation
Aspect Ratio (Min/Max) : Plate width-height ratio filter
Real-time preview (6 different modes)
Display OCR results
Turkish plate format validation
Automatic configuration saving
Result reporting in CSV format
Batch processing support
Operating System : Windows 10/11, Linux, macOS
Java : JDK 17 or higher
RAM : Minimum 4GB (8GB recommended)
Disk : 500MB free space
Dependency
Version
Description
OpenCV
4.9.0
Image processing library
Tess4J
5.11.0
Tesseract OCR Java wrapper
SLF4J
2.0.9
Logging facade
Logback
1.4.14
Logging implementation
git clone https://github.com/YOUR_USERNAME/JavaCV.git
cd JavaCV
2. Tesseract OCR Installation
# With Chocolatey:
choco install tesseract
# or manually:
# Download from https://github.com/UB-Mannheim/tesseract/wiki
sudo apt-get update
sudo apt-get install tesseract-ocr tesseract-ocr-eng
Make sure the eng.traineddata file is in the tessdata/ folder:
JavaCV/
├── tessdata/
│ └── eng.traineddata ← This file is required!
To download: tessdata repository
# Download dependencies and compile
mvn clean install
# To skip tests:
mvn clean install -DskipTests
mvn exec:java -Dexec.mainClass=" com.alpr.TuningGUI"
CLI Mode (Batch Processing)
# Single image processing
mvn exec:java -Dexec.mainClass=" com.alpr.Main" -Dexec.args=" path/to/image.jpg"
# Process all images in folder
mvn exec:java -Dexec.mainClass=" com.alpr.Main" -Dexec.args=" src/plates"
6. Creating Distributable Package
Creating Fat JAR (All dependencies included)
This command creates the following files in the target/ folder:
File
Description
license-plate-recognition-1.0-SNAPSHOT.jar
Executable JAR containing all dependencies
alpr-cli.exe
Windows CLI application
alpr-gui.exe
Windows GUI application
# CLI mode
java -jar target/license-plate-recognition-1.0-SNAPSHOT.jar src/plates
# GUI mode
java -cp target/license-plate-recognition-1.0-SNAPSHOT.jar com.alpr.TuningGUI
Running Windows EXE Files
# CLI version
target\a lpr-cli.exe src/plates
# GUI version (can also be opened by double-clicking)
target\a lpr-gui.exe
7. Preparing Distribution Package
To distribute the application, copy these files to a folder:
ALPR-Distribution/
├── alpr-cli.exe # or .jar file
├── alpr-gui.exe # or .jar file
├── tessdata/
│ └── eng.traineddata # Required for OCR
├── haarcascade_russian_plate_number.xml # Haar cascade model
└── alpr_config.properties # (optional) pre-configured parameters
Note: Java 17+ must be installed on the user's computer. EXE files use the JAVA_HOME environment variable.
Load Image : Load the image to be tested
Adjust Parameters : Use sliders to change parameters
Detect : Run plate detection (runs automatically if Auto is selected)
Run OCR : Run OCR on detected plates
Preview Mode : View different processing steps
Mode
Description
Original + Overlays
Original image + detection boxes
Grayscale
Grayscale image
Filtered
Bilateral filter applied
Canny Edges
Edge detection result
Dilated
After morphological dilation
Detection Result
All detection results
Ctrl+O : Load image
Ctrl+Q : Exit
JavaCV/
├── pom.xml # Maven configuration
├── alpr_config.properties # Automatically saved settings
├── alpr_summary.csv # Summary result report
├── haarcascade_russian_plate_number.xml # Haar Cascade model
│
├── src/
│ ├── main/
│ │ ├── java/com/alpr/
│ │ │ ├── TuningGUI.java # Main GUI application
│ │ │ ├── PlateDetector.java # Plate detection engine
│ │ │ ├── OcrService.java # Tesseract OCR service
│ │ │ ├── DetectionResult.java # Detection result model
│ │ │ ├── Main.java # CLI entry point
│ │ │ └── TestImageGenerator.java # Test image generator
│ │ └── resources/
│ └── plates/ # Test images folder
│
├── tessdata/
│ └── eng.traineddata # Tesseract language file
│
├── debug_output/ # Debug images
│ ├── step1_grayscale/
│ ├── step2_filtered/
│ ├── step3_canny/
│ ├── step3b_dilated/
│ ├── step4_detected_plate/
│ ├── step5_ocr_preprocessed/
│ ├── haar_plates/ # Plates detected with Haar
│ └── geo_plates/ # Plates detected with Geometric
│
└── target/ # Maven build outputs
Main GUI application - Swing-based parameter adjustment and preview tool.
Method
Description
loadConfig()
Loads settings from alpr_config.properties file
saveConfig()
Saves current settings to file
scheduleAutoSave()
Schedules automatic save with debounce mechanism (1s delay)
applyConfig()
Applies loaded settings to UI components
Method
Description
initializeUI()
Creates main window and components
createControlPanel()
Creates left-side control panel
createPreviewPanel()
Creates right-side image preview panel
createStatusBar()
Creates bottom status bar
createMenuBar()
Creates menu bar
createSlider(min, max, value, majorTick, name)
Creates parameter slider
createSliderPanel(label, slider, valueLabel)
Creates labeled panel for slider
createTitledBorder(title)
Creates titled border
createLegendItem(text, color)
Creates color legend label
Method
Description
loadImage()
Loads image with file chooser
processImage()
Runs plate detection and updates results
updatePreview()
Updates preview according to selected mode
runOcrOnAllDetections()
Runs OCR on all detected plates
calculateConfidence(text)
Calculates confidence score of OCR result
resetDefaults()
Returns all parameters to default values
clearOcrResults()
Clears OCR result areas
matToBufferedImage(mat)
Converts OpenCV Mat to BufferedImage
checkResources()
Checks existence of Haar Cascade file
Method
Description
setImage(image)
Sets image to display
setDetectionResults(results, showHaar, showGeo, showOverlap)
Sets detection results and visibility settings
clearOverlays()
Clears overlays
paintComponent(g)
Draws image and detection boxes
drawDetectionRect(g2d, rect, color, scale, offsetX, offsetY, label)
Draws single detection rectangle
Main plate detection engine containing dual detection system.
Method
Description
createDebugDirectories()
Creates debug output folders
initializeHaarClassifier()
Loads Haar Cascade classifier
saveDebugImage(stepDir, image, imageName)
Saves debug image
Method
Description
setBlurKernel(size)
Sets bilateral filter kernel size (odd number)
setCannyThreshold1(threshold)
Sets Canny lower threshold value
setCannyThreshold2(threshold)
Sets Canny upper threshold value
setMinAspectRatio(ratio)
Sets minimum aspect ratio
setMaxAspectRatio(ratio)
Sets maximum aspect ratio
setDilateKernelSize(size)
Sets dilate kernel size
setDilateIterations(iterations)
Sets dilate iteration count
setHaarScaleFactor(factor)
Sets Haar scale factor
setHaarMinNeighbors(neighbors)
Sets Haar minimum neighbor count
Method
Description
getBlurKernel()
Returns blur kernel value
getCannyThreshold1()
Returns Canny threshold 1 value
getCannyThreshold2()
Returns Canny threshold 2 value
getMinAspectRatio()
Returns minimum aspect ratio value
getMaxAspectRatio()
Returns maximum aspect ratio value
getDilateKernelSize()
Returns dilate kernel size
getDilateIterations()
Returns dilate iteration count
isHaarAvailable()
Returns whether Haar cascade is available
Intermediate Image Getters
Method
Description
getOriginalImage()
Returns original loaded image
getLastGrayImage()
Returns grayscale image
getLastFilteredImage()
Returns filtered image
getLastEdgeImage()
Returns Canny edge image
getLastDilatedImage()
Returns dilated image
getLastContourImage()
Returns contour visualization image
getLastResults()
Returns last detection results
getCurrentImageName()
Returns current image name
Method
Description
loadImage(imagePath)
Loads image from file
preprocess()
Runs image preprocessing pipeline
preprocessImageWithOriginal(imagePath)
Loads image, processes and creates debug records
Method
Description
detectAll()
Runs both detection methods and merges results
detectWithHaar()
Performs plate detection with Haar Cascade
detectWithGeometric()
Performs plate detection with Geometric/Contour analysis
cropPlateWithPadding(rect, padding)
Crops plate region with padding
findHighConfidenceDetections()
Finds regions detected by both methods
Perspective Transform Methods
Method
Description
fourPointTransform(image, pts)
Applies 4-point perspective transform
orderPoints(pts)
Orders corner points (top-left, top-right, bottom-right, bottom-left)
indexOfMin(arr)
Finds index of minimum value in array
indexOfMax(arr)
Finds index of maximum value in array
distance(p1, p2)
Calculates distance between two points
Method
Description
createContourVisualization()
Visualizes detection results with colored boxes
getDetectionStats()
Returns detection statistics as [haar, geo, overlap]
Tesseract OCR integration and plate text recognition service.
Method
Description
initializeTesseract()
Initializes Tesseract engine and applies settings
findTessdataPath()
Automatically finds tessdata folder
ensureDebugDir()
Ensures existence of debug output folder
Method
Description
recognizePlate(plateMat, imageName)
Runs OCR on plate image and returns result
recognizePlate(plateMat)
Runs OCR without image name
preprocessForOcr(plate, imageName)
Image preprocessing for OCR (resize, threshold)
cleanResult(raw)
Cleans OCR result (uppercase, alphanumeric)
Method
Description
setTessdataPath(path)
Sets tessdata path
getTessdataPath()
Returns current tessdata path
setWhitelist(whitelist)
Sets character list to be recognized
setLanguage(lang)
Sets OCR language
isWindows()
Checks if operating system is Windows
isMac()
Checks if operating system is macOS
Data model representing a single plate detection.
Value
Description
HAAR
Detected with Haar Cascade
GEOMETRIC
Detected with Geometric analysis
Constructor
Description
DetectionResult(bounds, method)
Basic constructor (confidence = 1.0)
DetectionResult(bounds, method, confidence)
Constructor with confidence value
Method
Description
getBounds()
Returns detection rectangle (Rect)
getMethod()
Returns detection method
getConfidence()
Returns confidence value
getCroppedPlate()
Returns cropped plate image
setCroppedPlate(mat)
Sets cropped plate image
getOcrResult()
Returns OCR result
setOcrResult(text)
Sets OCR result
Method
Description
calculateIoU(other)
Calculates IoU with another detection
calculateIoU(r1, r2)
(static) Calculates IoU between two rectangles
overlaps(other, threshold)
Checks if overlap exceeds specified threshold
Command line interface and entry point for batch processing.
Method
Description
main(args)
Application entry point
processDirectory(directory)
Processes all images in folder
processAndPrintResult(imagePath)
Processes single image and prints result
processImage(imagePath, expectedPlate)
Runs complete ALPR pipeline
Method
Description
extractExpectedPlate(fileName)
Extracts expected plate from filename
countMatchingChars(expected, actual)
Calculates matching character count
calculateScore(text, expected)
Calculates score of OCR result
Method
Description
printFinalSummary()
Prints detailed summary report to console
exportResultsToCSV()
Saves results to timestamped CSV file
exportSummaryRow(timestamp)
Adds summary row to alpr_summary.csv
truncate(str, maxLen)
Truncates text to specified length
getStatusSymbol(result)
Returns symbol for result status (✓, ~, ✗)
6. TestImageGenerator.java
Test image generation utility class.
Method
Description
generateTestImage(outputPath)
Creates synthetic test image (640x480, simulated plate)
Parameters and Optimization
Image Processing Pipeline
Original Image
↓
1. Grayscale Conversion
↓
2. CLAHE (Contrast Limited Adaptive Histogram Equalization)
↓
3. Bilateral Filter (blur kernel)
↓
4. Canny Edge Detection (threshold1, threshold2)
↓
5. Morphological Closing (21x5 kernel)
↓
6. Dilation (dilate kernel, iterations)
↓
7. Contour Analysis + Aspect Ratio Filtering
↓
Detected Plates
Parameter Recommendations
Parameter
Default
Low Value Effect
High Value Effect
Blur Kernel
11
More noise
Detail loss
Canny T1
50
More edges
Fewer edges
Canny T2
150
More edges
Fewer edges
Dilate Kernel
3
Thin edges
Thick edges
Dilate Iter
2
Gaps
Merged areas
Min AR
2.0
Square regions included
Only rectangles
Max AR
7.0
Narrow plates excluded
Wide regions included
Turkish plates have the following format: [2 digits][1-3 letters][2-4 digits]
Examples:
34ABC123 (Istanbul)
06XY1234 (Ankara)
35A12 (Izmir)
Folder
Content
step1_grayscale/
Grayscale images
step2_filtered/
After bilateral filter
step3_canny/
After Canny edge detection
step3b_dilated/
After dilation
step4_detected_plate/
Detected plate regions
step5_ocr_preprocessed/
Images prepared for OCR
haar_plates/
Plates detected with Haar
geo_plates/
Plates detected with Geometric
alpr_results_YYYYMMDD_HHMMSS.csv : Detailed result report
alpr_summary.csv : Summary rows for parameter comparison
ALPR Academic Project Team:
Mert Ozbay
Defne Oktem
Ata Atay
Ayse Ceren Sarigul
Aylin Baki
Ahmad Ali al Ghazi
This project is licensed under GNU General Public License v3.0 (GPL-3.0) .
This license provides:
Commercial use
Modification
Distribution
Patent use
Private use
Conditions:
Source code must be open
License and copyright notice must be included
Same license must be used (copyleft)
Changes must be stated
For details, see the LICENSE file or GNU GPL v3.0 page.
"Haar Cascade file not found"
# Make sure the Haar cascade file is in the project root directory
ls haarcascade_russian_plate_number.xml
# Add to PATH for Windows or check tessdata folder
dir tessdata\e ng.traineddata
# Re-download Maven dependencies
mvn clean install -U
Use GitHub Issues for problems or contact the project team.
Developed for optimization in license plate recognition systems.