opencv videocapture无法打开MJPEG流 [英] opencv videocapture can't open MJPEG stream

查看:652
本文介绍了opencv videocapture无法打开MJPEG流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

the Opencv 2.4.9: VideoCapture cann't open the 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.并且我进行了很多搜索,例如,并尝试了

I can see the video use gst-launch. and I have searched a lot,like this and tried the fifo like this,but still cann't open it.

然后我想调试到opencv,用CMAKE_BUILD_TYPE = DEBUG编译opencv,但是我的GDB无法进入开放功能.知道吗?

then I want to debug into opencv,compile opencv with CMAKE_BUILD_TYPE=DEBUG, but my GDB just cann't step into the open function.any idea?

我的makefile:

my makefile:

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中打开视频.

by the way, I am in opensue13.1, with the same code,I can open the video in win 7.

谢谢.

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

Update now I can step into some function like:imshow,waitKey, but I can not step into others like:imread,namedWindow,it shows:

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:

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

我的makefile:

my makefile:

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

推荐答案

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

opencv videocapture can't open MJPEG stream,because I don't compile opencv with FFMPEG support. detail: when cmake the 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.我应该在我的机器(Opensuse 13.1)中安装libffmpeg-devel,然后pkg-config可以找到FFMPEG,您可以使用以下命令进行检查:

so the cmake don't find the FFMPEG. I should install libffmpeg-devel in my machine(Opensuse 13.1),then the pkg-config can find FFMPEG,you can check with this:

pkg-config --list-all | grep libavcodec

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

then run the above cmake command again, I get:

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

制作,我得到了能够打开MJPG_Streamer的opencv视频捕捉.

make,and I get the opencv videocapture able to open MJPG_Streamer.

PS:找出原因,我编译了一个调试版本的opencv,并进入了VideoCapture的open函数,并在"opencv-2.4.9/modules/highgui/src/cap"中的icvInitFFMPEG()的构造函数中. cpp:

PS:to find the reason,I compile a debug version opencv,and step into the VideoCapture's open function,and in the construction function of icvInitFFMPEG() in " 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.

it just step over these code,so I know because I don't have the HAVE_FFMPEG defined in compiling process.

这篇关于opencv videocapture无法打开MJPEG流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆