@Override public Shape getShape() { return connectedComponent.toPolygon(); } }
/** * Calculates the polygon that defines the minimum bounding box that best * fits the connected component, at whatever angle that may be. * * @return A {@link RotatedRectangle} that defines the minimum bounding box. */ public RotatedRectangle calculateOrientatedBoundingBox() { return this.toPolygon().minimumBoundingRectangle(); } }
/** * Compute the aspect ratio of the oriented bounding box. * * @return the aspect ratio of the oriented bounding box. */ public double calculateOrientatedBoundingBoxAspectRatio() { final RotatedRectangle r = toPolygon().minimumBoundingRectangle(); return r.height / r.width; }
/** * Calculates the polygon that defines the minimum bounding box that best * fits the connected component, at whatever angle that may be. * * @return A {@link RotatedRectangle} that defines the minimum bounding box. */ public RotatedRectangle calculateOrientatedBoundingBox() { return this.toPolygon().minimumBoundingRectangle(); } }
/** * Compute the aspect ratio of the oriented bounding box. * * @return the aspect ratio of the oriented bounding box. */ public double calculateOrientatedBoundingBoxAspectRatio() { final RotatedRectangle r = toPolygon().minimumBoundingRectangle(); return r.height / r.width; }
@Override public void process(ConnectedComponent cc) { area = cc.calculateArea(); final double[] c = cc.calculateCentroid(); cx = c[0]; cy = c[1]; direction = cc.calculateDirection(); elongatedness = cc.calculateOrientatedBoundingBoxAspectRatio(); final float edge_length = cc.getOuterBoundary().size(); compactness = (edge_length * edge_length) / new ConnectedComponent(cc.toPolygon()).calculateArea(); if (area > 4) chfit = new ConnectedComponent(cc.toPolygon()).calculatePercentageConvexHullFit(); // chfit // won't // work // for // really // small // regions else chfit = 1; if (area > 100) cornerEst = cc.estimateNumberOfVertices(3, 10); else cornerEst = area; }
@Override public void process(ConnectedComponent cc) { area = cc.calculateArea(); final double[] c = cc.calculateCentroid(); cx = c[0]; cy = c[1]; direction = cc.calculateDirection(); elongatedness = cc.calculateOrientatedBoundingBoxAspectRatio(); final float edge_length = cc.getOuterBoundary().size(); compactness = (edge_length * edge_length) / new ConnectedComponent(cc.toPolygon()).calculateArea(); if (area > 4) chfit = new ConnectedComponent(cc.toPolygon()).calculatePercentageConvexHullFit(); // chfit // won't // work // for // really // small // regions else chfit = 1; if (area > 100) cornerEst = cc.estimateNumberOfVertices(3, 10); else cornerEst = area; }
public static void main(String[] args) throws Exception { final VideoCapture vc = new VideoCapture(320, 240); final JFrame frame = DisplayUtilities.displaySimple(vc.getNextFrame(), "capture"); final ConnectedComponentLabeler ccl = new ConnectedComponentLabeler(ConnectMode.CONNECT_4); final String dev = "/dev/tty.usbmodemfd121"; final SerialDevice device = new SerialDevice(dev, 9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); while (true) { final MBFImage cimg = vc.getNextFrame(); final FImage gimg = cimg.flatten(); // gimg.processInplace(new OtsuThreshold()); gimg.threshold(0.6f); ccl.analyseImage(gimg); final ConnectedComponent hand = Fingers.findBiggest(ccl.getComponents()); if (hand != null) { final Polygon poly = hand.toPolygon(); cimg.drawPolygon(poly, 2, RGBColour.RED); double ratio = hand.calculateRegularBoundingBoxAspectRatio(); System.out.println(ratio); ratio = 1 - ((ratio - 3.0) / (5.5 - 3)); ratio = ratio < 0 ? 0 : ratio > 1 ? 1 : ratio; final int amt = (int) (ratio * 180); sendCommand(device, amt); System.out.println(ratio + " " + amt); } DisplayUtilities.display(cimg, frame); } }
public static void main(String[] args) throws Exception { final VideoCapture vc = new VideoCapture(320, 240); final JFrame frame = DisplayUtilities.displaySimple(vc.getNextFrame(), "capture"); final ConnectedComponentLabeler ccl = new ConnectedComponentLabeler(ConnectMode.CONNECT_4); final String dev = "/dev/tty.usbmodemfd121"; final SerialDevice device = new SerialDevice(dev, 9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); while (true) { final MBFImage cimg = vc.getNextFrame(); final FImage gimg = cimg.flatten(); // gimg.processInplace(new OtsuThreshold()); gimg.threshold(0.6f); ccl.analyseImage(gimg); final ConnectedComponent hand = Fingers.findBiggest(ccl.getComponents()); if (hand != null) { final Polygon poly = hand.toPolygon(); cimg.drawPolygon(poly, 2, RGBColour.RED); double ratio = hand.calculateRegularBoundingBoxAspectRatio(); System.out.println(ratio); ratio = 1 - ((ratio - 3.0) / (5.5 - 3)); ratio = ratio < 0 ? 0 : ratio > 1 ? 1 : ratio; final int amt = (int) (ratio * 180); sendCommand(device, amt); System.out.println(ratio + " " + amt); } DisplayUtilities.display(cimg, frame); } }
frame.drawShape(big.toPolygon(), RGBColour.RED);
frame.drawShape(big.toPolygon(), RGBColour.RED);
Polygon poly = hand.toPolygon(); poly = poly.reduceVertices(3);
Polygon poly = hand.toPolygon(); poly = poly.reduceVertices(3);