opencv videocapture can't open MJPEG stream

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

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

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.

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?

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 $@ $< 

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

thank you.

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:

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

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 

run 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 

回答1:

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 .. 

you get something like:

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

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 

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 

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

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 

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!