GithubHelp home page GithubHelp logo

linecode / handwriting-number-classification Goto Github PK

View Code? Open in Web Editor NEW

This project forked from markmohr/handwriting-number-classification

0.0 2.0 0.0 2.61 MB

An computer vision project, based on cimg library and svm training, to classify handwriting number.

C++ 99.88% C 0.12%

handwriting-number-classification's Introduction

Handwriting Number Classification

An computer vision project, based on cimg library and svm training, to classify handwriting number.

1. Project Requirement

1.1 Input

  • A photo in which an A4 paper is placed on the desk, with some handwriting numbers on

1.2 Output

  • A string of the numbers written on the paper, like "70026548853"

1.3 Intermediate Processes

  • Modify the paper in the photo into a standard A4 paper
  • Implement the segmentation of the numbers, dividing them into single number
  • Use Adaboost or SVM to train a classifier of the handwriting numbers
  • Classify the handwriting numbers with the trained classifier

2. Coding Environment & 3rd Party Library


3. Implementation Procedure

  1. Find the 4 vertices of the paper

  2. Modify the paper into a standard A4 paper

  3. Segmentation of the numbers in order:

    • Convert into binary image
    • Use vertical histogram to divide the source image into sub-image (each sub-image contains a line of numbers)
    • Use horizontal histogram to divide the line-sub-image into several row-sub-images
    • Foreach sub-image, implement dilation to thicken the number (and join the broken ones)
    • Foreach sub-image, use connected-component_labeling algorithm to divide the single number: https://en.wikipedia.org/wiki/Connected-component_labeling
    • Foreach sub-image, save all single number images and a list of their name in .txt
  4. Use libsvm to train model and test, and predict the number finally

    • Data prepairing:
    • Model training:
      • extract the HOG features of each image and construct them into svm format (in **.txt)
      • Scale the features(in **.txt) with svm-scale.exe (search the windows/ folder)
      • Train the model with svm-train.exe, and get **.model
      • (Optional) Test the data with svm-predict.exe and see the accuracy (modify the training parameter to get the highest accuracy)
    • Number predicting:
      • read the number images you segmented just now and do prediction with the trained model

4. Result Screenshots

  • 4 vertices of the paper & A4 paper modification

Image text

  • Segmentation of the numbers:

    • Binary image with dilation & Divided Image & Circled single number

    Image text Image text

    • Divided into single numbers in order as well as an image list in .txt

    Image text

    • Prediction:

    Image text


5. Some key points

5.1 Broken numbers joining

  • Comparison (Before joining & After joining)

    Image text

  • Implements : use the filters below when doing the dilation during the number segmentation Image text (filterA) Image text (filterB)

    • Do the dilation with filterA twice at first, and then filterB once.
    • filterB means: when at the white pixel, search up/down one pixel and left/right one pixel. If meeting a black pixel, set the current position to black.
    • filterA means: when at the white pixel, search up/down one pixel and left/right two pixel. Count the blacks with the coefficient, -1 or 1 (-1 means subtract one black when meeting a black at left/right side). At last, only if the blacks more than 0, set the current position to black.
    • Obviously, filterB is to thicken the number in all directions, leading to the cons that the holes in number 0, 6, 8, 9 with be filled. So I propose another simple but useful filter, the filterA, to deal with such problem. It can be seen that the intensity of a white pixel is much relevant to its horizontal neighbors, which prevent hole filling to some extent. Luckily it works well in my experiments.

6. Code and Algorithm Explanation

  1. Segmentation of the numbers & Broken numbers joining :

    http://blog.csdn.net/qq_33000225/article/details/73123880 (Chinese version)

  2. Prediction: (Waiting......)


7. Problems left

  1. Some numbers are connected to each other and are segmented together into one image......
  2. From the predict result above, we see that most of the 7s and 9s are classified into 1......

handwriting-number-classification's People

Contributors

markmohr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.