栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

OpenCV.图形绘制.圆

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

OpenCV.图形绘制.圆

圆的绘制

在OpenCV环境中,圆的绘制依赖于Imgproc.circle() 这个方法。该方法的一个构造方法如下:
circle(img, center, radius, color, thickness);
其参数解释如下:

  • mat
    Mat对象,表示要在其上绘制圆的图像。
  • point
    代表圆中心的Point对象。
  • radius
    表示圆的半径的整型变量。
  • scalar
    表示圆的颜色的标量对象(BGR)。
  • thickness
    表示圆的厚度的整数; 默认情况下,厚度值为1。

Java代码(JavaFX Controller层)

public class Controller{

    @FXML private Text fxText;
    @FXML private ImageView imageView;

    @FXML public void handleButtonEvent(ActionEvent actionEvent) throws IOException {
        Node source = (Node) actionEvent.getSource();
        Window theStage = source.getScene().getWindow();
        FileChooser fileChooser = new FileChooser();
        FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.png");
        fileChooser.getExtensionFilters().add(extFilter);
        fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JPG Files(*.jpg)", "*.jpg"));
        File file = fileChooser.showOpenDialog(theStage);

        imageView.setImage(this.drawCircle(file.getPath()));
    }


    private WritableImage drawCircle(String filePath) throws IOException {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

		// Source.
        Mat src = Imgcodecs.imread(filePath);

		// Draw a circle.
        Imgproc.circle(src, new Point(218,120), 55, new Scalar(0,0,255), 2);

		// Encode source into MatOfByte object.
        MatOfByte matOfByte = new MatOfByte();
        Imgcodecs.imencode(".jpg", src, matOfByte);

        byte[] bytes = matOfByte.toArray();
        InputStream in = new ByteArrayInputStream(bytes);
        BufferedImage bufImage = ImageIO.read(in);

        WritableImage writableImage = SwingFXUtils.toFXImage(bufImage, null);

        return writableImage;
    }

}

运行图:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/336932.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号