Search in sources :

Example 1 with DoNothingPixelTransform_F64

use of boofcv.alg.distort.DoNothingPixelTransform_F64 in project BoofCV by lessthanoptimal.

the class TestMultiBaselineDisparityMedian method computeFused.

/**
 * Given an already constructed fused image, compute the disparity image output.
 */
@Test
void computeFused() {
    var alg = new MultiBaselineDisparityMedian();
    intrinsic.width = 10;
    intrinsic.height = 8;
    alg.initialize(intrinsic, new DoNothingPixelTransform_F64());
    // add elements to each fused pixel that will be easy to compute the solution for
    int counter = 0;
    for (int y = 0; y < 8; y++) {
        for (int x = 0; x < 10; x++, counter++) {
            for (int i = 0; i < counter; i++) {
                alg.fused.get(x, y).add(i + 0.5f);
            }
        }
    }
    GrayF32 found = new GrayF32(10, 8);
    assertTrue(alg.computeFused(found));
    // manually compute the solution. Use a brute force approach for median value since it requires no thinking
    DogArray_F32 expected = new DogArray_F32();
    for (int y = 0; y < 8; y++) {
        for (int x = 0; x < 10; x++) {
            if (expected.size == 0)
                assertEquals(Float.MAX_VALUE, found.get(x, y), UtilEjml.TEST_F32);
            else if (expected.size == 1)
                assertEquals(0.5f, found.get(x, y), UtilEjml.TEST_F32);
            else if (expected.size == 2)
                assertEquals(1.0f, found.get(x, y), UtilEjml.TEST_F32);
            else {
                assertEquals(expected.data[expected.size / 2], found.get(x, y), UtilEjml.TEST_F32);
            }
            expected.add(expected.size + 0.5f);
        }
    }
}
Also used : DoNothingPixelTransform_F64(boofcv.alg.distort.DoNothingPixelTransform_F64) GrayF32(boofcv.struct.image.GrayF32) DogArray_F32(org.ddogleg.struct.DogArray_F32) Test(org.junit.jupiter.api.Test)

Example 2 with DoNothingPixelTransform_F64

use of boofcv.alg.distort.DoNothingPixelTransform_F64 in project BoofCV by lessthanoptimal.

the class TestScoreRectifiedViewCoveragePixels method everything.

/**
 * Put it all together and test using simple examples
 */
@Test
void everything() {
    var alg = new ScoreRectifiedViewCoveragePixels();
    alg.maxSide = 30;
    // do nothing to make the math easier to hand compute
    alg.initialize(width, height, new DoNothingPixelTransform_F64());
    // add a view that's half the size and rectification is simply identity (no change in pixels)
    alg.addView(width / 2, height, CommonOps_DDRM.diag(1, 1, 1), 1.0f, Float::max);
    // compute for just this one view
    alg.process();
    // coverage should be 0.5 and average 1.0
    double expected0 = 0.5 * (alg.scoreAverageOffset + 300.0 / (1.0 + 300.0));
    assertEquals(expected0, alg.getScore(), UtilEjml.TEST_F64);
    assertEquals(0.5, alg.getCovered(), UtilEjml.TEST_F64);
    // Add another image which will cover everything
    alg.addView(width, height, CommonOps_DDRM.diag(1, 1, 1), 1.0f, Float::sum);
    alg.process();
    double expected1 = 1.0 * (alg.scoreAverageOffset + 900 / (1.0 + 600.0));
    assertEquals(expected1, alg.getScore(), UtilEjml.TEST_F64);
}
Also used : DoNothingPixelTransform_F64(boofcv.alg.distort.DoNothingPixelTransform_F64) Test(org.junit.jupiter.api.Test)

Example 3 with DoNothingPixelTransform_F64

use of boofcv.alg.distort.DoNothingPixelTransform_F64 in project BoofCV by lessthanoptimal.

the class TestMultiBaselineDisparityMedian method checkDisparityConversion.

/**
 * @param imageValue pixel value in disparity image
 * @param focalScale How much the fused focal length is scaled by
 * @param baselineScale How much the fused baseline is scaled by
 * @param expected Expected value of fused disparity
 */
void checkDisparityConversion(float imageValue, double focalScale, double baselineScale, double expected) {
    int width = 3;
    int height = 2;
    var intrinsic2 = new CameraPinhole(intrinsic);
    intrinsic2.fx *= focalScale;
    intrinsic2.fy *= focalScale;
    var param2 = new DisparityParameters(5, 100, 500 * baselineScale, intrinsic2);
    var alg = new MultiBaselineDisparityMedian();
    alg.initialize(intrinsic, new DoNothingPixelTransform_F64());
    // keep the baseline the same, yes this should be checked too but isn't here
    alg.fusedBaseline = 500;
    var image = new MultiBaselineDisparityMedian.DisparityImage();
    image.disparity.reshape(width, height);
    ImageMiscOps.fill(image.disparity, imageValue);
    image.mask.reshape(image.disparity);
    ImageMiscOps.fill(image.mask, 1);
    image.parameters.setTo(param2);
    CommonOps_DDRM.setIdentity(image.undist_to_rect_px);
    assertTrue(alg.addToFusedImage(image));
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            if (expected > 0) {
                assertEquals(1, alg.fused.get(x, y).size);
                float found = alg.fused.get(x, y).get(0);
                assertEquals(expected, found, UtilEjml.TEST_F32);
            } else {
                assertEquals(0, alg.fused.get(x, y).size);
            }
        }
    }
}
Also used : DoNothingPixelTransform_F64(boofcv.alg.distort.DoNothingPixelTransform_F64) CameraPinhole(boofcv.struct.calib.CameraPinhole)

Example 4 with DoNothingPixelTransform_F64

use of boofcv.alg.distort.DoNothingPixelTransform_F64 in project BoofCV by lessthanoptimal.

the class TestMultiBaselineDisparityMedian method computeFused_AllInvalid.

/**
 * Should fail if it can't find a valid pixel
 */
@Test
void computeFused_AllInvalid() {
    var alg = new MultiBaselineDisparityMedian();
    intrinsic.width = 10;
    intrinsic.height = 8;
    alg.initialize(intrinsic, new DoNothingPixelTransform_F64());
    // This will fail because every pixel is empty
    assertFalse(alg.computeFused(new GrayF32(10, 8)));
}
Also used : DoNothingPixelTransform_F64(boofcv.alg.distort.DoNothingPixelTransform_F64) GrayF32(boofcv.struct.image.GrayF32) Test(org.junit.jupiter.api.Test)

Example 5 with DoNothingPixelTransform_F64

use of boofcv.alg.distort.DoNothingPixelTransform_F64 in project BoofCV by lessthanoptimal.

the class TestScoreRectifiedViewCoveragePixels method addView.

@Test
void addView() {
    var alg = new ScoreRectifiedViewCoveragePixels();
    alg.maxSide = 30;
    alg.initialize(width, height, new DoNothingPixelTransform_F64());
    // set one pixels to -1 and it should not be updated
    alg.viewed.set(0, 0, -1);
    // This will scale x-coordinate by a factor of two and leave y as is
    DMatrixRMaj rect = CommonOps_DDRM.diag(2.0, 1.0, 1.0);
    // Call the function being tested. Note that the height is smaller
    alg.addView(width, 1000, rect, 0.5f, Float::sum);
    for (int y = 0; y < 30; y++) {
        for (int x = 0; x < 20; x++) {
            float found = alg.viewed.unsafe_get(x, y);
            if (x == 0 && y == 0) {
                assertEquals(-1, found);
            } else if (x < 10 && y < 20) {
                // These should all be updated since they are within the small view AND 1/2 the x-axis resolution
                assertEquals(0.5f, found);
            } else {
                assertEquals(0, found);
            }
        }
    }
}
Also used : DoNothingPixelTransform_F64(boofcv.alg.distort.DoNothingPixelTransform_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.jupiter.api.Test)

Aggregations

DoNothingPixelTransform_F64 (boofcv.alg.distort.DoNothingPixelTransform_F64)5 Test (org.junit.jupiter.api.Test)4 GrayF32 (boofcv.struct.image.GrayF32)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)1 DogArray_F32 (org.ddogleg.struct.DogArray_F32)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1