我正在使用opencv在java中实现面部识别的Web应用程序。 当我运行面部识别代码时,我遇到了像
这样的错误java.lang.UnsatisfiedLinkError: Native Library F:\opencv\build\java\x86\opencv_java2411.dll already loaded in another classloader
我已经在互联网上做了几种可用的方法,例如检查是否加载了类,或者将system.loadlibrary作为静态块添加到环境变量的路径等等,但是在所有这些过程之后错误仍然存在于系统中。 / p>
does anyone has the solution for this problem i am able to run with this dll in desktop application but while running in web application the error comes
i am running this project using glassfish server on netbeans ide
public class FaceRecognition {
public static boolean loaded = false;
public void loadLib(){
System.out.println("loading library");
try {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}catch(Exception e){}
loaded = true;
}
public FaceRecognition() {
}
public void saveFaceRecognizedImage(File file){
try {
MatOfByte mem = new MatOfByte();
CascadeClassifier faceDetector = new CascadeClassifier(facerecog.FaceRecognition.class.getResource("haarcascade_frontalface_alt.xml").getPath().substring(1));
MatOfRect faceDetections = new MatOfRect();
BufferedImage bi = ImageIO.read(file);
Mat frame = bufferedImageToMat(bi);
Rect rectcrop = null;
faceDetector.detectMultiScale(frame, faceDetections);
for (Rect rect : faceDetections.toArray()) {
System.out.println("ttt");
Core.rectangle(frame, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255,0));
rectcrop = new Rect(rect.x,rect.y,120,120);
}
try {
Mat imgrr = new Mat(frame,rectcrop);
Highgui.imwrite(file.getAbsolutePath(), imgrr);
// BufferedImage image = ImageIO.read(file);
// BufferedImage scaled = getScaledInstance(
// image, 120,120, RenderingHints.VALUE_INTERPOLATION_BILINEAR, true);
// writeJPG(scaled, new FileOutputStream(file.getAbsolutePath()), 0.85f);
}catch(Exception e){}
// Highgui.imencode(".bmp", frame, mem);
// Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));
// BufferedImage buff = (BufferedImage) im;
// ImageIO.write(buff,"jpg",file);
} catch (IOException ex) {
Logger.getLogger(FaceRecognition.class.getName()).log(Level.SEVERE, null, ex);
}
}
答案 0 :(得分:1)
每个类加载器都管理自己的一组本机库。 相同 JNI本机库无法加载到多个类加载器中。 这样做会导致抛出UnsatisfiedLinkError。例如, System.loadLibrary在用于加载时抛出UnsatisfiedLinkError 本机库分为两类加载器。
在应用程序服务器中,应用程序的每个实例都使用新的类加载器,因此,如果多个应用程序尝试加载相同的本机库,或者重新启动单个应用程序而不重新启动整个应用程序服务器,则会看到此错误。一些选择: