1
votes

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: 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)

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...
}

I gave the path to open cv dll- -Djava.library.path="C:\Users\vivek\Documents\NetBeansProjects\TrendFaceRecognizer\src\java\data"

I don't know what's wrong I am doing.

1

1 Answers

1
votes

How to resolve java.lang.UnsatisfiedLinkError
User should check whether-

  • System.loadLibrary is passed an incorrect parameter:

    • Windows: To load Name.dll, Name is passed to the loadLibrary method.

      AIX, HP-UX, Solaris, Linux: To load libName.so or libName.a, libName is passed
      to the loadLibrary method

  • Native library is already loaded-

    If the native library was already loaded by an application and the same
    application tries to load it again, this can cause this error.

  • Native Library is not present in java.library.path or
    LD_LIBRARY_PATH

Reference:Debugging java.lang.UnsatisfiedLinkError

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)Instead System.loadLibrary("opencv_java247") try using System.load("opencv_java247") .It seems loadLibrary uses default path and load will use absolute path