use of org.ddogleg.struct.DogArray_F64 in project BoofCV by lessthanoptimal.
the class WrapAssociateGreedy method associate.
@Override
public void associate() {
if (listSrc == null)
throw new IllegalArgumentException("source features not specified");
if (listDst == null)
throw new IllegalArgumentException("destination features not specified");
unassocSrc.reset();
alg.associate(listSrc, listDst);
DogArray_I32 pairs = alg.getPairs();
DogArray_F64 score = alg.getFitQuality();
matches.reset();
for (int i = 0; i < listSrc.size; i++) {
int dst = pairs.data[i];
if (dst >= 0)
matches.grow().setTo(i, dst, score.data[i]);
else
unassocSrc.add(i);
}
}
use of org.ddogleg.struct.DogArray_F64 in project BoofCV by lessthanoptimal.
the class CompleteSift_MT method describeDetections.
@Override
protected void describeDetections(List<SiftDetector.SiftPoint> detections) {
// if there are very few features don't spawn threads
if (minimumDetectionsThread >= detections.size())
super.describeDetections(detections);
BoofConcurrency.loopBlocks(0, detections.size(), helpers, (helper, idx0, idx1) -> {
final OrientationHistogramSift<GrayF32> orientation = helper.orientation;
final DescribePointSift<GrayF32> describe = helper.describe;
helper.reset();
for (int detIdx = idx0; detIdx < idx1; detIdx++) {
SiftDetector.SiftPoint p = detections.get(detIdx);
// Gradient image is offset by one
GrayF32 derivX = gradient.getDerivX(p.octaveIdx, (byte) (p.scaleIdx - 1));
GrayF32 derivY = gradient.getDerivY(p.octaveIdx, (byte) (p.scaleIdx - 1));
orientation.setImageGradient(derivX, derivY);
describe.setImageGradient(derivX, derivY);
double pixelScaleToInput = scaleSpace.pixelScaleCurrentToInput(p.octaveIdx);
// adjust the image for the down sampling in each octave
double localX = p.pixel.x / pixelScaleToInput;
double localY = p.pixel.y / pixelScaleToInput;
double localSigma = p.scale / pixelScaleToInput;
// find potential orientations first
orientation.process(localX, localY, localSigma);
// describe each feature
DogArray_F64 angles = orientation.getOrientations();
for (int angleIdx = 0; angleIdx < angles.size; angleIdx++) {
describe.process(localX, localY, localSigma, angles.get(angleIdx), helper.features.grow());
helper.orientations.add(angles.get(angleIdx));
helper.locations.add(p);
}
}
});
// Stitch results from all the threads back together
for (int i = 0; i < helpers.size(); i++) {
ThreadHelper helper = helpers.get(i);
locations.addAll(helper.locations);
combinedFeatures.addAll(helper.features);
orientations.addAll(helper.orientations);
}
}
use of org.ddogleg.struct.DogArray_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, DogArray_F64 optional, @Nullable FitData<Circle2D_F64> outputStorage) {
if (outputStorage == null) {
outputStorage = new FitData<>(new Circle2D_F64());
}
if (optional == null) {
optional = new DogArray_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.DogArray_F64 in project BoofCV by lessthanoptimal.
the class FiducialDetection method parseImage.
void parseImage(int index, String[] args) {
boolean robust = true;
List<String> paths = new ArrayList<>();
DogArray_F64 sizes = new DogArray_F64();
double borderWidth = 0.25;
for (; index < args.length; index++) {
String arg = args[index];
if (!arg.startsWith("--")) {
throw new RuntimeException("Expected flags for image fiducial");
}
splitFlag(arg);
if (flagName.compareToIgnoreCase("Robust") == 0) {
robust = Boolean.parseBoolean(parameters);
} else if (flagName.compareToIgnoreCase("Image") == 0) {
String[] words = parameters.split(":");
if (words.length != 2)
throw new RuntimeException("Expected two for width and image path");
sizes.add(Double.parseDouble(words[0]));
paths.add(words[1]);
} else if (flagName.compareToIgnoreCase("Border") == 0) {
borderWidth = Double.parseDouble(parameters);
} else {
throw new RuntimeException("Unknown image option " + flagName);
}
}
if (paths.isEmpty())
throw new RuntimeException("Need to specify patterns");
System.out.println("image: robust = " + robust + " total patterns = " + paths.size() + " border = " + borderWidth);
ConfigFiducialImage config = new ConfigFiducialImage();
config.borderWidthFraction = borderWidth;
ConfigThreshold configThreshold;
if (robust)
configThreshold = ConfigThreshold.local(ThresholdType.LOCAL_MEAN, 21);
else
configThreshold = ConfigThreshold.fixed(DEFAULT_THRESHOLD);
SquareImage_to_FiducialDetector<GrayU8> detector = FactoryFiducial.squareImage(config, configThreshold, GrayU8.class);
for (int i = 0; i < paths.size(); i++) {
BufferedImage buffered = UtilImageIO.loadImage(paths.get(i));
if (buffered == null)
throw new RuntimeException("Can't find pattern " + paths.get(i));
GrayU8 pattern = new GrayU8(buffered.getWidth(), buffered.getHeight());
ConvertBufferedImage.convertFrom(buffered, pattern);
detector.addPatternImage(pattern, 125, sizes.get(i));
}
this.detector = detector;
}
use of org.ddogleg.struct.DogArray_F64 in project BoofCV by lessthanoptimal.
the class TestShapeFittingOps method averageCircle_I32.
@Test
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;
DogArray_F64 optional = new DogArray_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