use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class DenseOpticalFlowBlockPyramid method process.
/**
* Computes the optical flow form 'prev' to 'curr' and stores the output into output
* @param pyramidPrev Previous image
* @param pyramidCurr Current image
*/
public void process(ImagePyramid<T> pyramidPrev, ImagePyramid<T> pyramidCurr) {
InputSanityCheck.checkSameShape(pyramidPrev, pyramidCurr);
int numLayers = pyramidPrev.getNumLayers();
for (int i = numLayers - 1; i >= 0; i--) {
T prev = pyramidPrev.getLayer(i);
T curr = pyramidCurr.getLayer(i);
flowCurrLayer.reshape(prev.width, prev.height);
int N = prev.width * prev.height;
if (scores.length < N)
scores = new float[N];
// mark all the scores as being very large so that if it has not been processed its score
// will be set inside of checkNeighbors.
Arrays.fill(scores, 0, N, Float.MAX_VALUE);
int x1 = prev.width - regionRadius;
int y1 = prev.height - regionRadius;
if (i == numLayers - 1) {
// the top most layer in the pyramid has no hint
for (int y = regionRadius; y < y1; y++) {
for (int x = regionRadius; x < x1; x++) {
extractTemplate(x, y, prev);
float score = findFlow(x, y, curr, tmp);
if (tmp.isValid())
checkNeighbors(x, y, tmp, flowCurrLayer, score);
else
flowCurrLayer.unsafe_get(x, y).markInvalid();
}
}
} else {
// for all the other layers use the hint of the previous layer to start its search
double scale = pyramidPrev.getScale(i + 1) / pyramidPrev.getScale(i);
for (int y = regionRadius; y < y1; y++) {
for (int x = regionRadius; x < x1; x++) {
// grab the flow in higher level pyramid
ImageFlow.D p = flowPrevLayer.get((int) (x / scale), (int) (y / scale));
if (!p.isValid())
continue;
// get the template around the current point in this layer
extractTemplate(x, y, prev);
// add the flow from the higher layer (adjusting for scale and rounding) as the start of
// this search
int deltaX = (int) (p.x * scale + 0.5);
int deltaY = (int) (p.y * scale + 0.5);
int startX = x + deltaX;
int startY = y + deltaY;
float score = findFlow(startX, startY, curr, tmp);
// find flow only does it relative to the starting point
tmp.x += deltaX;
tmp.y += deltaY;
if (tmp.isValid())
checkNeighbors(x, y, tmp, flowCurrLayer, score);
else
flowCurrLayer.unsafe_get(x, y).markInvalid();
}
}
}
// swap the flow images
ImageFlow tmp = flowPrevLayer;
flowPrevLayer = flowCurrLayer;
flowCurrLayer = tmp;
}
}
use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class ChecksHornSchunck method process.
/**
* Manually construct the input so that it has a known and easily understood output
*/
@Test
public void process() {
HornSchunck<T, D> alg = createAlg();
T image1 = GeneralizedImageOps.createSingleBand(imageType, width, height);
T image2 = GeneralizedImageOps.createSingleBand(imageType, width, height);
ImageFlow output = new ImageFlow(width, height);
GImageMiscOps.fillRectangle(image1, 100, 10, 0, 20, 30);
GImageMiscOps.fillRectangle(image2, 100, 11, 0, 20, 30);
alg.process(image1, image2, output);
for (int y = 0; y < height - 1; y++) {
assertTrue(output.get(9, y).x > 0.9);
assertTrue(Math.abs(output.get(10, y).y) < 0.1);
assertTrue(output.get(10, y).x > 0.9);
assertTrue(Math.abs(output.get(11, y).y) < 0.1);
}
}
use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class GeneralDenseOpticalFlowChecks method checkSubImage.
@Test
public void checkSubImage() {
DenseOpticalFlow<T> alg = createAlg(imageType);
shift(orig, 1, -1, shifted);
alg.process(orig, shifted, found);
// should produce identical solution
T subOrig = BoofTesting.createSubImageOf(orig);
T subShifted = BoofTesting.createSubImageOf(shifted);
ImageFlow found2 = new ImageFlow(found.width, found.height);
alg.process(subOrig, subShifted, found2);
for (int y = 0; y < found.height; y++) {
for (int x = 0; x < found.width; x++) {
ImageFlow.D a = found.get(x, y);
ImageFlow.D b = found2.get(x, y);
if (a.isValid()) {
assertTrue(a.x == b.x);
assertTrue(a.y == b.y);
} else {
assertFalse(b.isValid());
}
}
}
}
use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class HornSchunckPyramid_to_DenseOpticalFlow method process.
@Override
public void process(T source, T destination, ImageFlow flow) {
hornSchunck.process(source, destination);
GrayF32 flowX = hornSchunck.getFlowX();
GrayF32 flowY = hornSchunck.getFlowY();
int index = 0;
for (int y = 0; y < flow.height; y++) {
for (int x = 0; x < flow.width; x++, index++) {
ImageFlow.D d = flow.unsafe_get(x, y);
d.x = flowX.data[index];
d.y = flowY.data[index];
}
}
}
use of boofcv.struct.flow.ImageFlow in project BoofCV by lessthanoptimal.
the class BroxWarpingSpacial_to_DenseOpticalFlow method process.
@Override
public void process(T source, T destination, ImageFlow flow) {
brox.process(source, destination);
GrayF32 flowX = brox.getFlowX();
GrayF32 flowY = brox.getFlowY();
int index = 0;
for (int y = 0; y < flow.height; y++) {
for (int x = 0; x < flow.width; x++, index++) {
ImageFlow.D d = flow.unsafe_get(x, y);
d.x = flowX.data[index];
d.y = flowY.data[index];
}
}
}
Aggregations