-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOCR.h
executable file
·68 lines (57 loc) · 1.79 KB
/
OCR.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*****************************************************************************
* Number Plate Recognition using SVM and Neural Networks
******************************************************************************
* by Ronnie Leon Ochieng, 25th March 2024
******************************************************************************/
#ifndef OCR_h
#define OCR_h
#include <string.h>
#include <vector>
#include "Plate.h"
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/ml.hpp>
using namespace std;
using namespace cv;
#define HORIZONTAL 1
#define VERTICAL 0
class CharSegment{
public:
CharSegment();
CharSegment(Mat i, Rect p);
Mat img;
Rect pos;
};
class OCR{
public:
bool DEBUG;
bool saveSegments;
string filename;
static const int numCharacters;
static const char strCharacters[];
OCR(string trainFile);
OCR();
string run(Plate *input);
int charSize;
Mat preprocessChar(Mat in);
int classify(Mat f);
void train(Mat trainData, Mat trainClasses, int nlayers);
int classifyKnn(Mat f);
void trainKnn(Mat trainSamples, Mat trainClasses, int k);
Mat features(Mat input, int size);
private:
bool trained;
vector<CharSegment> segment(Plate input);
Mat Preprocess(Mat in, int newSize);
Mat getVisualHistogram(Mat *hist, int type);
void drawVisualFeatures(Mat character, Mat hhist, Mat vhist, Mat lowData);
Mat ProjectedHistogram(Mat img, int t);
bool verifySizes(Mat r);
cv::Ptr<cv::ml::ANN_MLP> ann;
cv::Ptr<cv::ml::KNearest> knnClassifier;
int K;
};
#endif