1. 环境搭建。

opencv官网,往下拉。

java 搭建opencv环境进行图片处理

 

java 搭建opencv环境进行图片处理

 

 java 搭建opencv环境进行图片处理

 在opencv\build\java\以及opencv\build\java\x64下提取jar包以及动态库。

windows : dll

linux : so

mac : dylib

java 搭建opencv环境进行图片处理

 

 

<dependency>
<groupId>org</groupId>
<artifactId>opencv</artifactId>
<scope>system</scope>
<systemPath>${project.basedir}\src\main\resources\lib\opencv\opencv-440.jar</systemPath>
</dependency>


class DemoApplicationTests {
public void testOpencv() throws Exception {
// 解决awt报错问题
System.setProperty("java.awt.headless", "false");
System.out.println(System.getProperty("java.library.path"));
// 加载动态库
URL url = ClassLoader.getSystemResource("lib/opencv/opencv_java440.dll");
System.load(url.getPath());
// 读取图像
Mat image = imread("C:\\Users\\admin\\Pictures\\hello.jpg");
if (image.empty()) {
throw new Exception("image is empty");
}
imshow("Original Image", image);

// 创建输出单通道图像
Mat grayImage = new Mat(image.rows(), image.cols(), CvType.CV_8SC1);
// 进行图像色彩空间转换
cvtColor(image, grayImage, COLOR_RGB2GRAY);

imshow("Processed Image", grayImage);
imwrite("D://hello.jpg", grayImage);
waitKey();
}
}

 

相关文章:

  • 2022-01-01
  • 2022-12-23
  • 2021-11-30
  • 2021-04-12
  • 2022-01-01
  • 2021-08-26
猜你喜欢
  • 2021-11-30
  • 2022-12-23
  • 2022-02-11
  • 2021-06-18
  • 2021-07-12
  • 2022-02-27
相关资源
相似解决方案