Skip to content

This project is a functional programming application written in Scala 3, designed to process and decode EAN-13 barcodes from raw digital images. The application implements a complete image processing pipeline—from parsing low-level pixel data to algorithmic decoding of barcode digits—without relying on external computer vision libraries.

Notifications You must be signed in to change notification settings

GeorgeGrasu/Barcode-Reader-In-Scala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Barcode Reader (Scala)

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.

Features

  • 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.

Project Structure

  • 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).

Requirements

  • Scala: 3.3.5
  • sbt: (Simple Build Tool) 1.x or higher

Setup and Usage

  1. Clone the repository:

    git clone <repository-url>
    cd <project-folder>
  2. Prepare Input:

    • Create a folder named MyBarcodesInput in the project root.
    • Place your .ppm images containing barcodes into this folder.
  3. Run the Application: You can run the application using sbt.

    sbt run

    When prompted, select MyBarcodes as the main class to run.

    Alternatively, you can modify MyBarcodes.scala to change the input/output directory names:

    val barcodes = readBarcodes("MyBarcodesInput", "MyBarcodesOutput")
  4. Check Output:

    • The application will print the decoded barcode numbers to the console.
    • Processed black-and-white images (.pbm) will be saved in the ProcessedBarcodes (or specified output) directory.

How it Works

  1. Input: A raw .ppm image.
  2. Convert to Greyscale: Calculates luminance for each pixel.
  3. Convert to Black & White: Uses a quadrant-based adaptive threshold to distinguish black bars from white spaces.
  4. 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.

About

This project is a functional programming application written in Scala 3, designed to process and decode EAN-13 barcodes from raw digital images. The application implements a complete image processing pipeline—from parsing low-level pixel data to algorithmic decoding of barcode digits—without relying on external computer vision libraries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages