OpenCV无法加载动态Web项目的库 [英] OpenCV unable to load library for a dynamic web project
问题描述
我正在准备一个有关人脸识别的Java Web项目.我正在使用OpenCV 2.4.7的Java库.当我从servlet调用FaceDetector类时,它给出了错误-
I am preparing a java web project on face recognition.I am using java library of opencv 2.4.7. when I am calling FaceDetector class from a servlet, it gives error-
java.lang.UnsatisfiedLinkError:java.library.path中没有opencv_java247 java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886) java.lang.Runtime.loadLibrary0(Runtime.java:849) java.lang.System.loadLibrary(System.java:1088) Models.NewFaceDetector.(NewFaceDetector.java:24) Servlets.helloServlet.doPost(helloServlet.java:108) javax.servlet.http.HttpServlet.service(HttpServlet.java:647) javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
java.lang.UnsatisfiedLinkError: no opencv_java247 in java.library.path java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886) java.lang.Runtime.loadLibrary0(Runtime.java:849) java.lang.System.loadLibrary(System.java:1088) Models.NewFaceDetector.(NewFaceDetector.java:24) Servlets.helloServlet.doPost(helloServlet.java:108) javax.servlet.http.HttpServlet.service(HttpServlet.java:647) javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
此代码在控制台Java项目中运行良好. Servlet代码是-
This code is working perfectly in console java project. Servlet Code is-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();
Part name=request.getPart("NameBox");
Part img=request.getPart("Img");
String filename=getFileName(img);
InputStream is=img.getInputStream();
int i=is.available();
byte[] b=new byte[i];
is.read(b);
String path="E:/temp/"+filename;
FileOutputStream os=new FileOutputStream(path);
os.write(b);
os.close();
is.close();
FaceDetector fd=new FaceDetector();
fd.getFaces(path);
}
我的脸部检测器课程是-
and my face detector class is-
public class FaceDetector {
static{ System.loadLibrary("opencv_java247"); }
public List<Mat> getFaces(String url) throws MalformedURLException, IOException
{
List<Mat>faces=new ArrayList();
Mat image = Highgui.imread(url);
//code...
}
我给出了打开cv dll的路径--Djava.library.path ="C:\ Users \ vivek \ Documents \ NetBeansProjects \ TrendFaceRecognizer \ src \ java \ data"
I gave the path to open cv dll- -Djava.library.path="C:\Users\vivek\Documents\NetBeansProjects\TrendFaceRecognizer\src\java\data"
我不知道我在做什么.
推荐答案
如何解决java.lang.UnsatisfiedLinkError
用户应检查是否-
How to resolve java.lang.UnsatisfiedLinkError
User should check whether-
-
System.loadLibrary传递了错误的参数:
System.loadLibrary is passed an incorrect parameter:
-
Windows:要加载Name.dll,必须将Name传递给loadLibrary方法.
Windows: To load Name.dll, Name is passed to the loadLibrary method.
AIX,HP-UX,Solaris,Linux:要加载libName.so或libName.a,必须传递libName
到loadLibrary方法
AIX, HP-UX, Solaris, Linux: To load libName.so or libName.a, libName is passed
to the loadLibrary method
本地库已加载-
如果本机库已由相同的应用程序加载了
应用程序尝试再次加载它,这可能导致此错误.
If the native library was already loaded by an application and the same
application tries to load it again, this can cause this error.
参考:调试java.lang.UnsatisfiedLinkError
在您的情况下, 1)检查您的servlet(可能在不同的程序包中)是否可以访问\ TrendFaceRecognizer \ src \ java \ data
and in your case, 1)check whether your servlet(might be in different package) that could access the dll in \TrendFaceRecognizer\src\java\data
2)代替System.loadLibrary("opencv_java247")尝试使用System.load("opencv_java247").似乎loadLibrary使用默认路径,而负载将使用绝对路径
2)Instead System.loadLibrary("opencv_java247") try using System.load("opencv_java247") .It seems loadLibrary uses default path and load will use absolute path
这篇关于OpenCV无法加载动态Web项目的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!