Fix for CvSVM tutorial documentation (Bugfix #3969)
Description
Associated revisions
Merge pull request #3969 from Dikay900:master_to_2_4
History
Updated by Yida Wang over 10 years ago
In the OpenCV machine learning tutorial: [[http://docs.opencv.org/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.html#explanation]]
Explanation
1.Set up the training data
The training data of this exercise is formed by a set of labeled 2D-points that belong to one of two different classes; one of the classes consists of one point and the other of three points.
float labels4 = {1.0, -1.0, -1.0, -1.0};
float trainingData4[2] = {501, 10}, {255, 10}, {501, 255}, {10, 501};
The function
CvSVM::train that will be used afterwards requires the training data to be stored as Mat objects of floats. Therefore, we create these objects from the arrays defined above: Mat trainingDataMat(3, 2, CV_32FC1, trainingData); Mat labelsMat (3, 1, CV_32FC1, labels);
*The Mat dimension initiating is wrong. *
It should be fixed as:
Mat trainingDataMat(4, 2, CV_32FC1, trainingData);
Mat labelsMat (4, 1, CV_32FC1, labels);