/** * Given two points, get a transform matrix that takes points from point a * to point b * * @param from * from this point * @param to * to this point * @return transform matrix */ public static Matrix translateToPointMatrix(Point2d from, Point2d to) { final Matrix matrix = Matrix.constructWithCopy(new double[][] { { 1, 0, to.minus(from).getX() }, { 0, 1, to.minus(from).getY() }, { 0, 0, 1 }, }); return matrix; }
public static void main(String[] args) throws IOException, InterruptedException { final FImage[] sequence = new FImage[3]; for (int i = 0; i < sequence.length; i++) { sequence[i] = ImageUtilities.readF(new File("/Users/jon/pendulum+circle/frame_" + (i + 10) + ".png")); } final MotionEstimatorAlgorithm.TEMPLATE_MATCH alg = new MotionEstimatorAlgorithm.TEMPLATE_MATCH(); final MotionEstimator e = new GridMotionEstimator(new ArrayBackedVideo<FImage>(sequence), alg, 10, 10, true); e.getNextFrame(); e.getNextFrame(); final Map<Point2d, Point2d> mv1 = e.getMotionVectors(); e.getNextFrame(); final Map<Point2d, Point2d> mv2 = e.getMotionVectors(); drawVectors(sequence, mv1); drawVectors(sequence, mv2); final Map<Point2d, Point2d> accel = new HashMap<Point2d, Point2d>(); for (final Entry<Point2d, Point2d> p : mv1.entrySet()) { final Point2d from = p.getKey(); final Point2d to = p.getValue().copy(); to.translate(from); final Point2d v1 = p.getValue(); Point2d v2 = mv2.get(to); if (v2 == null) v2 = new Point2dImpl(0, 0); final Point2d acc = v2.copy().minus(v1); accel.put(to, acc); } drawVectors(sequence, accel); }
public static void main(String[] args) throws IOException, InterruptedException { final FImage[] sequence = new FImage[3]; for (int i = 0; i < sequence.length; i++) { sequence[i] = ImageUtilities.readF(new File("/Users/jon/pendulum+circle/frame_" + (i + 10) + ".png")); } final MotionEstimatorAlgorithm.TEMPLATE_MATCH alg = new MotionEstimatorAlgorithm.TEMPLATE_MATCH(); final MotionEstimator e = new GridMotionEstimator(new ArrayBackedVideo<FImage>(sequence), alg, 10, 10, true); e.getNextFrame(); e.getNextFrame(); final Map<Point2d, Point2d> mv1 = e.getMotionVectors(); e.getNextFrame(); final Map<Point2d, Point2d> mv2 = e.getMotionVectors(); drawVectors(sequence, mv1); drawVectors(sequence, mv2); final Map<Point2d, Point2d> accel = new HashMap<Point2d, Point2d>(); for (final Entry<Point2d, Point2d> p : mv1.entrySet()) { final Point2d from = p.getKey(); final Point2d to = p.getValue().copy(); to.translate(from); final Point2d v1 = p.getValue(); Point2d v2 = mv2.get(to); if (v2 == null) v2 = new Point2dImpl(0, 0); final Point2d acc = v2.copy().minus(v1); accel.put(to, acc); } drawVectors(sequence, accel); }
return centerOfGrid.minus(firstBest);
return centerOfGrid.minus(firstBest);
/** * Create a transform to transform from one rectangle to another. * * @param from * first rectangle * @param to * second rectangle * @return the transform */ public static Matrix makeTransform(Rectangle from, Rectangle to) { final Point2d trans = to.getTopLeft().minus(from.getTopLeft()); final double scaleW = to.getWidth() / from.getWidth(); final double scaleH = to.getHeight() / from.getHeight(); return TransformUtilities.scaleMatrix(scaleW, scaleH).times( TransformUtilities.translateMatrix(trans.getX(), trans.getY())); }
final Point2d deltap = pt.minus(frameCentre);
final Point2d deltap = pt.minus(frameCentre);
final Point2d delta = pt.minus(frameCentre);
final Point2d delta = pt.minus(frameCentre);