OpenCV帧抓取器捕获图像错误

时间:2015-11-19 17:27:35

标签: java jsp opencv servlets

我正在使用OpenCV从在线Ivideon云视频流中捕获图像。 我得到了不满意的错误:
这是我的Stack Trace

Nov 19, 2015 10:36:17 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [CaptureImage] in context with path   [/ImageCapture] threw exception [Servlet execution threw an exception] with root cause
java.lang.UnsatisfiedLinkError: no tbb in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:593)
at com.googlecode.javacpp.Loader.load(Loader.java:481)
at com.googlecode.javacpp.Loader.load(Loader.java:431)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:127)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.googlecode.javacpp.Loader.load(Loader.java:453)
at com.googlecode.javacv.cpp.opencv_imgproc.<clinit>(opencv_imgproc.java:96)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.googlecode.javacpp.Loader.load(Loader.java:453)
at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:91)
at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:94)
at com.image.CaptureImage.doGet(CaptureImage.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

我正在使用带有div标签的jsp页面,其中包含来自Ivideon Cloud Streaming的嵌入式URL。 以下是我的ImageLoad.jsp内容:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Video</title>
</head>
<body>
<div class="iv-embed" style="margin:0 auto;padding:0;border:0;width:642px;"><div class="iv-v" style="display:block;margin:0;padding:1px;border:0;background:#000;"><iframe class="iv-i" style="display:block;margin:0;padding:0;border:0;" src="//open.ivideon.com/embed/v2/?server=200-66de71ac6bb817f2356a7eb6388b8ff4&amp;camera=0&amp;width=&amp;height=&amp;lang=en" width="640" height="480" frameborder="0" allowfullscreen></iframe></div><div class="iv-b" style="display:block;margin:0;padding:0;border:0;"><div style="float:right;text-align:right;padding:0 0 10px;line-height:10px;"><a class="iv-a" style="font:10px Verdana,sans-serif;color:inherit;opacity:.6;" href="http://www.ivideon.com/" target="_blank">powered by Ivideon</a></div><div style="clear:both;height:0;overflow:hidden;">&nbsp;</div><script src="http://open.ivideon.com/embed/v2/embedded.js"></script></div></div>
<div id="2">
 <form action="grabImage" method="Get">
  <input type="submit" name="submit" value="Take Picture"/>
 </form>
</div>
</body>
</html>

以下是servlet CaptureImage.java的内容:

      package com.image;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import org.opencv.highgui.Highgui;

import java.io.*;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.DatatypeConverter;

import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
/**
 * Servlet implementation class CaptureImage
 */
@WebServlet("/CaptureImage")
public class CaptureImage extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public CaptureImage() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        try {
            //System.setProperty(“"java.library.path", );
            //System.loadLibrary("opencv-249");
            //System.setProperty("java.library.path",";C:/opencv/opencv/build/x64/vc11/bin");
            //System.out.println("not working7"+System.getProperty("java.library.path"));
            System.out.println("dfddfdfdfd");
         OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(
                    "http://10.217.83.59:8080/video?dummy=param.mjpg");
            System.out.println("after");
            //System.out.println(grabber+"hcsdf");
            grabber.setFormat("mjpeg");
            System.out.println("1");
            grabber.start();
            System.out.println("2");
            IplImage frame = grabber.grab();
            System.out.println("3");

            // convert the image
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            System.out.println("frame capturing");
            ImageIO.write(frame.getBufferedImage(), "png", baos);
            System.out.println("frame captured");
            grabber.stop();
            System.out.println("baos.toByteArray() " + baos.toByteArray());
            System.out.println("baos.toByteArray().length "
                    + baos.toByteArray().length);
            String data = DatatypeConverter.printBase64Binary(baos
                    .toByteArray());
            String imageString = "data:image/png;base64," + data;

            PrintWriter out = response.getWriter();
            out.write(imageString);
            out.flush();
            out.close();

        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }


}

我正在Tomcat 7.0 Server上部署它。 我已经添加了javacv,open-cv jar来构建路径。 并将open cv提取到C:/并且还改变了路径环境变量。

感谢任何帮助?

0 个答案:

没有答案