在OpenCV 3.2和Java中未检测到IP摄像机

时间:2018-12-09 18:49:11

标签: java opencv

任何人都可以在Java的开放式简历中使用IP摄像机。我使用了下面的代码,该代码对于网络摄像头效果很好。但是当我尝试使用网络摄像机时却无法正常工作

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import javax.imageio.ImageIO;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfByte;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
import org.opencv.videoio.VideoCapture;

import com.amazonaws.services.rekognition.model.Image;
import com.amazonaws.util.IOUtils;
import com.wso2telco.rnd.ui.DashBoard;
import com.wso2telco.rnd.ui.UI;

public class TestIPCamera {

private static final long SLEEP_TIME = 1000;
private static VideoCapture camera;
private static FaceComparer comparer;
private static UI ui;
private static DashBoard dashUi;

public static void main(String args[]) {

    comparer = new FaceComparer();

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    //nu.pattern.OpenCV.loadLocally();
    System.loadLibrary("opencv_java320");

    camera = new VideoCapture();
    camera.open("http://192.168.1.2:8080/video?video=x.mpjeg");
    System.out.println(camera.isOpened());
    while(!camera.isOpened()) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    if (!camera.isOpened()) {
        System.out.println("Camera Error");
    } else {
        System.out.println("Camera Ready");
        ui = new UI();
        dashUi = new DashBoard();

    }
    while(true){
        runImage();
    }
}

我尝试了其他主题中给出的许多建议,但找不到该问题的具体答案。

1 个答案:

答案 0 :(得分:0)

尝试了其他选项之后,最后我通过安装Open CV 3.4.1版本解决了该问题。

当您安装open cv时,它会显示如下输出。在那里,您可以检查 FFMPEG:是否表示为 NO 。此配置将停止使用代码中的IP摄像机的代码。为避免这种错误配置,您需要使用 -D WITH_FFMPEG = ON .. 安装Open CV以解决此问题

    --   OpenCV modules:
--     To be built:                 core flann hdf imgproc ml objdetect phase_unwrapping photo plot reg surface_matching video xphoto bgsegm dnn face freetype fuzzy img_hash imgcodecs shape videoio xobjdetect highgui superres ts bioinspired dpm features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo structured_light tracking videostab xfeatures2d ximgproc aruco java optflow stitching python3
--     Disabled:                    world contrib_world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev python2 viz cnn_3dobj cvv dnn_modern matlab sfm
-- 
--   GUI: 
--     QT:                          NO
--     GTK+ 3.x:                    YES (ver 3.20.9)
--     GThread :                    YES (ver 2.50.2)
--     GtkGlExt:                    NO
--     OpenGL support:              NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.25)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6)
--     JPEG 2000:                   /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
--     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
--     GDAL:                        NO
--     GDCM:                        NO
-- 
--   Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.4)
--     FFMPEG:                      NO
--       avcodec:                    NO
--       avformat:                   NO
--       avutil:                     NO
--       swscale:                    NO
--       avresample:                 NO
--     GStreamer:                   NO
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     OpenNI2:                     NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     Aravis SDK:                  NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    NO/YES
--     XIMEA:                       NO
--     Xine:                        NO
--     Intel Media SDK:             NO
--     gPhoto2:                     NO
-- 
--   Parallel framework:            TBB (ver 4.4 interface 9005)
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Use Intel IPP:               2017.0.2 [2017.0.2]
--                at:               /home/hao/opencv-3.3.0/build/3rdparty/ippicv/ippicv_lnx
--     Use Intel IPP IW:            prebuilt binaries (2017.0.2)
--     Use Intel IPP Async:         NO
--     Use VA:                      NO
--     Use Intel VA-API/OpenCL:     NO
--     Use Lapack:                  NO
--     Use Eigen:                   YES (ver 3.3.4)
--     Use Cuda:                    NO
--     Use OpenCL:                  YES
--     Use OpenVX:                  NO
--     Use custom HAL:              NO
-- 
--   OpenCL:                        <Dynamic loading of OpenCL library>
--     Include path:                /home/hao/opencv-3.3.0/3rdparty/include/opencl/1.2
--     Use AMDFFT:                  NO
--     Use AMDBLAS:                 NO
-- 
--   Python 2:
--     Interpreter:                 (ver 2.7.12)
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.5.2)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.5m.so (ver 3.5.2+)
--     numpy:                       /usr/local/lib/python3.5/dist-packages/numpy/core/include (ver 1.12.0)
--     packages path:               lib/python3.5/dist-packages
-- 
--   Python (for build):            
-- 
--   Java:
--     ant:                         /usr/bin/ant (ver 1.9.7)
--     JNI:                         /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
--     Java wrappers:               YES
--     Java tests:                  YES
-- 
--   Matlab:                        Matlab not found or implicitly disabled
-- 
--   Documentation:
--     Doxygen:                     NO
-- 
--   Tests and samples:
--     Tests:                       YES
--     Performance tests:           YES
--     C/C++ Examples:              YES
-- 
--   Install path:                  /usr/local
-- 
--   cvconfig.h is in:              /home/hao/opencv-3.3.0/build
--