-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclassifierinterface.cpp
More file actions
37 lines (33 loc) · 888 Bytes
/
classifierinterface.cpp
File metadata and controls
37 lines (33 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "classifierinterface.h"
ClassifierInterface::ClassifierInterface() {
testSample = cv::Mat::zeros(1,2,CV_32FC1);
isTrainedFlag = false;
}
void ClassifierInterface::loadData(const std::vector<cv::Point> &data, const std::vector<int> &labels)
{
cv::Mat(data).copyTo(pData);
cv::Mat(labels).copyTo(lData);
pData = pData.reshape(1, pData.rows);
pData.convertTo(pData, CV_32FC1);
}
bool ClassifierInterface::isTrained()
{
return isTrainedFlag;
}
float ClassifierInterface::calcSelfError()
{
int numErr = 0;
float x,y;
for(int ii =0; ii<pData.rows; ii++) {
x = pData.at<float>(ii,0);
y = pData.at<float>(ii,1);
if(classify(x, y) != lData.at<int>(ii)) {
numErr++;
}
}
if(pData.rows>0) {
return (float)numErr/(float)pData.rows;
} else {
return -1.f;
}
}