forked from lrse/whycon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircle_detector.h
More file actions
94 lines (72 loc) · 2.44 KB
/
circle_detector.h
File metadata and controls
94 lines (72 loc) · 2.44 KB
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
/*
* Date: 2010
* Author: Tom Krajnik, Matias Nitsche
*/
#ifndef __CIRCLE_DETECTOR_H__
#define __CIRCLE_DETECTOR_H__
#include <opencv2/opencv.hpp>
#include <math.h>
#include <vector>
#define WHYCON_DEFAULT_OUTER_DIAMETER 0.122
#define WHYCON_DEFAULT_INNER_DIAMETER 0.050
#define WHYCON_DEFAULT_DIAMETER_RATIO (WHYCON_DEFAULT_INNER_DIAMETER/WHYCON_DEFAULT_OUTER_DIAMETER)
namespace cv {
class CircleDetector
{
public:
class Circle;
class Context;
CircleDetector(int width, int height, Context* context, float diameter_ratio = WHYCON_DEFAULT_DIAMETER_RATIO);
~CircleDetector();
Circle detect(const cv::Mat& image, const Circle& previous_circle = cv::CircleDetector::Circle());
bool examineCircle(const cv::Mat& image, Circle& circle, int ii, float areaRatio);
void cover_last_detected(cv::Mat& image);
void improveEllipse(const cv::Mat& image, Circle& c);
int get_threshold(void) const;
private:
int minSize, maxSize;
float diameterRatio;
int thresholdStep;
float circularTolerance;
float ratioTolerance;
float centerDistanceToleranceRatio;
int centerDistanceToleranceAbs;
float outerAreaRatio,innerAreaRatio,areasRatio;
int width,height,len,siz;
int threshold, threshold_counter;
void change_threshold(void);
int queueStart,queueEnd,queueOldStart,numSegments;
Context* context;
public:
class Circle {
public:
Circle(void);
float x;
float y;
int size;
int maxy,maxx,miny,minx;
int mean;
int type;
float roundness;
float bwRatio;
bool round;
bool valid;
float m0,m1; // axis dimensions
float v0,v1; // axis (v0,v1) and (v1,-v0)
void write(cv::FileStorage& fs) const;
void read(const cv::FileNode& node);
void draw(cv::Mat& image, const std::string& text = std::string(), cv::Vec3b color = cv::Vec3b(0,255,0), float thickness = 1) const;
};
class Context {
public:
Context(int _width, int _height);
void debug_buffer(const cv::Mat& image, cv::Mat& img);
std::vector<int> buffer, queue;
int width, height;
private:
void cleanup(const Circle& c, bool fast_cleanup);
friend class CircleDetector;
};
};
}
#endif