Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int NUMBER_SUPPORT_VECTORS = 47;
- const int FEATURE_COUNT = 3780;
- const float RHO = -3.0012184359343319e-001;
- string trainedmodel_file_name = "\\trained_svm\\trained_svm_cup.dat";
- float alphas[NUMBER_SUPPORT_VECTORS] = {3.2053527868542001e-003, 1.5553905458136224e-003,
- 2.9452720547068517e-004, 3.2824372327225249e-003,
- 3.2425279604319417e-003, 1.3063714194970718e-003,
- 1.1695732894871692e-003, 9.6702676814445913e-004,
- 2.4027870634888526e-003, 2.3599372023786595e-004,
- 1.1337484230573383e-003, 4.3153771462965907e-003,
- 1.2042344053693243e-003, 1.0541910999459186e-003,
- 5.0809912373503859e-003, 4.7009057917870301e-003,
- 1.9739495612086169e-003, 1.1963889697291360e-003,
- 3.6251557531878976e-003, 3.7693095137171815e-004,
- 2.1398841909665467e-003, 3.1497181481758828e-004,
- 2.0503986996999310e-003, 1.2500314690926857e-003,
- 6.8125903822869422e-004, 5.4317464372580851e-003,
- -4.1390085186689633e-003, -5.2683688057603879e-003,
- -8.6586224845176536e-004, -3.4918318024996256e-004,
- -2.5953444888890871e-003, -3.5922821776841812e-003,
- -1.3102360136554253e-003, -3.6668285159909670e-003,
- -1.1080503083321796e-003, -3.8175695946552997e-003,
- -1.9677580869279982e-003, -4.9864690635346709e-003,
- -2.6933825551601572e-003, -1.8505823303022439e-004,
- -1.5228635958362317e-003, -5.4621914133806356e-004,
- -2.3781817484084377e-003, -3.4432957270396991e-003,
- -4.4566918814856159e-003, -2.6657078377878567e-003,
- -2.6337912586287052e-003
- };
- cout << endl << "Loading and converting svm model...";
- svm.load((char*)trainedmodel_file_name.c_str()); // loading
- //int sv_count = svm.get_support_vector_count();
- int sv_count = NUMBER_SUPPORT_VECTORS;
- int feature_count = FEATURE_COUNT;
- //multiply each row with a constant.
- Mat m(sv_count,feature_count,CV_32FC1);
- for(int r=0; r< sv_count; r++){
- float tmp=0;
- const float* v = svm.get_support_vector(r);
- for(int c=0; c<feature_count; c++){
- tmp = alphas[r] * (*v);
- m.row(r).col(c) = tmp;
- v++;
- }
- }
- //sum each column and flatten to [1 * 3780]
- Mat newMat(1,feature_count,CV_32FC1);
- for(int c=0; c<feature_count; c++){
- float tmp1 =0;
- for(int r=0; r<sv_count; r++){
- tmp1 = tmp1 + m.at<float>(r,c);
- }
- newMat.row(0).col(c) = tmp1;
- }
- //copy from OpenCv:Mat to vector by using pointer.
- const float* p = newMat.ptr<float>(0);
- std::vector<float> finalVector(p, p + newMat.cols);
- //appending -rho
- finalVector.push_back(-RHO);
- cout << endl << "Done loading and converting model...";
- //set the custom detector-vector.
- HOGDescriptor hog;
- hog.setSVMDetector(finalVector);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement