A SVM-based OpenCV Project for recognizing handwritten digits in C++.
This project uses the MNIST Database of Handwritten Digits.
-
Visit the official OpenCV website and install OpenCV.
-
Clone this Repository (SVM-Recognition).
-
Download MNIST Data and put the data files under
SVM-Recognition/data
.
t10k-images.idx3-ubyte t10k-labels.idx1-ubyte train-images.idx3-ubyte train-labels.idx1-ubyte
- Input the following command in your command prompt to run.
NOTE: You need to run every command of this recipe in the SVM-Recognition
root path:
cd build cmake ..
To train a SVM model, run the following command.
NOTE: You need to run every command of this recipe in the SVM-Recognition
root path:
cd build make train cd train ./train
The program will train a SVM model by the training data train-images.idx3-ubyte
and train-labels.idx1-ubyte
, and will calculate the accuracy by t10k-images.idx3-ubyte
and t10k-labels.idx1-ubyte
.
To run predictions of an image of a digit, make sure the image conforms to the format in MNIST database, i.e., a 28*28 bmp image
. The filename of the image does not matter. So long as the image is in the right format and is a .bmp
file, the program will run a prediction.
- Extracted MNIST Image by 3omar-mostafa: Github Repo
To start, put the image under SVM-Recognition/data
. The program will only run predictions for the first occurrence of a .bmp file, so don't put more than one image.
NOTE: You need to run every command of this recipe in the SVM-Recognition
root path:
cd build make recognition cd recognition ./recognition
The program will then print the prediction of the image.
A pre-trained model is included: /SVM-Recognition/build/mnist_svm.xml
with accuracy 97.54%.
-
K Nearest Neighbors (KNN): Fundamentals, OpenCV Example
-
Support Vector Machine (SVM): Fundamentals, OpenCV Example
-
K-means clustering (Kmeans): Fundamentals, OpenCV Example
-
Decision Trees: Fundamentals, OpenCV Example
-
Deep Neural Network (DNN): Fundamentals, OpenCV Example