Reputation:
Well its a forum for posting the question in which you feel difficulty , well the same thing happen to me so i post the question here , i need to learn the code , understand it , what its doing and what we can do more with it
// Data for visual representation
int width = 512, height = 512;
Mat image = Mat::zeros(height, width, CV_8UC3);
// Set up training data
float labels[4] = {1.0, -1.0, -1.0, -1.0};
Mat labelsMat(3, 1, CV_32FC1, labels);
float trainingData[4][2] = { {501, 10}, {255, 10}, {501, 255}, {10, 501} };
Mat trainingDataMat(3, 2, CV_32FC1, trainingData);
// Set up SVM’s parameters
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::LINEAR;
params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
// Train the SVM
CvSVM SVM;
SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);
Vec3b green(0,255,0), blue (255,0,0);
// Show the decision regions given by the SVM
for (int i = 0; i <2; ++i)
for (int j = 0; j <2; ++j)
{
Mat sampleMat = (Mat_<float>(1,2) << i,j);
float response = SVM.predict(sampleMat);
if (response == 1)
image.at<Vec3b>(j, i) = green;
else if (response == -1)
image.at<Vec3b>(j, i) = blue;
}
I know this code is for training data , but i want to know about its basic things , its basic understanding , which i think i didn't found on opencv documentation like why and when we use CV_8UC3
, and with which things this code is training
Thanks
Upvotes: 1
Views: 873
Reputation: 2588
image
is an empty 3 channel matrix data, i.e. 512x512; R-G-B channels. At the end, this code draws the responses (predictions of SVM) onto that image - image at somewhere = green = (0,255,0). it is done in a for loop to create the lines from pointwise assigning.
the SVM model training is an internal process of this method, in which opencv uses a learning algorithm that can be found only looking at the source code. however, it is declared and described in the documentation that the parameters like svm_type, kernel_type, k_fold, grid, balanced, ... changes the behaviour of the method.
Upvotes: 1