How to get MJPG stream video from android IPWebcam using opencv

落花浮王杯 提交于 2019-12-04 08:42:39

问题


I am using the IP Webcam program on android and receiving it on my PC by WiFi. What I want is to use opencv in Visual Studio, C++, to get that video stream, there is an option to get MJPG stream by the following URL: http://MyIP:port/videofeed How to get it using opencv?


回答1:


Old question, but I hope this can help someone (same as my answer here)

OpenCV expects a filename extension for its VideoCapture argument, even though one isn't always necessary (like in your case).

You can "trick" it by passing in a dummy parameter which ends in the mjpg extension:

So perhaps try:

VideoCapture vc;
ipCam.open("http://MyIP:port/videofeed/?dummy=param.mjpg")



回答2:


Install IP Camera Adapter and configure it to capture the videostream. Then install ManyCam and you'll see "MPEG Camera" in the camera section.(you'll see the same instructions if you go to the link on how to setup IPWebCam for skype) Now you can access your MJPG stream just like a webcam through openCV. I tried this with OpenCV 2.2 + QT and works well. Think this helps.




回答3:


I did a dirty patch to make openCV working with android ipWebcam:

In the file OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp

In the function bool CvCapture_FFMPEG::open( const char* _filename )

replace:

int err = av_open_input_file(&ic, _filename, NULL, 0, NULL);

by

AVInputFormat* iformat = av_find_input_format("mjpeg");
int err = av_open_input_file(&ic, _filename, iformat, 0, NULL);
ic->iformat = iformat;

and comment:

err = av_seek_frame(ic, video_stream, 10, 0);
if (err < 0)
{
    filename=(char*)malloc(strlen(_filename)+1);
    strcpy(filename, _filename);
    // reopen videofile to 'seek' back to first frame
    reopen();
}
else
{
    // seek seems to work, so we don't need the filename,
    // but we still need to seek back to filestart
    filename=NULL;
    int64_t ts    = video_st->first_dts;
    int     flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_BACKWARD;
    av_seek_frame(ic, video_stream, ts, flags);
}

That should work. Hope it helps.




回答4:


This is the solution (im using IP Webcam on android):

CvCapture* capture = 0;
capture = cvCaptureFromFile("http://IP:Port/videofeed?dummy=param.mjpg");

I am not able to comment, so im posting new post. In original answer is an error - used / before dummy. THX for solution.




回答5:


Working example for me

// OpenCVTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"

/**
* @function main
*/
int main( int argc, const char** argv )
{
    CvCapture* capture;
    IplImage* frame = 0;

    while (true)
    {
        //Read the video stream
        capture = cvCaptureFromFile("http://192.168.1.129:8080/webcam.mjpeg");
        frame = cvQueryFrame( capture );

        // create a window to display detected faces
        cvNamedWindow("Sample Program", CV_WINDOW_AUTOSIZE);

        // display face detections
        cvShowImage("Sample Program", frame);

        int c = cvWaitKey(10);
        if( (char)c == 27 ) { exit(0); }

    }

    // clean up and release resources
    cvReleaseImage(&frame);

    return 0;

}

Broadcast mjpeg from a webcam with vlc, how described at http://tumblr.martinml.com/post/2108887785/how-to-broadcast-a-mjpeg-stream-from-your-webcam-with



来源:https://stackoverflow.com/questions/7266256/how-to-get-mjpg-stream-video-from-android-ipwebcam-using-opencv

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