views:

6215

answers:

3

I'm using openCV 1.1pre1 under Windows. I have a network camera and I need to grab frames from openCV. That camera can stream a standard mpeg4 stream over RTSP or mjpeg over http. I've seen many threads talking about using ffmpeg with openCV but I cannot make it work.

How I can grab frames from an IP camera with openCV?

Thanks

Andrea

+1  A: 

Use ffmpeglib to connect to the stream.

These functions may be useful. But take a look in the docs

av_open_input_stream(...);
av_find_stream_info(...);
avcodec_find_decoder(...);
avcodec_open(...);
avcodec_alloc_frame(...);

You would need a little algo to get a complete frame, which is available here

http://www.dranger.com/ffmpeg/tutorial01.html

Once you get a frame you could copy the video data (for each plane if needed) into a IplImage which is an OpenCV image object.

You can create an IplImage using something like...

IplImage *p_gray_image = cvCreateImage(size, IPL_DEPTH_8U, 1);

Once you have an IplImage, you could perform all sorts of image operations available in the OpenCV lib

Indeera
I've seen in many threads that ffmpeg is already included and used inside openCV, is this right?Maybe I need to recompile openCV with ffgmpeg support? In this case how I can do this under windows?Thanks
Grifo
I'm not aware of this. However, ffmpeg is an application where as ffmpeglib is a library. If you are new to these please look at the dranger.com tutorials.
Indeera
+1  A: 

OpenCV can be compiled with FFMPEG support. From ./configure --help:

--with-ffmpeg     use ffmpeg libraries (see LICENSE) [automatic]

You can then use *cvCreateFileCapture_FFMPEG* to create a CvCapture with e.g. the URL of the camera's MJPG stream.

I use this to grab frames from an AXIS camera:

CvCapture *capture = 
    cvCreateFileCapture_FFMPEG("http://axis-cam/mjpg/video.mjpg?resolution=640x480&req_fps=10&.mjpg");
f3lix
Is it possible to configure openCV with ffmpeg support under Windows?
Grifo
A: 

I just do it like this:

CvCapture *capture = cvCreateFileCapture("rtsp://camera-address");

Also make sure this dll is available at runtime else cvCreateFileCapture will return NULL

opencv_ffmpeg200d.dll

The camera needs to allow unauthenticated access too, usually set via its web interface. MJPEG format worked via rtsp but MPEG4 didn't.

hth

Si

sipickles
Are you using OpenCV 2.0?
Grifo
The library version says that he is using openCV 2.0 - that's the `200` part in `opencv_ffmpeg200d.dll`
jamuraa