24 #include <fvmodels/shape/accumulators/fc_accum.h> 36 const float FittedCircle::TOO_SMALL_DELTA = 1.0e-3f;
43 FittedCircle::FittedCircle(
void)
49 FittedCircle::~FittedCircle(
void)
55 FittedCircle::reset(
void)
58 for (
int i=0; i<2; ++i)
60 circle_matrices[i].A00 = circle_matrices[i].A01 = circle_matrices[i].A02 = 0.0f;
61 circle_matrices[i].A10 = circle_matrices[i].A11 = circle_matrices[i].A12 = 0.0f;
62 circle_matrices[i].A20 = circle_matrices[i].A21 = circle_matrices[i].A22 = 0.0f;
63 circle_matrices[i].b0 = circle_matrices[i].b1 = circle_matrices[i].b2 = 0.0f;
77 int next_circle = 1 - current_circle;
80 circle_matrices[next_circle].A00 += 4 * pt.
x * pt.
x;
81 circle_matrices[next_circle].A01 += 4 * pt.
x * pt.
y;
82 circle_matrices[next_circle].A02 += 2 * pt.
x;
84 circle_matrices[next_circle].A10 += 4 * pt.
y * pt.
x;
85 circle_matrices[next_circle].A11 += 4 * pt.
y * pt.
y;
86 circle_matrices[next_circle].A12 += 2 * pt.
y;
88 circle_matrices[next_circle].A20 += 2 * pt.
x;
89 circle_matrices[next_circle].A21 += 2 * pt.
y;
90 circle_matrices[next_circle].A22 += 1;
92 float r2 = pt.
x * pt.
x + pt.
y * pt.
y;
93 circle_matrices[next_circle].b0 += 2 * r2 * pt.
x;
94 circle_matrices[next_circle].b1 += 2 * r2 * pt.
y;
95 circle_matrices[next_circle].b2 += r2;
99 Circle* p = fitCircle(&circle_matrices[next_circle]);
105 dist = fabs(sqrt(dx*dx+dy*dy)-r);
122 int next_circle = 1 - current_circle;
125 circle_matrices[next_circle].A00 -= 4 * pt.
x * pt.
x;
126 circle_matrices[next_circle].A01 -= 4 * pt.
x * pt.
y;
127 circle_matrices[next_circle].A02 -= 2 * pt.
x;
129 circle_matrices[next_circle].A10 -= 4 * pt.
y * pt.
x;
130 circle_matrices[next_circle].A11 -= 4 * pt.
y * pt.
y;
131 circle_matrices[next_circle].A12 -= 2 * pt.
y;
133 circle_matrices[next_circle].A20 -= 2 * pt.
x;
134 circle_matrices[next_circle].A21 -= 2 * pt.
y;
135 circle_matrices[next_circle].A22 -= 1;
137 float r2 = pt.
x * pt.
x + pt.
y * pt.
y;
138 circle_matrices[next_circle].b0 -= 2 * r2 * pt.
x;
139 circle_matrices[next_circle].b1 -= 2 * r2 * pt.
y;
140 circle_matrices[next_circle].b2 -= r2;
150 FittedCircle::distanceTo(
const upoint_t& pt,
bool current)
152 int id = current?current_circle:(1-current_circle);
153 Circle* p = fitCircle(&circle_matrices[
id]);
158 return fabs(sqrt(dx*dx+dy*dy)-p->
radius);
170 FittedCircle::commit(
void)
174 current_circle = 1 - current_circle;
184 FittedCircle::getCount(
void)
const 194 FittedCircle::getCircle(
void)
const 196 return fitCircle(const_cast<circle_matrix*>(&circle_matrices[current_circle]));
205 FittedCircle::fitCircle(circle_matrix* p)
const 209 float delta = + p->A00 * p->A11 * p->A22 + p->A01 * p->A12 * p->A20 + p->A02 * p->A10 * p->A21
210 - p->A00 * p->A12 * p->A21 - p->A01 * p->A10 * p->A22 - p->A02 * p->A11 * p->A20;
211 if (delta > -TOO_SMALL_DELTA && delta < TOO_SMALL_DELTA)
214 printf(
"\t%f\t%f\t%f\n", p->A00, p->A01, p->A02);
215 printf(
"\t%f\t%f\t%f\n", p->A10, p->A11, p->A12);
216 printf(
"\t%f\t%f\t%f\n", p->A20, p->A21, p->A22);
218 printf(
"\t%f\t%f\t%f\n", p->b0, p->b1, p->b2);
219 printf(
"Delta too small: %e\n", delta);
224 c.
center.
x = (float)( ( + p->b0 * p->A11 * p->A22 + p->A01 * p->A12 * p->b2 + p->A02 * p->b1 * p->A21
225 - p->b0 * p->A12 * p->A21 - p->A01 * p->b1 * p->A22 - p->A02 * p->A11 * p->b2 ) / delta);
226 c.
center.
y = (float)( ( + p->A00 * p->b1 * p->A22 + p->b0 * p->A12 * p->A20 + p->A02 * p->A10 * p->b2
227 - p->A00 * p->A12 * p->b2 - p->b0 * p->A10 * p->A22 - p->A02 * p->b1 * p->A20 ) / delta);
228 c.
radius = (float)sqrt((+ p->A00 * p->A11 * p->b2 + p->A01 * p->b1 * p->A20 + p->b0 * p->A10 * p->A21
229 - p->A00 * p->b1 * p->A21 - p->A01 * p->A10 * p->b2 - p->b0 * p->A11 * p->A20 ) / delta
Fawkes library namespace.
unsigned int y
y coordinate
unsigned int x
x coordinate
Point with cartesian coordinates as unsigned integers.
int count
Number of pixels.
center_in_roi_t center
Center of object in ROI.
float radius
Radius of object.