本文整理汇总了Java中org.openimaj.image.MBFImage.drawPolygon方法的典型用法代码示例。如果您正苦于以下问题:Java MBFImage.drawPolygon方法的具体用法?Java MBFImage.drawPolygon怎么用?Java MBFImage.drawPolygon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openimaj.image.MBFImage
的用法示例。
在下文中一共展示了MBFImage.drawPolygon方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
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);
}
}
示例2: main
import org.openimaj.image.MBFImage; //导入方法依赖的package包/类
public static void main(String[] args) throws VideoCaptureException {
final VideoCapture vc = new VideoCapture(320, 240);
final JFrame frame = DisplayUtilities.displaySimple(vc.getNextFrame(), "capture");
final ConnectedComponentLabeler ccl = new ConnectedComponentLabeler(ConnectMode.CONNECT_4);
while (true) {
final MBFImage cimg = vc.getNextFrame();
final FImage gimg = cimg.flatten();
gimg.processInplace(new OtsuThreshold());
// gimg.threshold(0.4f);
ccl.analyseImage(gimg);
final ConnectedComponent hand = findBiggest(ccl.getComponents());
cimg.drawPoints(hand, RGBColour.WHITE, 1);
if (hand != null) {
Polygon poly = hand.toPolygon();
poly = poly.reduceVertices(3);
final Polygon chull = poly.calculateConvexHull();
final List<ConvexityDefect> defects = ConvexityDefect.findDefects(poly, chull);
// for (final ConvexityDefect cd : defects) {
// cimg.drawShapeFilled(cd.getTriangle(), RGBColour.MAGENTA);
// }
final List<Point2d> tips = findTips(defects);
final Point2d centroid = poly.calculateCentroid();
System.out.println(centroid);
for (final Point2d pt : tips) {
cimg.drawLine(centroid, pt, RGBColour.RED);
cimg.drawShape(new Circle(pt, 5), RGBColour.CYAN);
}
cimg.drawPolygon(poly, 1, RGBColour.RED);
cimg.drawPolygon(chull, 1, RGBColour.BLUE);
}
DisplayUtilities.display(cimg, frame);
}
}