This repository is currently being migrated. It's locked while the migration is in progress.
forked from h3ct0r/fast_ellipse_detector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
151 lines (114 loc) · 3.85 KB
/
common.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
This code is intended for academic use only.
You are free to use and modify the code, at your own risk.
If you use this code, or find it useful, please refer to the paper:
Michele Fornaciari, Andrea Prati, Rita Cucchiara,
A fast and effective ellipse detector for embedded vision applications
Pattern Recognition, Volume 47, Issue 11, November 2014, Pages 3693-3708, ISSN 0031-3203,
http://dx.doi.org/10.1016/j.patcog.2014.05.012.
(http://www.sciencedirect.com/science/article/pii/S0031320314001976)
The comments in the code refer to the abovementioned paper.
If you need further details about the code or the algorithm, please contact me at:
last update: 23/12/2014
*/
#pragma once
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/types_c.h>
#include <opencv2/core/core_c.h>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/core/utility.hpp>
//#include "opencv2\core\internal.hpp"
using namespace std;
using namespace cv;
typedef vector<Point> VP;
typedef vector< VP > VVP;
typedef unsigned int uint;
#define _INFINITY 1024
int inline sgn(float val) {
return (0.f < val) - (val < 0.f);
};
bool inline isInf(float x)
{
union
{
float f;
int i;
} u;
u.f = x;
u.i &= 0x7fffffff;
return !(u.i ^ 0x7f800000);
};
float inline Slope(float x1, float y1, float x2, float y2)
{
//reference slope
float den = float(x2 - x1);
float num = float(y2 - y1);
if(den != 0)
{
return (num / den);
}
else
{
return ((num > 0) ? float(_INFINITY) : float(-_INFINITY));
}
};
void Canny3( InputArray image, OutputArray _edges,
OutputArray _sobel_x, OutputArray _sobel_y,
int apertureSize, bool L2gradient,
bool normalize_for_threshold,
double percent_of_pixels_not_edges,
double threshold_ratio
);
float inline ed2(const Point& A, const Point& B)
{
return float(((B.x - A.x)*(B.x - A.x) + (B.y - A.y)*(B.y - A.y)));
}
float inline ed2f(const Point2f& A, const Point2f& B)
{
return (B.x - A.x)*(B.x - A.x) + (B.y - A.y)*(B.y - A.y);
}
void Labeling(Mat1b& image, vector<vector<Point> >& segments, int iMinLength);
void LabelingRect(Mat1b& image, VVP& segments, int iMinLength, vector<Rect>& bboxes);
void Thinning(Mat1b& imgMask, uchar byF=255, uchar byB=0);
bool SortBottomLeft2TopRight(const Point& lhs, const Point& rhs);
bool SortTopLeft2BottomRight(const Point& lhs, const Point& rhs);
bool SortBottomLeft2TopRight2f(const Point2f& lhs, const Point2f& rhs);
struct Ellipse
{
float _xc;
float _yc;
float _a;
float _b;
float _rad;
float _score;
Ellipse() : _xc(0.f), _yc(0.f), _a(0.f), _b(0.f), _rad(0.f), _score(0.f) {};
Ellipse(float xc, float yc, float a, float b, float rad, float score = 0.f) : _xc(xc), _yc(yc), _a(a), _b(b), _rad(rad), _score(score) {};
Ellipse(const Ellipse& other) : _xc(other._xc), _yc(other._yc), _a(other._a), _b(other._b), _rad(other._rad), _score(other._score) {};
void Draw(Mat& img, const Scalar& color, const int thickness)
{
ellipse(img, Point(cvRound(_xc),cvRound(_yc)), Size(cvRound(_a),cvRound(_b)), _rad * 180.0 / CV_PI, 0.0, 360.0, color, thickness);
};
void Draw(Mat3b& img, const int thickness)
{
Scalar color(0, cvFloor(255.f * _score), 0);
ellipse(img, Point(cvRound(_xc),cvRound(_yc)), Size(cvRound(_a),cvRound(_b)), _rad * 180.0 / CV_PI, 0.0, 360.0, color, thickness);
};
bool operator<(const Ellipse& other) const
{
if(_score == other._score)
{
float lhs_e = _b / _a;
float rhs_e = other._b / other._a;
if(lhs_e == rhs_e)
{
return false;
}
return lhs_e > rhs_e;
}
return _score > other._score;
};
};
float GetMinAnglePI(float alpha, float beta);