我正在尝试在servlet中使用OpenCV,每次运行servlet时都会弹出此错误。这是相同的堆栈跟踪:
SEVERE: Servlet.service() for servlet [com.patternrecognition.preprocessing.Preprocessing] in context with path **[/ImagePreprocessing] threw exception [Servlet execution threw an exception] with root cause
java.lang.UnsatisfiedLinkError: org.opencv.highgui.Highgui.imread_0(Ljava/lang/String;I)J
at org.opencv.highgui.Highgui.imread_0(Native Method)
at org.opencv.highgui.Highgui.imread(Highgui.java:309)**
at com.patternrecognition.preprocessing.Preprocessing.smooth(Preprocessing.java:168)
at com.patternrecognition.preprocessing.Preprocessing.startPreprocessing(Preprocessing.java:56)
at com.patternrecognition.preprocessing.Preprocessing.doGet(Preprocessing.java:46)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
我的项目时间不多了。请帮忙。
答案 0 :(得分:1)
我通过使用方法“imread”读取的图像的绝对路径解决了这个问题。因为它是一个Web项目,所以它没有采用默认项目文件夹的相对路径。
我在做:
Highgui.imread("img_perspective.png", Highgui.CV_LOAD_IMAGE_GRAYSCALE);
我把它改为:
Highgui.imread("C:/Users/ImagePreprocessing/WebContent/WEB-INF/img_perspective.png", Highgui.CV_LOAD_IMAGE_GRAYSCALE);
希望它有所帮助。
答案 1 :(得分:0)
您不满意的链接错误很可能是由于服务器无法理解文件系统上存在相应的共享对象的位置。
您需要拥有opencv jar,opencv java共享对象以及JVM可用的opencv共享库。
这取决于您的容器和操作系统。
您可能希望查看设置" java.library.path"或LD_LIBRARY_PATH。