View on GitHub

Handwritten Math Solver

by Atharva K

Download this project as a .zip file Download this project as a tar.gz file

Handwritten Equation Recognition using HOG \& SVM

This repository contains a project for recognizing handwritten numerical equations by first segmenting images into meaningful regions (i.e., individual characters) and then classifying them using Histogram of Oriented Gradients (HOG) for feature extraction and a Polynomial Support Vector Machine (SVM) for classification.


Table of Contents


Introduction

Handwritten equation recognition poses challenges in dealing with varied handwriting styles and segmentation of dense, grid-like characters. This project tackles these challenges by:

The switch from traditional SIFT to HOG was driven by the need for a fixed-length, efficient descriptor that aligns with the smoothly varying structure of handwritten characters.


Project Overview

The project workflow involves:

A modular implementation in PyTorch enables running the model on both CPU and GPU, and it can be easily extended for real-time recognition tasks.


Features

Below is a comparison of different HOG configurations explored during development:

Configuration Orientations Pixels per Cell Cells per Block Performance
Best Configuration 12 4 x 4 3 x 3 Optimal performance
Generalized Approach 9 8 x 8 2 x 2 Underperformed
Overfitting Setup 16 4 x 4 3 x 3 Overfitting observed

Methodology

Data Processing

HOG Feature Extraction

SVM Classification


Clone the Repository:

git clone https://github.com/Atharvack/SVM_HOG.git

Project Structure

.
├── code
│   ├── model.py           # Contains the PolynomialSVM and HingeLoss definitions
│   ├── preprocessing.py   # Functions for image preprocessing and HOG feature extraction
│   └── main.py            # Main testing workflow and integration script
├── saved_features_2
│   └── hog_features.pkl   # Precomputed HOG features and class labels
├── best_svm_model_poly_2.pth  # Trained SVM model weights
└── README.md              # This file

Jupyter Notebooks

Predictions can be seen in the last block!

License

Distributed under the MIT License. See LICENSE for more information.