use of org.ddogleg.struct.GrowQueue_F64 in project BoofCV by lessthanoptimal.
the class ShapeFittingOps method averageCircle_I32.
/**
* Computes a circle which has it's center at the mean position of the provided points and radius is equal to the
* average distance of each point from the center. While fast to compute the provided circle is not a best
* fit circle by any reasonable metric, except for special cases.
*
* @param points (Input) Set of unordered points. Not modified.
* @param optional (Optional) Used internally to store the distance of each point from the center. Can be null.
* @param outputStorage (Output/Optional) Storage for results. If null then a new circle instance will be returned.
* @return The found circle fit.
*/
public static FitData<Circle2D_F64> averageCircle_I32(List<Point2D_I32> points, GrowQueue_F64 optional, FitData<Circle2D_F64> outputStorage) {
if (outputStorage == null) {
outputStorage = new FitData<>(new Circle2D_F64());
}
if (optional == null) {
optional = new GrowQueue_F64();
}
Circle2D_F64 circle = outputStorage.shape;
int N = points.size();
// find center of the circle by computing the mean x and y
int sumX = 0, sumY = 0;
for (int i = 0; i < N; i++) {
Point2D_I32 p = points.get(i);
sumX += p.x;
sumY += p.y;
}
optional.reset();
double centerX = circle.center.x = sumX / (double) N;
double centerY = circle.center.y = sumY / (double) N;
double meanR = 0;
for (int i = 0; i < N; i++) {
Point2D_I32 p = points.get(i);
double dx = p.x - centerX;
double dy = p.y - centerY;
double r = Math.sqrt(dx * dx + dy * dy);
optional.push(r);
meanR += r;
}
meanR /= N;
circle.radius = meanR;
// compute radius variance
double variance = 0;
for (int i = 0; i < N; i++) {
double diff = optional.get(i) - meanR;
variance += diff * diff;
}
outputStorage.error = variance / N;
return outputStorage;
}
use of org.ddogleg.struct.GrowQueue_F64 in project BoofCV by lessthanoptimal.
the class CompleteSift method handleDetection.
@Override
protected void handleDetection(ScalePoint p) {
// adjust the image for the down sampling in each octave
double localX = p.x / pixelScaleToInput;
double localY = p.y / pixelScaleToInput;
double localSigma = p.scale / pixelScaleToInput;
// find potential orientations first
orientation.process(localX, localY, localSigma);
// describe each feature
GrowQueue_F64 angles = orientation.getOrientations();
for (int i = 0; i < angles.size; i++) {
BrightFeature feature = features.grow();
feature.white = p.white;
describe.process(localX, localY, localSigma, angles.get(i), feature);
orientations.add(angles.get(i));
locations.add(p);
}
}
use of org.ddogleg.struct.GrowQueue_F64 in project BoofCV by lessthanoptimal.
the class TestShapeFittingOps method averageCircle_F64.
@Test
public void averageCircle_F64() {
List<Point2D_F64> points = new ArrayList<>();
points.add(new Point2D_F64(0, 0));
points.add(new Point2D_F64(10, 0));
points.add(new Point2D_F64(5, 5));
points.add(new Point2D_F64(5, -5));
FitData<Circle2D_F64> found = ShapeFittingOps.averageCircle_F64(points, null, null);
assertEquals(5, found.shape.center.x, 1e-5);
assertEquals(0, found.shape.center.y, 1e-5);
assertEquals(5, found.shape.radius, 1e-5);
assertEquals(0, found.error, 1e-5);
// Pass in storage and see if it fails
found.error = 23;
found.shape.center.x = 3;
GrowQueue_F64 optional = new GrowQueue_F64();
optional.push(4);
ShapeFittingOps.averageCircle_F64(points, optional, found);
assertEquals(5, found.shape.center.x, 1e-5);
assertEquals(0, found.shape.center.y, 1e-5);
assertEquals(5, found.shape.radius, 1e-5);
assertEquals(0, found.error, 1e-5);
// now make it no longer a perfect fit
points.get(0).x = -1;
found = ShapeFittingOps.averageCircle_F64(points, null, null);
assertTrue(found.error > 0);
}
use of org.ddogleg.struct.GrowQueue_F64 in project BoofCV by lessthanoptimal.
the class TestCompleteSift method basic.
/**
* Doesn't do much more than see if it blows up and the expected size of objects is returned
*/
@Test
public void basic() {
GrayF32 image = new GrayF32(300, 290);
GImageMiscOps.fillUniform(image, rand, 0, 200);
CompleteSift alg = createAlg();
alg.process(image);
assertEquals(128, alg.getDescriptorLength());
GrowQueue_F64 orientations = alg.getOrientations();
FastQueue<ScalePoint> locations = alg.getLocations();
FastQueue<BrightFeature> descriptions = alg.getDescriptions();
assertTrue(orientations.size > 10);
assertEquals(orientations.size, locations.size);
assertEquals(orientations.size, descriptions.size);
}
use of org.ddogleg.struct.GrowQueue_F64 in project BoofCV by lessthanoptimal.
the class TestShapeFittingOps method averageCircle_I32.
@Test
public void averageCircle_I32() {
List<Point2D_I32> points = new ArrayList<>();
points.add(new Point2D_I32(0, 0));
points.add(new Point2D_I32(10, 0));
points.add(new Point2D_I32(5, 5));
points.add(new Point2D_I32(5, -5));
FitData<Circle2D_F64> found = ShapeFittingOps.averageCircle_I32(points, null, null);
assertEquals(5, found.shape.center.x, 1e-5);
assertEquals(0, found.shape.center.y, 1e-5);
assertEquals(5, found.shape.radius, 1e-5);
assertEquals(0, found.error, 1e-5);
// Pass in storage and see if it fails
found.error = 23;
found.shape.center.x = 3;
GrowQueue_F64 optional = new GrowQueue_F64();
optional.push(4);
ShapeFittingOps.averageCircle_I32(points, optional, found);
assertEquals(5, found.shape.center.x, 1e-5);
assertEquals(0, found.shape.center.y, 1e-5);
assertEquals(5, found.shape.radius, 1e-5);
assertEquals(0, found.error, 1e-5);
// now make it no longer a perfect fit
points.get(0).x = -1;
found = ShapeFittingOps.averageCircle_I32(points, null, null);
assertTrue(found.error > 0);
}
Aggregations