How to get MJPG stream video from android IPWebcam using opencv

前端 未结 5 1502
暗喜
暗喜 2021-02-04 19:48

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 t

相关标签:
5条回答
  • 2021-02-04 20:09

    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.

    0 讨论(0)
  • 2021-02-04 20:13

    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.

    0 讨论(0)
  • 2021-02-04 20:19

    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.

    0 讨论(0)
  • 2021-02-04 20:27

    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")
    
    0 讨论(0)
  • 2021-02-04 20:32

    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

    0 讨论(0)
提交回复
热议问题