@Override public void translate(float x, float y) { for (final Point2d v : vertices) v.translate(x, y); }
@Override public double computeResidual(IndependentPair<Point2d, Point2d> data) { final Point2d p1 = data.getFirstObject(); final Point2d p2 = data.getSecondObject(); final Point2d p1t = p1.transform(transform); final Point2d p2t = p2.transform(transformInv); final float p1x = p1.getX(); final float p1y = p1.getY(); final float p1tx = p1t.getX(); final float p1ty = p1t.getY(); final float p2x = p2.getX(); final float p2y = p2.getY(); final float p2tx = p2t.getX(); final float p2ty = p2t.getY(); final float dx12t = (p1x - p2tx); final float dy12t = (p1y - p2ty); final float dx1t2 = (p1tx - p2x); final float dy1t2 = (p1ty - p2y); return dx12t * dx12t + dy12t * dy12t + dx1t2 * dx1t2 + dy1t2 * dy1t2; }
/** * Scale the {@link PointList} only in the x-direction by the given amount * about (0,0). Scale factors between 0 and 1 will shrink the * {@link PointList} * * @param sc * The scale factor * @return this {@link PointList} */ public PointList scaleX(float sc) { for (final Point2d p : points) { p.setX(p.getX() * sc); } return this; }
/** * Apply the radial and tangential distortion of this camera to the given * projected point (presumably computed by projecting a world point through * the homography defined by the extrinsic parameters of a camera). The * point is modified in-place. * * @param p * the projected point * @return the input point (with the distortion added) */ public Point2d applyDistortion(Point2d p) { final double dx = (p.getX() - getPrincipalPointX()) / getFocalLengthX(); final double dy = (p.getY() - getPrincipalPointY()) / getFocalLengthY(); final double r2 = dx * dx + dy * dy; final double r4 = r2 * r2; final double r6 = r2 * r2 * r2; // radial component double tx = dx * (k1 * r2 + k2 * r4 + k3 * r6); double ty = dy * (k1 * r2 + k2 * r4 + k3 * r6); // tangential component tx += 2 * p1 * dx * dy + p2 * (r2 + 2 * dx * dx); ty += p1 * (r2 + 2 * dy * dy) + 2 * p2 * dx * dy; p.translate((float) tx, (float) ty); return p; }
/** * Scale the {@link PointList} only in the y-direction by the given amount * about (0,0). Scale factors between 0 and 1 will shrink the * {@link PointList} * * @param sc * The scale factor * @return this {@link PointList} */ public PointList scaleY(float sc) { for (final Point2d p : points) { p.setY(p.getY() * sc); } return this; }
/** * {@inheritDoc} * @see org.openimaj.vis.DataUnitsTransformer#calculateUnitsAt(java.lang.Object) */ @Override public Double calculateUnitsAt( final double[] position ) { if( this.transform == null ) this.precalc( ); final Point2d p = new Point2dImpl( (float)position[0], (float)position[1] ); final Point2d p2 = p.transform( this.transform.inverse() ); return new Double(p2.getX()); }
/** * @return The x-ordinate of the centre */ public float getX() { return centre.getX(); }
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); }
private static void drawVectors(final FImage[] sequence, final Map<Point2d, Point2d> mv1) { final FImage fr = new FImage(sequence[0].width, sequence[0].height); for (final Entry<Point2d, Point2d> p : mv1.entrySet()) { final Point2d from = p.getKey(); final Point2d to = p.getValue().copy(); to.translate(from); if (!from.equals(to)) fr.drawLine(from, to, 1f); } DisplayUtilities.display(fr); } }
@Override public Point2d predict(Point2d data) { return data.transform(homography); } }
/** * Set the x-ordinate of the centre of the circle. * * @param x * The x-ordinate */ public void setX(float x) { this.centre.setX(x); }
/** * Set the y-ordinate of the centre of the circle. * * @param y * The y-ordinate */ public void setY(float y) { this.centre.setY(y); }
/** * Scale the polygon only in the x-direction by the given amount about * (0,0). Scale factors between 0 and 1 will shrink the polygon * * @param sc * The scale factor * @return this polygon */ @Override public Polygon scaleX(float sc) { for (int pp = 0; pp < getNumInnerPoly(); pp++) { final Polygon ppp = getInnerPoly(pp); for (int i = 0; i < ppp.nVertices(); i++) { final Point2d p = ppp.points.get(i); p.setX(p.getX() * sc); } } return this; }
/** * Scale the polygon only in the y-direction by the given amount about * (0,0). Scale factors between 0 and 1 will shrink the polygon * * @param sc * The scale factor * @return this polygon */ @Override public Polygon scaleY(float sc) { for (int pp = 0; pp < getNumInnerPoly(); pp++) { final Polygon ppp = getInnerPoly(pp); for (int i = 0; i < ppp.nVertices(); i++) { final Point2d p = ppp.points.get(i); p.setY(p.getY() * sc); } } return this; }
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); }
private static void drawVectors(final FImage[] sequence, final Map<Point2d, Point2d> mv1) { final FImage fr = new FImage(sequence[0].width, sequence[0].height); for (final Entry<Point2d, Point2d> p : mv1.entrySet()) { final Point2d from = p.getKey(); final Point2d to = p.getValue().copy(); to.translate(from); if (!from.equals(to)) fr.drawLine(from, to, 1f); } DisplayUtilities.display(fr); } }