@Test public void findFlow() { Dummy alg = new Dummy(3, 2, 200, ImageUInt8.class); alg.minScore = 0.1f; alg.targetX = 4; alg.targetY = 8; ImageUInt8 image = new ImageUInt8(30, 40); ImageFlow.D flow = new ImageFlow.D(); // see if it selects the obvious minimum assertEquals(0.1f, alg.findFlow(6, 7, image, flow), 1e-4); assertTrue(flow.valid); assertEquals(-2, flow.x, 1e-4); assertEquals(1, flow.y, 1e-4); // now try the case where the error is too high alg.minScore = 100000000f; alg.findFlow(6, 7, image, flow); assertFalse(flow.valid); // now give it a case where everything has the same score. See if it picks the one with the // least motion alg.sameScore = true; alg.minScore = 0.1f; alg.findFlow(6, 7, image, flow); assertTrue(flow.valid); assertEquals(0, flow.x, 1e-4); assertEquals(0, flow.y, 1e-4); }
@Test public void checkNeighbors() { int r = 3; Dummy alg = new Dummy(r, 2, 200, ImageUInt8.class); alg.scores = new float[20 * 30]; ImageFlow flows = new ImageFlow(20, 30); ImageFlow.D tmp = new ImageFlow.D(); tmp.valid = true; 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).valid = true; alg.scores[5 * 20 + 6] = 10; flows.get(5, 5).valid = true; alg.scores[5 * 20 + 5] = 4; // same score, but more motion flows.get(5, 6).valid = true; alg.scores[6 * 20 + 5] = 5; flows.get(5, 6).x = 2; flows.get(5, 6).y = 2; // same score, but less motion flows.get(6, 6).valid = true; 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 = -r; i <= r; i++) { for (int j = -r; j <= r; j++) { int x = j + 6; int y = i + 7; ImageFlow.D f = flows.get(x, y); assertTrue(f.valid); if (x == 5 && y == 5) { assertEquals(4, alg.scores[y * 20 + x], 1e-4); assertEquals(0, f.x, 1e-4); assertEquals(0, 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); } } } }
@Override public String compute(String arg) throws InterruptedException { return dummy.echoWith(arg); }