python画箭头opencv_OpenCV绘制箭头线
OpenCV绘制箭头线
可以使用imgproc类的arrowedLine()方法在图像上绘制箭头线。 以下是这种方法的语法 -
arrowedLine(Mat img, Point pt1, Point pt2, Scalar color)
该方法接受以下参数 -
mat - 表示要在其上绘制矩形的图像的Mat对象。
pt1 和 pt2 - 两个Point对象,表示要绘制的矩形的顶点。
color - 表示矩形颜色的标量对象(BGR)。
示例
以下程序演示如何在图像上绘制箭头线并使用JavaFX窗口显示它。
package yiibai.com;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javafx.application.Application;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.stage.Stage;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class DrawingArrowedLine extends Application {
Mat matrix = null;
@Override
public void start(Stage stage) throws Exception {
// Capturing the snapshot from the camera
DrawingArrowedLine obj = new DrawingArrowedLine();
WritableImage writableImage = obj.LoadImage();
// Setting the image view
ImageView imageView = new ImageView(writableImage);
// setting the fit height and width of the image view
imageView.setFitHeight(600);
imageView.setFitWidth(600);
// Setting the preserve ratio of the image view
imageView.setPreserveRatio(true);
// Creating a Group object
Group root = new Group(imageView);
// Creating a scene object
Scene scene = new Scene(root, 600, 400);
// Setting title to the Stage
stage.setTitle("Drawing a line on the image");
// Adding scene to the stage
stage.setScene(scene);
// Displaying the contents of the stage
stage.show();
}
public WritableImage LoadImage() throws Exception {
// Loading the OpenCV core library
System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
// Reading the Image from the file and storing it in to a Matrix object
String file ="F:/worksp/opencv/images/sample2.jpg";
Mat matrix = Imgcodecs.imread(file);
//Drawing a line
Imgproc.arrowedLine(
matrix, // Matrix obj of the image
new Point(10, 200), // p1
new Point(590, 200), // p2
new Scalar(0, 100, 255) // Scalar object for color
);
// arrowedLine(Mat img, Point pt1, Point pt2, Scalar color)
// Encoding the image
MatOfByte matOfByte = new MatOfByte();
Imgcodecs.imencode(".jpg", matrix, matOfByte);
// Storing the encoded Mat in a byte array
byte[] byteArray = matOfByte.toArray();
// Displaying the image
InputStream in = new ByteArrayInputStream(byteArray);
BufferedImage bufImage = ImageIO.read(in);
this.matrix = matrix;
// Creating the Writable Image
WritableImage writableImage = SwingFXUtils.toFXImage(bufImage, null);
return writableImage;
}
public static void main(String args[]) {
launch(args);
}
}
执行上面示例代码,您将会看到以下结果 -
python画箭头opencv_OpenCV绘制箭头线相关推荐
- python在地图上标注点_怎样用python画地图上的标注线
怎样用python画地图上的标注线 发布时间:2020-11-16 09:52:53 来源:亿速云 阅读:90 作者:小新 小编给大家分享一下怎样用python画地图上的标注线,希望大家阅读完这篇文章 ...
- python画地图经纬度_如何用python画地图上的标注线?
我们平时看文章的时候会遇到一些不太好理解的地方,如果上面有标注那就事半功倍了.当然在地图中也是如此.之前我们学会了很多画图的技巧,但是忽略了标注这种细节的重要作用.小编经过一番学习和整理,清楚了这部分 ...
- python地图标点_如何用python画地图上的标注线?
我们平时看文章的时候会遇到一些不太好理解的地方,如果上面有标注那就事半功倍了.当然在地图中也是如此.之前我们学会了很多画图的技巧,但是忽略了标注这种细节的重要作用.小编经过一番学习和整理,清楚了这部分 ...
- python绘制蜡烛图_一步一步教你用Python画出专业的K线图
漂亮的界面是量化程序的脸面,直观专业的界面能帮助我们了解股票的走势和形象地展示量化交易的结果.本文介绍如何使用matplotlib做出专业的K线图和展示各种技术指标: matplotlib是受MATL ...
- 用python绘制股票图_一步一步教你用Python画出专业的K线图
漂亮的界面是量化程序的脸面,直观专业的界面能帮助我们了解股票的走势和形象地展示量化交易的结果.本文介绍如何使用matplotlib做出专业的K线图和展示各种技术指标: matplotlib是受MATL ...
- python画散点图类型-绘制python中的线和散点图
我目前正在从Coursera( https://www.coursera.org/learn/ml-foundations/lecture/6wD6H/visualizing-predictions- ...
- 如何使用python画出好看的K线图
tushare ID:468684 一.安装mplfinance库 画K线蜡烛图,使用python的mplfinance库比较方便 安装:pip install mplfinance mplfinan ...
- 如何用Python的pyecharts库绘制K线图
01 K线图 一.概念 股市及期货市场中的K线图的画法包含四个数据,即开盘价.最高价.最低价.收盘价,所有的K线都是围绕这四个数据展开,反映大势的状况和价格信息.如果把每日的K线图放在一张纸上,就能得 ...
- python画k线图_一步一步教你用Python画出专业的K线图
漂亮的界面是量化程序的脸面,直观专业的界面能帮助我们了解股票的走势和形象地展示量化交易的结果.本文介绍如何使用matplotlib做出专业的K线图和展示各种技术指标: matplotlib是受MATL ...
最新文章
- flume采集最简demo
- 移动端浏览器body的overflow:hidden并没有什么作用
- 一切从用户的需求与体验出发
- U94222-循环往复【tarjan,DAGdp】
- elementUI组件el-dropdown - 踩坑篇
- 258. Move 0s To The End I -- Laicode
- 一个野生程序员的真实自述:我是如何从数学专业学渣入坑程序员的
- Rollup 插件开发牛刀小试
- linux上系统烧录工具,烧录操作系统安装光盘镜像到 U 盘的方法
- 想不想修真鸿蒙秘术,想不想修真鸿蒙秘诀怎么得 揭开想不想修真秘诀真面目...
- BIM建模助手上线一周,有哪些BUG被用户找到?
- 千纸鹤(小纸片)全套源码
- 【​观察】“数字广东”背后的力量 腾讯云创新政务服务新模式
- 研究生如何发表论文必读
- cmd 命令行执行 Python 脚本
- 小白渗透0-1:BlackMarket靶场渗透记录
- 什么是计算机集中管理,什么如何的是集中管理和集中管理集群创建?
- 万互技术浅谈为什么完美的芭比,非要朝着不完美的方向努力?
- 基于Tushare数据库统计混合型基金前十大重仓股持仓变化
- jar调用dll文件提示找不到指定的模块Unable to load library