Search in sources :

Example 6 with ImageFlow

use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.

the class GeneralDenseOpticalFlowChecks method checkChangeInputSize.

/**
 * Does it handle the input image size being changed after the first image?
 */
@Test
public void checkChangeInputSize() {
    DenseOpticalFlow<T> alg = createAlg(imageType);
    alg.process(orig, shifted, found);
    T larger0 = GeneralizedImageOps.createSingleBand(imageType, 40, 35);
    T larger1 = GeneralizedImageOps.createSingleBand(imageType, 40, 35);
    // if it doesn't blow up it worked
    alg.process(larger0, larger1, new ImageFlow(40, 35));
}
Also used : ImageFlow(boofcv.struct.flow.ImageFlow) Test(org.junit.Test)

Example 7 with ImageFlow

use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.

the class TestDenseOpticalFlowBlockPyramid method checkNeighbors.

@Test
public void checkNeighbors() {
    int sr = 3;
    int rr = 2;
    Dummy alg = new Dummy(sr, rr, 200, GrayU8.class);
    alg.scores = new float[20 * 30];
    Arrays.fill(alg.scores, 20);
    ImageFlow flows = new ImageFlow(20, 30);
    flows.invalidateAll();
    ImageFlow.D tmp = new ImageFlow.D();
    tmp.x = -1;
    tmp.y = 2;
    // checks to see if a pixel is invalid that it's flow is always set
    // if a pixel is valid then the score is only set if the score is better
    flows.get(6, 5).x = 1;
    flows.get(6, 5).y = 2;
    alg.scores[5 * 20 + 6] = 10;
    flows.get(5, 5).x = 1;
    flows.get(5, 5).y = 2;
    alg.scores[5 * 20 + 5] = 4;
    // same score, but more motion
    alg.scores[6 * 20 + 5] = 5;
    flows.get(5, 6).x = 2;
    flows.get(5, 6).y = 2;
    // same score, but less motion
    alg.scores[6 * 20 + 6] = 5;
    flows.get(6, 6).x = 0;
    flows.get(6, 6).y = 1;
    alg.checkNeighbors(6, 7, tmp, flows, 5);
    for (int i = -rr; i <= rr; i++) {
        for (int j = -rr; j <= rr; j++) {
            int x = j + 6;
            int y = i + 7;
            ImageFlow.D f = flows.get(x, y);
            assertTrue(f.isValid());
            if (x == 5 && y == 5) {
                assertEquals(4, alg.scores[y * 20 + x], 1e-4);
                assertEquals(1, f.x, 1e-4);
                assertEquals(2, f.y, 1e-4);
            } else if (x == 6 && y == 6) {
                assertEquals(5, alg.scores[y * 20 + x], 1e-4);
                assertEquals(0, f.x, 1e-4);
                assertEquals(1, f.y, 1e-4);
            } else {
                assertEquals(x + " " + y, 5, alg.scores[y * 20 + x], 1e-4);
                assertEquals(-1, f.x, 1e-4);
                assertEquals(2, f.y, 1e-4);
            }
        }
    }
}
Also used : ImageFlow(boofcv.struct.flow.ImageFlow) Test(org.junit.Test)

Example 8 with ImageFlow

use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.

the class TestDenseOpticalFlowKlt method negative.

/**
 * Very simple negative case. The second image is blank so it should fail at tracking
 */
@Test
public void negative() {
    ImageMiscOps.fillRectangle(image0, 200, 7, 9, 5, 5);
    processInputImage();
    DenseOpticalFlowKlt<GrayF32, GrayF32> alg = createAlg();
    ImageFlow flow = new ImageFlow(image0.width, image0.height);
    alg.process(prev, prevDerivX, prevDerivY, curr, flow);
    int totalFail = 0;
    for (int i = 0; i < flow.data.length; i++) {
        if (!flow.data[i].isValid()) {
            totalFail++;
        }
    }
    assertTrue(totalFail / (double) flow.data.length >= 0.90);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ImageFlow(boofcv.struct.flow.ImageFlow) Test(org.junit.Test)

Example 9 with ImageFlow

use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.

the class TestDenseOpticalFlowKlt method positive.

/**
 * Very simple positive case
 */
@Test
public void positive() {
    ImageMiscOps.fillRectangle(image0, 50, 10, 12, 2, 2);
    ImageMiscOps.fillRectangle(image1, 50, 11, 13, 2, 2);
    processInputImage();
    DenseOpticalFlowKlt<GrayF32, GrayF32> alg = createAlg();
    ImageFlow flow = new ImageFlow(image0.width, image0.height);
    flow.invalidateAll();
    alg.process(prev, prevDerivX, prevDerivY, curr, flow);
    // no texture in the image so KLT can't do anything
    check(flow.get(0, 0), false, 0, 0);
    check(flow.get(29, 39), false, 0, 0);
    // there is texture at the target
    check(flow.get(10, 12), true, 1, 1);
    check(flow.get(11, 12), true, 1, 1);
    check(flow.get(10, 13), true, 1, 1);
    check(flow.get(11, 13), true, 1, 1);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) ImageFlow(boofcv.struct.flow.ImageFlow) Test(org.junit.Test)

Example 10 with ImageFlow

use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.

the class TestHornSchunck method innerAverageFlow_borderAverageFlow.

@Test
public void innerAverageFlow_borderAverageFlow() {
    ImageFlow flow = new ImageFlow(30, 35);
    ImageFlow found = new ImageFlow(30, 35);
    for (int y = 0; y < flow.height; y++) {
        for (int x = 0; x < flow.width; x++) {
            flow.get(x, y).x = rand.nextFloat() * 2;
            flow.get(x, y).y = rand.nextFloat() * 2;
        }
    }
    HornSchunck.borderAverageFlow(flow, found);
    HornSchunck.innerAverageFlow(flow, found);
    ImageFlow.D expected = new ImageFlow.D();
    for (int y = 0; y < flow.height; y++) {
        for (int x = 0; x < flow.width; x++) {
            computeAverage(flow, x, y, expected);
            assertEquals(expected.x, found.get(x, y).x, 1e-4);
            assertEquals(expected.y, found.get(x, y).y, 1e-4);
        }
    }
}
Also used : ImageFlow(boofcv.struct.flow.ImageFlow) Test(org.junit.Test)

Aggregations

ImageFlow (boofcv.struct.flow.ImageFlow)14 Test (org.junit.Test)8 GrayF32 (boofcv.struct.image.GrayF32)7 FDistort (boofcv.abst.distort.FDistort)1 PanelGridPanel (boofcv.gui.PanelGridPanel)1 AnimatePanel (boofcv.gui.image.AnimatePanel)1 MediaManager (boofcv.io.MediaManager)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)1 BufferedImage (java.awt.image.BufferedImage)1