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;
    }

}

运行图:
在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值