wave2: fix opencv dll load fail from library directory
This commit is contained in:
parent
e3fdca4ac2
commit
8e55124158
@ -25,7 +25,7 @@ public class SEApplication {
|
|||||||
|
|
||||||
System.setProperty("jna.library.path", combinedPath);
|
System.setProperty("jna.library.path", combinedPath);
|
||||||
// 如果 OpenCV 使用的是标准 JNI (System.loadLibrary),可能还需要设置 java.library.path
|
// 如果 OpenCV 使用的是标准 JNI (System.loadLibrary),可能还需要设置 java.library.path
|
||||||
System.setProperty("java.library.path", opencvPath);
|
System.setProperty("opencv.library.path", opencvPath);
|
||||||
SpringApplication.run(SEApplication.class, args);
|
SpringApplication.run(SEApplication.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.io.File;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -136,7 +137,22 @@ public class JmImageController {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
static {
|
static {
|
||||||
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
//System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
||||||
|
//加载 OpenCV (强制使用绝对路径加载,解决 UnsatisfiedLinkError)
|
||||||
|
String openCvDll = System.getProperty("opencv.library.path") + File.separator + Core.NATIVE_LIBRARY_NAME + ".dll";
|
||||||
|
try {
|
||||||
|
File dllFile = new File(openCvDll);
|
||||||
|
if (dllFile.exists()) {
|
||||||
|
// 注意:必须使用 System.load() 加载绝对路径
|
||||||
|
System.load(dllFile.getAbsolutePath());
|
||||||
|
System.out.println("SUCCESS: OpenCV loaded from -> " + dllFile.getAbsolutePath());
|
||||||
|
} else {
|
||||||
|
System.err.println("ERROR: OpenCV DLL not found at -> " + openCvDll);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
System.err.println("CRITICAL: Failed to load OpenCV: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@IgnoreAuth
|
/*@IgnoreAuth
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user