Build a Java SpringBoot 3.x License Plate Recognition System with OCR

This article walks through creating a server‑side license‑plate recognition solution using Java SpringBoot 3.x, Tesseract OCR, and OpenCV, covering project goals, Maven dependencies, image‑processing services, special‑plate handling, and a REST API for real‑time plate detection.

Java Tech Enthusiast
Java Tech Enthusiast
Java Tech Enthusiast
Build a Java SpringBoot 3.x License Plate Recognition System with OCR

This tutorial demonstrates how to combine OCR technology with the Java SpringBoot 3.x framework to build a license‑plate recognition system applicable to security, logistics, and traffic scenarios.

Goal and Requirements

The system aims to accurately and quickly identify vehicle license plates, supporting real‑time data for vehicle control, safety checks, and traffic statistics. Key requirements include high accuracy, fast response, scalability for concurrent requests, and a user‑friendly interface for image upload and result display.

License Plate OCR Recognition

We use the open‑source Tesseract OCR library, which can be trained to recognize specific characters such as license‑plate text.

Add Project Dependencies

<dependency>
  <groupId>org.bytedeco</groupId>
  <artifactId>leptonica-platform</artifactId>
  <version>1.78.0-1.5.3</version>
</dependency>

<dependency>
  <groupId>org.bytedeco</groupId>
  <artifactId>tesseract-platform</artifactId>
  <version>4.1.1-1.5.3</version>
</dependency>

Image Processing Service

Using OpenCV for preprocessing (denoising, binarization, contrast enhancement) we implement LicensePlateRecognitionService:

import org.bytedeco.javacpp.*;
import org.bytedeco.leptonica.*;
import org.bytedeco.tesseract.*;
import java.io.File;

@Service
public class LicensePlateRecognitionService {
    public String recognizeLicensePlate(String imagePath) {
        // Create TessBaseAPI object
        TessBaseAPI api = new TessBaseAPI();
        // Initialize Tesseract (point to tessdata directory)
        if (api.Init("/path/to/tesseract/tessdata", "eng") != 0) {
            System.err.println("Could not initialize tesseract.");
            System.exit(1);
        }
        // Load image
        PIX image = pixRead(imagePath);
        if (image == null) {
            System.err.println("Could not open input image.");
            System.exit(1);
        }
        // Set image for OCR
        api.SetImage(image);
        // Get result
        String result = api.GetUTF8Text().getString();
        api.End();
        pixDestroy(image);
        return result;
    }
}

Handling Special and Abnormal Plates

The SpecialLicensePlateService preprocesses plates with non‑standard colors, fonts, or damage using OpenCV:

import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

@Service
public class SpecialLicensePlateService {
    static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
    public String preprocess(String imagePath) {
        Mat src = Imgcodecs.imread(imagePath, Imgcodecs.IMREAD_GRAYSCALE);
        Mat dst = new Mat();
        // Denoising
        Imgproc.fastNlMeansDenoising(src, dst, 10, 7, 21);
        // Binarization
        Imgproc.threshold(dst, dst, 0, 255, Imgproc.THRESH_BINARY + Imgproc.THRESH_OTSU);
        // Contrast enhancement
        CLAHE clahe = Imgproc.createCLAHE();
        clahe.setClipLimit(4.0);
        clahe.apply(dst, dst);
        String processedImagePath = "/path/to/processed/image";
        Imgcodecs.imwrite(processedImagePath, dst);
        return processedImagePath;
    }
}

Actual Application Integration

When a request arrives, the controller first preprocesses the image if needed, then calls the recognition service:

@RestController
public class LicensePlateController {
    @Autowired
    private SpecialLicensePlateService specialLicensePlateService;
    @Autowired
    private LicensePlateRecognitionService licensePlateRecognitionService;

    @RequestMapping("/recognize")
    public String recognize(@RequestParam("image") String imagePath) {
        String processedImagePath = specialLicensePlateService.preprocess(imagePath);
        String licensePlate = licensePlateRecognitionService.recognizeLicensePlate(processedImagePath);
        return licensePlate;
    }
}

The API saves the uploaded image, runs preprocessing if required, and returns the recognized plate number to the client.

Conclusion

The article provides a complete, practical solution for license‑plate recognition, covering design, dependency setup, image preprocessing, OCR integration, and a SpringBoot REST endpoint, enabling developers to apply the approach in their own projects.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaOCRSpringBootOpenCVlicense plate recognitiontesseract
Java Tech Enthusiast
Written by

Java Tech Enthusiast

Sharing computer programming language knowledge, focusing on Java fundamentals, data structures, related tools, Spring Cloud, IntelliJ IDEA... Book giveaways, red‑packet rewards and other perks await!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.