Python 官方文档:入门教程 => 点击学习
目录前言核心代码效果图前言 代码地址 序號名稱方法1圖像 添加文字Imgproc.putText2圖像 畫直綫Imgproc.line3圖像 畫橢圓Imgproc.ellipse4圖
代码地址
序號 | 名稱 | 方法 |
---|---|---|
1 | 圖像 添加文字 | Imgproc.putText |
2 | 圖像 畫直綫 | Imgproc.line |
3 | 圖像 畫橢圓 | Imgproc.ellipse |
4 | 圖像 畫矩形 | Imgproc.rectangle |
5 | 圖像 畫園 | Imgproc.circle |
6 | 圖像 填充 | Imgproc.fillConvexPoly |
package com.xu.OpenCV.canva;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.highgui.HighGui;
import org.opencv.imGCodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class canvas {
static {
String os = System.getProperty("os.name");
String type = System.getProperty("sun.arch.data.model");
if (os.toUpperCase().contains("windows")) {
File lib;
if (type.endsWith("64")) {
lib = new File("lib\\OpenCV-455\\x64\\" + System.mapLibraryName("opencv_java455"));
} else {
lib = new File("lib\\OpenCV-455\\x86\\" + System.mapLibraryName("opencv_java455"));
}
System.load(lib.getAbsolutePath());
}
}
public static void main(String[] args) {
fillPoly();
}
public static void putText() {
Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\5.jpeg");
Imgproc.putText(src, "test text", new Point(60, 60), Imgproc.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(0, 255, 0), 1, Imgproc.LINE_AA, false);
HighGui.imshow("putText", src);
HighGui.waiTKEy(1);
}
public static void line() {
Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\5.jpeg");
Imgproc.line(src, new Point(10, 50), new Point(100, 50), new Scalar(0, 0, 255), 1, Imgproc.LINE_AA);
HighGui.imshow("图像画线", src);
HighGui.waitKey(1);
}
public static void ellipse() {
Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\5.jpeg");
Imgproc.ellipse(src, new Point(200, 200), new Size(90, 50), 0, 0, 360, new Scalar(0, 0, 255), 1, Imgproc.LINE_AA);
HighGui.imshow("图像椭圆", src);
HighGui.waitKey(1);
}
public static void rectangle() {
Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\5.jpeg");
Imgproc.rectangle(src, new Point(10, 10), new Point(200, 200), new Scalar(0, 255, 0));
HighGui.imshow("图像矩形", src);
HighGui.waitKey(1);
}
public static void circle() {
Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\5.jpeg");
Imgproc.circle(src, new Point(50, 50), 20, new Scalar(0, 255, 0), 2, Imgproc.LINE_8);
HighGui.imshow("图像画圆", src);
HighGui.waitKey(1);
}
public static void fillPoly() {
Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\5.jpeg");
// 1
List<Point> points1 = new ArrayList<>();
points1.add(new Point(0, 100));
points1.add(new Point(50, 50));
points1.add(new Point(100, 100));
points1.add(new Point(150, 50));
points1.add(new Point(200, 100));
points1.add(new Point(100, 250));
Point[] array = points1.stream().toArray(Point[]::new);
MatOfPoint point = new MatOfPoint(array);
Imgproc.fillConvexPoly(src, point, new Scalar(0, 255, 0), Imgproc.LINE_AA);
// 2
List<Point> points2 = new ArrayList<>();
points2.add(new Point(100, 100));
points2.add(new Point(150, 50));
points2.add(new Point(200, 100));
Imgproc.fillConvexPoly(src, new MatOfPoint(points2.stream().toArray(Point[]::new)), new Scalar(0, 255, 0), Imgproc.LINE_AA);
HighGui.imshow("图像填充", src);
HighGui.waitKey(1);
}
}
到此这篇关于Java OpenCV图像处理之图形与文字绘制的文章就介绍到这了,更多相关Java OpenCV绘制图形 文字内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: JavaOpenCV图像处理之图形与文字绘制
本文链接: https://www.lsjlt.com/news/140456.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0