【问题标题】:opencv videocapture can't open MJPEG streamopencv videocapture 无法打开 MJPEG 流
【发布时间】:2014-10-25 07:13:25
【问题描述】:

Opencv 2.4.9:VideoCapture 无法打开 MJPG-streamer:

 VideoCapture cap;
 cap.open("http://127.0.0.1:8080/?action=stream&type=.mjpg");
 if (!cap.isOpened())  // if not success, exit program
{
    cout << "Cannot open the video cam" << endl;
    return -1;
}

我可以看到视频使用 gst-launch。我已经搜索了很多,比如this,并尝试了this之类的先进先出,但仍然无法打开它。

然后我想调试到opencv,用CMAKE_BUILD_TYPE=DEBUG编译opencv,但是我的GDB无法进入open函数。有什么想法吗?

我的生成文件:

OpencvDebugLibDir=/home/ry/lib
CFLAGS = -g -I$(OpencvDebugLibDir)/include/opencv -I$(OpencvDebugLibDir)
LIBS = $(OpencvDebugLibDir)/lib/*.so

target : main.cpp
    g++ $(CFLAGS) $(LIBS) -o $@ $<

顺便说一下,我是opensue13.1,同样的代码,win 7可以打开视频。

谢谢。

更新 现在我可以进入一些函数,例如:imshow,waitKey,但我不能进入其他函数,例如:imread,namedWindow,它显示:

29          image = cv::imread(name);
(gdb) s
std::allocator<char>::allocator (this=0x7fffffffdc7f)
    at /usr/src/debug/gcc-4.8.1-20130909/obj-x86_64-suse-linux/x86_64-suse-linux/libstdc++-v3/include/bits/allocator.h:113
113           allocator() throw() { }

test4.cpp:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, char** argv )
{

Mat image;
image = imread( "LinuxLogo.jpg", 1 );

if ( !image.data )
{
    printf("No image data \n");
    return -1;
}
namedWindow("Display Image", CV_WINDOW_AUTOSIZE );
imshow("Display Image", image);

waitKey(0);

return 0;
}

我的生成文件:

OpencvDebugLibDir=/home/ry/lib
CFLAGS=-g -I$(OpencvDebugLibDir)/include/opencv -I$(OpencvDebugLibDir)
LIBS=$(OpencvDebugLibDir)/lib

test4:test4.cpp
    g++ $(CFLAGS) -o $@ $<  -L$(LIBS) -lopencv_highgui -lopencv_core -Wl,-rpath=/home/ry/lib/lib

运行 gdb:

gdb test4 -d /home/ry/learn/opencv/install/OpenCV/opencv-2.4.9/modules/core/src -d /home/ry/learn/opencv/install/OpenCV/opencv-2.4.9/modules/highgui/src

【问题讨论】:

    标签: linux opencv video gdb


    【解决方案1】:

    opencv videocapture 无法打开 MJPEG 流,因为我没有编译支持 FFMPEG 的 opencv。 详情: 当cmake opencv时:

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=ON -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_OPENCL=ON -D WITH_CUDA=ON -D WITH_GTK=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D WITH_QT=ON -D WITH_OPENGL=ON -D BUILD_JPEG=ON -D BUILD_PNG=ON -D BUILD_JASPER=ON -D BUILD_ZLIB=ON -D WITH_JPEG=ON -D WITH_PNG=ON -D WITH_JASPER=ON -D WITH_ZLIB=ON -D WITH_OPENEXR=OFF ..
    

    你会得到类似的东西:

       FFMPEG:                      NO
    --       codec:                     NO
    --       format:                    NO
    --       util:                      NO
    --       swscale:                   NO
    --       gentoo-style:              NO
    

    所以 cmake 找不到 FFMPEG。我应该在我的机器上安装libffmpeg-devel(Opensuse 13.1),然后pkg-config可以找到FFMPEG,你可以用这个检查:

    pkg-config --list-all | grep libavcodec
    

    然后再次运行上面的cmake命令,我得到:

    FFMPEG:                      YES
    --       codec:                     YES (ver 55.69.100)
    --       format:                    YES (ver 55.48.100)
    --       util:                      YES (ver 52.92.100)
    --       swscale:                   YES (ver 2.6.100)
    --       gentoo-style:              YES
    

    make,我得到了能够打开 MJPG_Streamer 的 opencv videocapture。

    PS:为了找到原因,我编译了一个debug版本的opencv,进入VideoCapture的open函数,在“opencv-2.4.9/modules/highgui/src/cap. cpp":

     #elif defined HAVE_FFMPEG
        icvCreateFileCapture_FFMPEG_p = (CvCreateFileCapture_Plugin)cvCreateFileCapture_FFMPEG;
        icvReleaseCapture_FFMPEG_p = (CvReleaseCapture_Plugin)cvReleaseCapture_FFMPEG;
        icvGrabFrame_FFMPEG_p = (CvGrabFrame_Plugin)cvGrabFrame_FFMPEG;
        icvRetrieveFrame_FFMPEG_p = (CvRetrieveFrame_Plugin)cvRetrieveFrame_FFMPEG;
        icvSetCaptureProperty_FFMPEG_p = (CvSetCaptureProperty_Plugin)cvSetCaptureProperty_FFMPEG;
        icvGetCaptureProperty_FFMPEG_p = (CvGetCaptureProperty_Plugin)cvGetCaptureProperty_FFMPEG;
        icvCreateVideoWriter_FFMPEG_p = (CvCreateVideoWriter_Plugin)cvCreateVideoWriter_FFMPEG;
        icvReleaseVideoWriter_FFMPEG_p = (CvReleaseVideoWriter_Plugin)cvReleaseVideoWriter_FFMPEG;
        icvWriteFrame_FFMPEG_p = (CvWriteFrame_Plugin)cvWriteFrame_FFMPEG;
    #endif
    

    它只是跳过这些代码,所以我知道因为我没有在编译过程中定义 HAVE_FFMPEG。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-22
      • 2014-09-02
      • 2021-09-10
      • 2016-02-01
      • 1970-01-01
      • 2012-04-30
      • 2019-05-18
      • 2017-11-08
      相关资源
      最近更新 更多