Eclipse中的OpenCV Java绑定链接错误
在Eclipse(Java10,MacOS)中使用java+opencv运行我的项目时出现以下错误: 工作正常,只有在从Eclipse运行时才会出现问题。Spring boot应用程序启动显示没有问题(基于Tomcat的web应用程序),执行下面的代码时出现错误 代码部分:Eclipse中的OpenCV Java绑定链接错误,java,eclipse,maven,opencv,Java,Eclipse,Maven,Opencv,在Eclipse(Java10,MacOS)中使用java+opencv运行我的项目时出现以下错误: 工作正常,只有在从Eclipse运行时才会出现问题。Spring boot应用程序启动显示没有问题(基于Tomcat的web应用程序),执行下面的代码时出现错误 代码部分: @Service public class PrepareImageService { static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
@Service
public class PrepareImageService {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public ScanResult prepare(InputStream input, MediaType mediaType) throws IOException {
ScanResult scanResult = new ScanResult();
scanResult.setContentType(mediaType);
scanResult.getImages().put(IMG_TYPE.ORIGINAL, StreamUtils.copyToByteArray(input));
MatOfByte inputBuffer = new MatOfByte(scanResult.getImages().get(IMG_TYPE.ORIGINAL));
Mat orig = Imgcodecs.imdecode(inputBuffer, Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
// ... skipped
return scanResult;
}
}
运行本机库时,需要配置库的位置。在这种情况下,您需要java包装器(jar和dylib)和opencv库
-Djava.library.path=/usr/local/Cellar/opencv/4.1.1_2/share/java/opencv4:/usr/local/Cellar/opencv/4.1.1_2/lib
根据opencv的安装方式,路径可能会有所不同。但您需要这两个文件夹:java共享库和opencv库。需要您的代码。.添加了代码段此链接可能会有所帮助。maven config fork出现相同错误=true
@Service
public class PrepareImageService {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public ScanResult prepare(InputStream input, MediaType mediaType) throws IOException {
ScanResult scanResult = new ScanResult();
scanResult.setContentType(mediaType);
scanResult.getImages().put(IMG_TYPE.ORIGINAL, StreamUtils.copyToByteArray(input));
MatOfByte inputBuffer = new MatOfByte(scanResult.getImages().get(IMG_TYPE.ORIGINAL));
Mat orig = Imgcodecs.imdecode(inputBuffer, Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
// ... skipped
return scanResult;
}
}
-Djava.library.path=/usr/local/Cellar/opencv/4.1.1_2/share/java/opencv4:/usr/local/Cellar/opencv/4.1.1_2/lib