use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ChecksGenericPointsToPolyline method checkMinVertexes_sequence.
/**
* Checks to see if this feature can be changed and is enforced
*/
@Test
void checkMinVertexes_sequence() {
PointsToPolyline alg = createAlg(false);
alg.setConvex(false);
alg.setMinimumSides(10);
List<Point2D_I32> contour = line(0, 0, 30, 0);
contour.addAll(line(30, 0, 30, 10));
contour.addAll(line(30, 10, 20, 10));
contour.addAll(line(20, 10, 20, 30));
contour.addAll(line(20, 30, 0, 30));
DogArray_I32 found = new DogArray_I32();
if (alg.process(contour, found)) {
assertEquals(9, found.size);
}
alg.setMinimumSides(3);
assertTrue(alg.process(contour, found));
check(found, 0, 30, 40, 50, 70, 89);
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class GenericAssociateGreedyChecks method ratioTest.
@Test
void ratioTest() {
// perfect match is a special case
// [2] is a very good fit and should pass the ratio test, but is not zero
DogArray<TupleDesc_F64> a = createData(1, 2, 3, 10);
DogArray<TupleDesc_F64> b = createData(1, 2, 3.01, 4);
AssociateGreedyBase<TupleDesc_F64> alg = createAlgorithm();
// ratio test is turned off by default
associate(alg, a, b);
DogArray_I32 pairs = alg.getPairs();
for (int i = 0; i < 4; i++) {
assertEquals(i, pairs.get(i));
}
// set it so that 4 will be rejected
alg.setRatioTest(0.1);
associate(alg, a, b);
pairs = alg.getPairs();
assertEquals(0, pairs.get(0));
assertEquals(1, pairs.get(1));
assertEquals(2, pairs.get(2));
assertEquals(-1, pairs.get(3));
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ChecksGenericPointsToPolyline method checkIsConvex.
/**
* Checks to see if this feature can be changed and is enforced
*/
@Test
void checkIsConvex() {
PointsToPolyline alg = createAlg(true);
alg.setConvex(true);
List<Point2D_I32> contour = line(0, 0, 30, 0);
contour.addAll(line(30, 0, 30, 10));
contour.addAll(line(30, 10, 20, 10));
contour.addAll(line(20, 10, 20, 30));
contour.addAll(line(20, 30, 0, 30));
contour.addAll(line(0, 30, 0, 0));
DogArray_I32 found = new DogArray_I32();
assertFalse(alg.process(contour, found));
alg.setConvex(false);
assertTrue(alg.process(contour, found));
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ConvolveImageUnrolled_SB_S16_I16_Div method convolve5.
public static void convolve5(Kernel2D_S32 kernel, GrayS16 src, GrayI16 dest, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
final short[] dataSrc = src.data;
final short[] dataDst = dest.data;
final int width = src.getWidth();
final int height = src.getHeight();
final int halfDivisor = divisor / 2;
final int kernelRadius = kernel.getRadius();
final int kernelWidth = 2 * kernelRadius + 1;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(kernelRadius, height-kernelRadius, kernelWidth, workspaces, (work, y0, y1)->{
final int y0 = kernelRadius, y1 = height - kernelRadius;
int[] totalRow = BoofMiscOps.checkDeclare(work, src.width, false);
for (int y = y0; y < y1; y++) {
// first time through the value needs to be set
int k1 = kernel.data[0];
int k2 = kernel.data[1];
int k3 = kernel.data[2];
int k4 = kernel.data[3];
int k5 = kernel.data[4];
int indexSrcRow = src.startIndex + (y - kernelRadius) * src.stride - kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc++]) * k3;
total += (dataSrc[indexSrc++]) * k4;
total += (dataSrc[indexSrc]) * k5;
totalRow[x] = total;
}
// rest of the convolution rows are an addition
for (int i = 1; i < 5; i++) {
indexSrcRow = src.startIndex + (y + i - kernelRadius) * src.stride - kernelRadius;
k1 = kernel.data[i * 5 + 0];
k2 = kernel.data[i * 5 + 1];
k3 = kernel.data[i * 5 + 2];
k4 = kernel.data[i * 5 + 3];
k5 = kernel.data[i * 5 + 4];
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc++]) * k3;
total += (dataSrc[indexSrc++]) * k4;
total += (dataSrc[indexSrc]) * k5;
totalRow[x] += total;
}
}
int indexDst = dest.startIndex + y * dest.stride + kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
dataDst[indexDst++] = (short) ((totalRow[x] + halfDivisor) / divisor);
}
}
// CONCURRENT_INLINE });
}
use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.
the class ConvolveImageUnrolled_SB_S16_I16_Div method convolve9.
public static void convolve9(Kernel2D_S32 kernel, GrayS16 src, GrayI16 dest, int divisor, @Nullable GrowArray<DogArray_I32> workspaces) {
workspaces = BoofMiscOps.checkDeclare(workspaces, DogArray_I32::new);
// CONCURRENT_REMOVE_LINE
final DogArray_I32 work = workspaces.grow();
final short[] dataSrc = src.data;
final short[] dataDst = dest.data;
final int width = src.getWidth();
final int height = src.getHeight();
final int halfDivisor = divisor / 2;
final int kernelRadius = kernel.getRadius();
final int kernelWidth = 2 * kernelRadius + 1;
// CONCURRENT_BELOW BoofConcurrency.loopBlocks(kernelRadius, height-kernelRadius, kernelWidth, workspaces, (work, y0, y1)->{
final int y0 = kernelRadius, y1 = height - kernelRadius;
int[] totalRow = BoofMiscOps.checkDeclare(work, src.width, false);
for (int y = y0; y < y1; y++) {
// first time through the value needs to be set
int k1 = kernel.data[0];
int k2 = kernel.data[1];
int k3 = kernel.data[2];
int k4 = kernel.data[3];
int k5 = kernel.data[4];
int k6 = kernel.data[5];
int k7 = kernel.data[6];
int k8 = kernel.data[7];
int k9 = kernel.data[8];
int indexSrcRow = src.startIndex + (y - kernelRadius) * src.stride - kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc++]) * k3;
total += (dataSrc[indexSrc++]) * k4;
total += (dataSrc[indexSrc++]) * k5;
total += (dataSrc[indexSrc++]) * k6;
total += (dataSrc[indexSrc++]) * k7;
total += (dataSrc[indexSrc++]) * k8;
total += (dataSrc[indexSrc]) * k9;
totalRow[x] = total;
}
// rest of the convolution rows are an addition
for (int i = 1; i < 9; i++) {
indexSrcRow = src.startIndex + (y + i - kernelRadius) * src.stride - kernelRadius;
k1 = kernel.data[i * 9 + 0];
k2 = kernel.data[i * 9 + 1];
k3 = kernel.data[i * 9 + 2];
k4 = kernel.data[i * 9 + 3];
k5 = kernel.data[i * 9 + 4];
k6 = kernel.data[i * 9 + 5];
k7 = kernel.data[i * 9 + 6];
k8 = kernel.data[i * 9 + 7];
k9 = kernel.data[i * 9 + 8];
for (int x = kernelRadius; x < width - kernelRadius; x++) {
int indexSrc = indexSrcRow + x;
int total = 0;
total += (dataSrc[indexSrc++]) * k1;
total += (dataSrc[indexSrc++]) * k2;
total += (dataSrc[indexSrc++]) * k3;
total += (dataSrc[indexSrc++]) * k4;
total += (dataSrc[indexSrc++]) * k5;
total += (dataSrc[indexSrc++]) * k6;
total += (dataSrc[indexSrc++]) * k7;
total += (dataSrc[indexSrc++]) * k8;
total += (dataSrc[indexSrc]) * k9;
totalRow[x] += total;
}
}
int indexDst = dest.startIndex + y * dest.stride + kernelRadius;
for (int x = kernelRadius; x < width - kernelRadius; x++) {
dataDst[indexDst++] = (short) ((totalRow[x] + halfDivisor) / divisor);
}
}
// CONCURRENT_INLINE });
}
Aggregations