This project is a Scala application designed to read, process, and decode EAN-13 barcodes from PPM images. It performs a pipeline of image processing steps to convert color images into bit patterns and then decodes the numeric value of the barcode.
- PPM Image Parsing: Reads standard
.ppm(P6) color images. - Image Processing Pipeline:
- Grayscale Conversion: Converts RGB pixels to grayscale values (PGM format).
- Binarization: Converts grayscale images to black and white (PBM format) using adaptive thresholding.
- Barcode Decoding:
- Identifies start/end guard patterns.
- Decodes digits based on parities (Odd/Even) and run-length encoding.
- Verifies checks to ensure valid EAN-13 codes.
src/main/scala/Convertor.scala: Handles image conversions (RGB -> Greyscale -> B&W).src/main/scala/Decoder.scala: Logic for decoding barcode bit patterns into digits.src/main/scala/Main.scala: Main processing flow that reads files and applies the pipeline.src/main/scala/MyBarcodes.scala: Entry point for user-defined input/output directories.src/main/scala/Parser.scala: Parses binary PPM file headers and content.src/main/scala/Types.scala: Definitions for internal data structures (Bit, Pixel, Image types).
- Scala: 3.3.5
- sbt: (Simple Build Tool) 1.x or higher
-
Clone the repository:
git clone <repository-url> cd <project-folder>
-
Prepare Input:
- Create a folder named
MyBarcodesInputin the project root. - Place your
.ppmimages containing barcodes into this folder.
- Create a folder named
-
Run the Application: You can run the application using
sbt.sbt run
When prompted, select
MyBarcodesas the main class to run.Alternatively, you can modify
MyBarcodes.scalato change the input/output directory names:val barcodes = readBarcodes("MyBarcodesInput", "MyBarcodesOutput")
-
Check Output:
- The application will print the decoded barcode numbers to the console.
- Processed black-and-white images (
.pbm) will be saved in theProcessedBarcodes(or specified output) directory.
- Input: A raw
.ppmimage. - Convert to Greyscale: Calculates luminance for each pixel.
- Convert to Black & White: Uses a quadrant-based adaptive threshold to distinguish black bars from white spaces.
- Scan & Decode:
- Scans the middle of the image.
- Converts pixel runs into bits (run-length matching).
- Matches bit patterns to EAN-13 digit encodings considering parity (Left/Right/G-parity).
- Validates the checksum digit.