如何获得MJPG流视频从android IPWebcam使用opencv

How to get MJPG stream video from android IPWebcam using opencv

本文关键字:android IPWebcam 使用 opencv 视频 何获得 MJPG      更新时间:2023-10-16

我在android上使用IP摄像头程序,并通过WiFi在我的PC上接收它。我想要的是在Visual Studio, c++中使用opencv来获得视视流,有一个选项可以通过以下URL获得MJPG流:http://MyIP:port/videofeed如何使用opencv获得它?

老问题,但我希望这能帮助别人(和我在这里的答案一样)

OpenCV期望它的videoccapture参数的文件名扩展名,即使不总是必要的(就像你的情况)。

你可以通过传递一个以。结尾的虚拟参数来"欺骗"它mjpg扩展:

不妨试试:

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

安装IP摄像机适配器并配置为捕获视频流。然后安装ManyCam,你会在相机部分看到"MPEG相机"。(如果你打开如何为skype设置IPWebCam的链接,你会看到相同的说明)现在你可以通过openCV访问你的MJPG流,就像一个网络摄像头一样。我用OpenCV 2.2 + QT尝试了这个,效果很好。

我做了一个肮脏的补丁使openCV与android ipWebcam一起工作:

在文件OpenCV-2.3.1/modules/highgui/src/cap_ffmpeg_impl.hpp

在函数bool CvCapture_FFMPEG::open(const char* _filename)

替换:

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

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

和评论:

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

应该可以。

这就是解决方案(我在android上使用IP Webcam):

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

我不能评论,所以我发布新的帖子。在原来的答案是一个错误-使用/前哑巴。

我的工作例子

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

用vlc从网络摄像头广播mjpeg,如何描述在http://tumblr.martinml.com/post/2108887785/how-to-broadcast-a-mjpeg-stream-from-your-webcam-with