Hand written digits classification using OpenCV

This tutorial is about how to classify handwritten digit from scratch using SVM classifier.

SVM (Support vector machine) classifier – 
SVM (Support vector machine) is an efficient classification method for high dimensional feature vector. We use here SVM implementation of python library sci-kit learn. In sci-kit learn, we can specify the kernel function (here, linear). For more detail  about kernel functions and SVM refer – SVM Kernels and SVM.


Steps involved in handwritten digits classification:
  • Training model:
  1. Download MNIST database of handwritten digits. 
  2. Extract HOG features for each digit in the dataset.
  3. Train a Linear SVM using extracted features and labels in the dataset. 
  4. Save the the classifier trained in step 2 to predict digits.


To download the source code go through link

  •  Testing model:
  1. Load classifier and input image for prediction as shown in figure below:

  2. Apply preprocessing to deal with noises in the image.
  3. Find contours in the preprocessed image.
  4. Draw rectangles around each contour.
  5. Find features for each contours.
  6. Predict digit for each contour using loaded classifier.

To download the source code go through link.

The output image of digits classification for above given input image will be



We can use different classifier instead of SVM e.g.  KNN, Decision tree, Naive bays etc. Moreover, we can use CNN (convolutional neural network )also. For demonstration purpose we used basic classifier. 
That's all for the scope of this post.


No comments:

Post a Comment

Rendering 3D maps on the web using opesource javascript library Cesium

This is a simple 3D viewer using the Cesium javascript library. The example code can be found here . Click on question-mark symbol on upp...