use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestSimilarImagesData method buildAndLookUp.
/**
* Checks all functions to some extent
*/
@Test
void buildAndLookUp() {
var alg = new SimilarImagesData();
List<List<Point2D_F64>> features = new ArrayList<>();
for (int i = 0; i < 4; i++) {
features.add(UtilPoint2D_F64.random(0, 200, 10 + i * 2, rand));
}
alg.add("0", features.get(0));
alg.add("1", features.get(1));
alg.add("2", features.get(2));
alg.add("3", features.get(3));
for (int i = 0; i < 3; i++) {
for (int j = i + 1; j < 3; j++) {
if ((i + j) % 2 == 0)
alg.setRelationship(i + "", j + "", randomAssociated(features.get(i).size(), features.get(j).size(), 8).toList());
else
alg.setRelationship(j + "", i + "", randomAssociated(features.get(j).size(), features.get(i).size(), 8).toList());
}
}
// See if the features were stored correctly
DogArray<Point2D_F64> foundFeatures = new DogArray<>(Point2D_F64::new);
for (int view = 0; view < features.size(); view++) {
List<Point2D_F64> expected = features.get(view);
alg.lookupPixelFeats(view + "", foundFeatures);
assertEquals(expected.size(), foundFeatures.size);
foundFeatures.forIdx((idx, v) -> assertTrue(v.isIdentical(expected.get(idx), 0.0)));
}
// Basic sanity check for similar views
List<String> foundSimilar = new ArrayList<>();
alg.findSimilar("2", (v) -> true, foundSimilar);
assertEquals(2, foundSimilar.size());
alg.findSimilar("3", (v) -> true, foundSimilar);
assertEquals(0, foundSimilar.size());
// Inspect the relationship between one set of views
var foundPairsA = new DogArray<>(AssociatedIndex::new);
var foundPairsB = new DogArray<>(AssociatedIndex::new);
// do it in both directions
alg.findSimilar("2", (v) -> true, foundSimilar);
alg.lookupAssociated("1", foundPairsA);
alg.findSimilar("1", (v) -> true, foundSimilar);
alg.lookupAssociated("2", foundPairsB);
// Other than the swap they should be identical
assertEquals(foundPairsA.size, foundPairsB.size);
for (int i = 0; i < foundPairsB.size; i++) {
AssociatedIndex a = foundPairsA.get(i);
AssociatedIndex b = foundPairsB.get(i);
assertEquals(a.src, b.dst);
assertEquals(a.dst, b.src);
}
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestSimilarImagesSceneRecognition method simpleAllTogether.
/**
* Simple scenario which exercises everything all at once
*/
@Test
void simpleAllTogether() {
var config = new ConfigSimilarImagesSceneRecognition();
// Needed to do some hacking since the defaults assume there are a bunch of image features
config.minimumSimilar.setRelative(0.1, 0.0);
config.recognizeNister2006.minimumDepthFromRoot = 0;
SimilarImagesSceneRecognition<GrayU8, TupleDesc_F32> alg = FactorySceneReconstruction.createSimilarImages(config, ImageType.SB_U8);
alg.detector = new HelperDetector();
for (int i = 0; i < 5; i++) {
alg.addImage("" + i, new GrayU8(50, 10));
}
alg.fixate();
// For all these other functions just check to see if something got populated
DogArray_I32 words = new DogArray_I32();
alg.lookupImageWords("3", words);
assertTrue(words.size > 0);
var features = new DogArray<>(Point2D_F64::new);
alg.lookupPixelFeats("1", features);
assertTrue(features.size > 0);
// Look up similar images. All but the query view should be similar
List<String> similarImages = new ArrayList<>();
alg.findSimilar("0", (a) -> true, similarImages);
assertTrue(similarImages.size() > 0);
var pairs = new DogArray<>(AssociatedIndex::new);
alg.lookupAssociated(similarImages.get(0), pairs);
assertTrue(features.size > 0);
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestVisualDepthOps method depthTo3D_with_rgb.
@Test
void depthTo3D_with_rgb() {
GrayU16 depth = new GrayU16(width, height);
depth.set(200, 80, 3400);
depth.set(600, 420, 50);
Planar<GrayU8> rgb = new Planar<>(GrayU8.class, width, height, 3);
GImageMiscOps.fillUniform(rgb, rand, 0, 200);
DogArray<Point3D_F64> pts = new DogArray<>(Point3D_F64::new);
DogArray<int[]> color = new DogArray<>(() -> new int[3]);
VisualDepthOps.depthTo3D(param, rgb, depth, pts, color);
assertEquals(2, pts.size());
assertEquals(2, color.size());
assertEquals(0, compute(200, 80, 3400).distance(pts.get(0)), 1e-8);
assertEquals(0, compute(600, 420, 50).distance(pts.get(1)), 1e-8);
color(200, 80, rgb, color.get(0));
color(600, 420, rgb, color.get(1));
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestMicroQrCodeDecoderImage method transposed.
/**
* Transposes the input image and sees if it can still be decoded by default
*/
@Test
void transposed() {
MicroQrCode qr = new MicroQrCodeEncoder().addAutomatic("123LK").fixate();
GrayU8 image = render(qr);
GrayU8 imageTransposed = image.createSameShape();
ImageMiscOps.transpose(image, imageTransposed);
var patterns = new DogArray<>(PositionPatternNode::new);
addPositionPattern(qr, patterns);
var alg = new MicroQrCodeDecoderImage<>(null, "", GrayU8.class);
alg.process(patterns.toList(), imageTransposed);
assertEquals(1, alg.found.size());
assertEquals(0, alg.failures.size());
assertEquals("123LK", alg.found.get(0).message);
// It should fail now since it won't consider a transposed marker
alg.considerTransposed = false;
alg.process(patterns.toList(), imageTransposed);
assertEquals(0, alg.found.size());
assertEquals(1, alg.failures.size());
}
use of org.ddogleg.struct.DogArray in project BoofCV by lessthanoptimal.
the class TestMicroQrCodeDecoderImage method simple_all_configs.
/**
* Render then decode images with all possible versions, masks, and error correction levels.
*/
@Test
void simple_all_configs() {
String message = "01234";
var engine = new FiducialImageEngine();
engine.configure(0, 100);
var generator = new MicroQrCodeGenerator();
generator.markerWidth = 100;
generator.setRender(engine);
var alg = new MicroQrCodeDecoderImage<>(null, "", GrayU8.class);
var patterns = new DogArray<>(PositionPatternNode::new);
for (int version = 1; version <= 4; version++) {
ErrorLevel[] errors = MicroQrCode.allowedErrorCorrection(version);
for (ErrorLevel error : errors) {
// Generate the QR code
var encoder = new MicroQrCodeEncoder();
// encoder.setVerbose(System.out, null);
MicroQrCode qr = encoder.setVersion(version).setError(error).setMask(M00).addNumeric(message).fixate();
generator.render(qr);
// Set up the "detected" position pattern
patterns.reset();
PositionPatternNode pp = patterns.grow();
pp.square = qr.pp;
pp.grayThreshold = (double) (engine.getWhite() / 2);
// ShowImages.showWindow(engine.getGray(), "Title");
// BoofMiscOps.sleep(10_000);
// Process the image
// alg.decoder.setVerbose(System.out, null);
alg.process(patterns.toList(), engine.getGray());
// Check results
assertEquals(1, alg.found.size());
assertEquals(0, alg.failures.size());
assertEquals(version, alg.found.get(0).version);
assertEquals(message, alg.found.get(0).message);
}
}
}
Aggregations