SVM digital recognition
# Include "stdafx. h "# include <fstream> # include" opencv2/opencv. hpp "# include <vector> using namespace std; using namespace cv; # define SHOW_PROCESS 1 # define ON_STUDY 1 class NumTrainData {public: NumTrainData () {memset (data, 0, sizeof (data); result =-1;} public: float data [64]; int result ;}; vector <NumTrainData> buffer; int featureLen = 64; void swapBuffer (char * buf) {char temp; temp = * (buf); * buf = * (bu F + 3); * (buf + 3) = temp; temp = * (buf + 1); * (buf + 1) = * (buf + 2 ); * (buf + 2) = temp;} void GetROI (Mat & src, Mat & dst) {int left, right, top, bottom; left = src. cols; right = 0; top = src. rows; bottom = 0; // Get valid area for (int I = 0; I <src. rows; I ++) {for (int j = 0; j <src. cols; j ++) {if (src. at <uchar> (I, j)> 0) {if (j <left) left = j; if (j> right) right = j; if (I <top) top = I; if (I> bottom) bottom = I ;}}} // Point center; // center. x = (left + right)/2; // center. y = (top + bottom)/2; int width = right-left; int height = bottom-top; int len = (width
The input is the image numbered 0 to p_num and the corresponding number, nclass. xml is the automatic storage format of the mat type by opencv, and then manually modify the content to find a better one, which is not found yet.