一、下载OpenCV、
下载链接:Releases - OpenCV

下载到指定目录后双击即可安装(正常下载过程)。
二、查看文件目录
1、找到opencv-4100.jar



找到opencv-4100.jar,这个是我们需要加载的包。
opencv-460.jar是给java操作openvc的程序包
2、找到opencv_java4100.dll

二、Java实现生成灰度图demo
1、建一个maven项目
2、在resources中加入配置


添加依赖进项目中
3、配置maven
XML
<dependency>
<groupId>com.opencv</groupId>
<artifactId>opencv</artifactId>
<version>4100</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/lib/opencv/opencv-4100.jar</systemPath>
</dependency>
我的配置如下图:

4、编写代码生成灰度图
java
public class test_ikun {
public static void main(String[] args) {
//加载 opencv_javaXX.dll
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
//测试图片地址
String imgPath = "./src/main/java/com/bluefoxyu/images/ikun.jpg";
//读取图片
Mat img = Imgcodecs.imread(imgPath);
//生成灰度图
Mat gray = new Mat();
Imgproc.cvtColor(img,gray, Imgproc.COLOR_BGR2GRAY);
//保存图片
Imgcodecs.imwrite("./src/main/java/com/bluefoxyu/results/images/result.png", gray);
}
}
5、出现报错
不出意外的话会出现下面的报错,这个报错我也解决了很久。
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java4100 in java.library.path

报错的大概意思就是opencv_java4100没有在jdk中。
6、解决问题
将opencv_java4100.dll 复制到自己下载的jdk的bin目录中

7、生成灰度图
运行demo,成功生成灰度图

效果如下:


还有一种方式可以将opencv导入项目中不会报错,感兴趣可以参考这个博主的博客:在Java中使用OpenCV_java使用opencv-CSDN博客
opencv新手小白,有大佬有什么资料希望可以在评论区分享分享呀~~~