use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class CompareTwoImagePanel method findBestPoints.
private void findBestPoints(int x, int y, List<Point2D_F64> pts, List<Integer> selected) {
double bestDist = clickDistance * clickDistance;
GrowQueue_I32 bestIndexes = new GrowQueue_I32(20);
for (int i = 0; i < pts.size(); i++) {
if (!isValidPoint(i))
continue;
Point2D_F64 p = pts.get(i);
double d = UtilPoint2D_F64.distanceSq(p.x, p.y, x, y);
if (d < bestDist) {
bestDist = d;
bestIndexes.reset();
bestIndexes.add(i);
} else if (Math.abs(d - bestDist) < 0.01) {
bestIndexes.add(i);
}
}
if (bestIndexes.size() > 0) {
int indexRight = bestIndexes.get(0);
}
for (int i = 0; i < bestIndexes.size(); i++) {
selected.add(bestIndexes.get(i));
}
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestAssociateNearestNeighbor method various.
/**
* Several tests combined into one
*/
@Test
public void various() {
Dummy<Integer> nn = new Dummy<>();
// src = assoc[i] where src is the index of the source feature and i is the index of the dst feature
nn.assoc = new int[] { 2, 0, 1, -1, 4, -1, -1, 2, 2, 1 };
AssociateNearestNeighbor<TupleDesc_F64> alg = new AssociateNearestNeighbor<>(nn, 10);
FastQueue<TupleDesc_F64> src = new FastQueue<>(10, TupleDesc_F64.class, false);
FastQueue<TupleDesc_F64> dst = new FastQueue<>(10, TupleDesc_F64.class, false);
for (int i = 0; i < 5; i++) {
src.add(new TupleDesc_F64(10));
}
for (int i = 0; i < 10; i++) {
dst.add(new TupleDesc_F64(10));
}
alg.setSource(src);
alg.setDestination(dst);
alg.associate();
FastQueue<AssociatedIndex> matches = alg.getMatches();
assertTrue(nn.pointDimension == 10);
assertEquals(7, matches.size);
for (int i = 0, count = 0; i < nn.assoc.length; i++) {
if (nn.assoc[i] != -1) {
int source = nn.assoc[i];
assertEquals(source, matches.get(count).src);
assertEquals(i, matches.get(count).dst);
count++;
}
}
GrowQueue_I32 unassoc = alg.getUnassociatedSource();
assertEquals(1, unassoc.size);
assertEquals(3, unassoc.get(0));
unassoc = alg.getUnassociatedDestination();
assertEquals(3, unassoc.size);
assertEquals(3, unassoc.get(0));
assertEquals(5, unassoc.get(1));
assertEquals(6, unassoc.get(2));
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class BinaryThinning method apply.
/**
* Applies the thinning algorithm. Runs for the specified number of loops or until no change is detected.
*
* @param binary Input binary image which is to be thinned. This is modified
* @param maxLoops Maximum number of thinning loops. Set to -1 to run until the image is no longer modified.
*/
public void apply(GrayU8 binary, int maxLoops) {
this.binary = binary;
inputBorder.setImage(binary);
ones0.reset();
zerosOut.reset();
findOnePixels(ones0);
for (int loop = 0; (loop < maxLoops || maxLoops == -1) && ones0.size > 0; loop++) {
boolean changed = false;
// do one cycle through all the masks
for (int i = 0; i < masks.length; i++) {
zerosOut.reset();
ones1.reset();
masks[i].apply(ones0, ones1, zerosOut);
changed |= ones0.size != ones1.size;
// mark all the pixels that need to be set to 0 as 0
for (int j = 0; j < zerosOut.size(); j++) {
binary.data[zerosOut.get(j)] = 0;
}
// swap the lists
GrowQueue_I32 tmp = ones0;
ones0 = ones1;
ones1 = tmp;
}
if (!changed)
break;
}
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class TestBinaryThinning method findBlackPixels.
private void findBlackPixels(GrayU8 img) {
GrowQueue_I32 marked = new GrowQueue_I32();
BinaryThinning alg = new BinaryThinning();
alg.binary = img;
alg.findOnePixels(marked);
assertEquals(2, marked.size());
assertEquals(img.getIndex(4, 1), marked.get(0));
assertEquals(img.getIndex(2, 3), marked.get(1));
}
use of org.ddogleg.struct.GrowQueue_I32 in project BoofCV by lessthanoptimal.
the class SplitMergeLineFitLoop method mergeSegments.
/**
* Merges lines together if the common corner is close to a common line
* @return true the list being changed
*/
protected boolean mergeSegments() {
// See if merging will cause a degenerate case
if (splits.size() <= 3)
return false;
boolean change = false;
work.reset();
for (int i = 0; i < splits.size; i++) {
int start = splits.data[i];
int end = splits.data[(i + 2) % splits.size];
if (selectSplitOffset(start, circularDistance(start, end)) < 0) {
// merge the two lines by not adding it
change = true;
} else {
work.add(splits.data[(i + 1) % splits.size]);
}
}
// swap the two lists
GrowQueue_I32 tmp = work;
work = splits;
splits = tmp;
return change;
}
Aggregations