Learning about JNI in Android (ii) Some understanding of Jni method names, data types, and method signatures

Source: Internet
Author: User

working with feature data and code


This address: http://blog.csdn.net/caroline_wendy/article/details/26240241


Input file:

1. The normalized signature file , the 1th column is the label, the remaining columns are features;

2. Characteristic maximum vector file: The first 3 columns are the standard format and the remaining columns are the maximum values;

Output file:

1. The characteristic format conforming to SVM training data ;

2. The standard XML file that the mat stores ;


Code:

/* Processing the feature data program by C.l.wang data format: Feature data: The 1th column is the label, the remaining columns are the characteristics; Maximum data: The first 3 columns are the standard format, the remaining columns are the maximum values, the conversion to: SVM General format, training SVM model; Convert to OpenCV matrix storage mat;*/#include <iostream> #include <string> #include <vector> #include <fstream > #include <opencv.hpp>/* conversion SVM data Format */void transformsvmdata (const std::string _inputfilename,/* Input data file */const std::string _outputfilename,/* output data file */const int _rows,/* Number of rows, custom */const int _cols/* Number of columns, self-set */) {//const int rows (800);//Number of rows , set//const int cols (104); Number of columns, set Cv::mat Traindata = Cv::mat (_rows, _cols, CV_64FC1);/* Read file */std::ifstream file_data (_inputfilename); if (file_ Data.fail ()) {Std::cerr << "Failed to open the file!" << Std::endl;return;} for (int i=0, i<_rows; ++i) {for (int j=0; j<_cols; ++j) {file_data >> traindata.at<double> (I,J);}} File_data.close ();/* Convert the SVM format */std::ofstream svmdata (_outputfilename); for (int i=0; i<_rows; i++) {svmdata << Traindata.at<double> (i, 0) << ""; for (int j=1; j<_cols-1; J + +) {//less than 1 linesSvmdata << J << ":" << traindata.at<double> (i, J) << "";} Svmdata << _cols-1 << ":" << traindata.at<double> (i,_cols-1) << Std::endl; The last line does not add a space}svmdata.close (); return;} /* Convert normalized vector */void transformnormxml (const std::string _MAXFILENAME,CONST int _cols/* column number, self-set */) {const int rows = 1;//const in t cols = 104; Number of columns, custom/* Read file */cv::mat Normmat = Cv::mat (rows, _cols, CV_64FC1); Std::ifstream maxData (_maxfilename, Std::ifstream::in if (Maxdata.fail ()) {Std::cerr << "Failed to open the file!" << Std::endl;return;} for (int i=0, i<rows; ++i) {for (int j=0; j<_cols; ++j) {maxData >> normmat.at<double> (I,J);}} Maxdata.close ();/* Write Xml*/cv::filestorage Filexml ("Normalization.xml", cv::filestorage::write); fileXml << " Normalization "<< Normmat; Label Filexml.release (); return;} int main () {const std::string input_file_name = "Violence_norm_matlab.txt";/* input data file */const std::string output_file_ Name = "Violence_norm_svm.txt "; /* Output data file */const int rows = 843; /* Enter the number of file lines, set */const int cols = 102; /* Enter the number of file columns, set the */transformsvmdata (Input_file_name, output_file_name, rows, cols); Const std::string Max_file_name = " Violence_max_matlab.txt "; Transformnormxml (Max_file_name, cols+2); and previous standard std::cout << "program over!" << Std::endl;return 0;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.