-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathDetectLabel.h
68 lines (56 loc) · 1.8 KB
/
DetectLabel.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
/*
* DetectLabel.h
*
* Created on: May 1, 2014
* Author: chd
*/
#ifndef DETECTLABEL_H_
#define DETECTLABEL_H_
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>
#include <iostream>
#include <math.h>
#include <string.h>
#include <sstream>
using namespace cv;
using namespace std;
const double PI = 3.14159265359;
struct LabelRegion
{
Mat labelImage;
Mat cropImage;
string text;
};
class DetectLabel
{
public:
DetectLabel();
virtual ~DetectLabel();
void binariza(const Mat &InputImage, Mat &binImage);
void findRect(const Mat &binImage, vector<vector<Point> > &mark);
void createLabelMat(const Mat &normalImage, vector<Point> &contour, Mat &labelImage);
void cropLabelImage(const Mat &normalImage, vector<Point> &contour, Mat &cropImage);
bool verifySize(vector<Point> &contour);
void runDetection();
void segment(const Mat &InputImage, vector<Mat> &output);
//
bool showBasicImages;
bool showAllImages;
private:
double angle( Point pt1, Point pt2, Point pt0 );
Point getCenter( vector<Point> points );
float distanceBetweenPoints( Point p1, Point p2 );
vector<Point> sortCorners( vector<Point> square );
void cropImageWithMask(const Mat &img_orig, const Mat &mask, Mat &crop);
void cropImageColor(const Mat &img, const Mat &cropImage, Mat & color_crop);
Scalar regionAvgColor(const Mat &img, const Mat &mask);
bool regionIsCloseToWhite(const Mat &img, const Mat &mask);
vector<Point> setReducedSquareContour( vector<Point> points );
//
Mat blankImage;
vector<vector<Point> > segments;
size_t MaxNumLabels;
int labelCounter;
};
#endif /* DETECTLABEL_H_ */