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

发布于 2024-12-02 13:19:00 字数 221 浏览 1 评论 0 原文

我正在 Android 上使用 IP 网络摄像头程序,并通过 WiFi 在我的电脑上接收它。我想要的是在 Visual Studio、C++ 中使用 opencv 来获取视频流,有一个选项可以通过以下 URL 获取 MJPG 流: http://MyIP:port/videofeed 如何使用opencv得到它?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

以为你会在 2024-12-09 13:19:00

老问题,但我希望这可以帮助别人(与我的回答相同)

OpenCV 需要其 VideoCapture 参数的文件扩展名,
即使并不总是必要的(就像您的情况一样)。

您可以通过传入一个以以下结尾的虚拟参数来“欺骗”它
mjpg 扩展名:

所以也许可以尝试:

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

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")
静水深流 2024-12-09 13:19:00

安装 IP 摄像头适配器 并将其配置为捕获视频流。然后安装ManyCam,您将在相机部分看到“MPEG Camera”。(如果您转到有关如何为 Skype 设置 IPWebCam 的链接)
现在您可以像通过 openCV 访问网络摄像头一样访问您的 MJPG 流。我用 OpenCV 2.2 + QT 尝试过,效果很好。
认为这有帮助。

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.

绝影如岚 2024-12-09 13:19:00

我做了一个肮脏的补丁,使 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);

by

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

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

应该可以。希望有帮助。

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.

梦言归人 2024-12-09 13:19:00

这就是解决方案(我在 Android 上使用 IP 网络摄像头):

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

我无法发表评论,所以我发布新帖子。在原始答案中是一个错误 - 在虚拟之前使用 / 。感谢您的解决方案。

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.

琴流音 2024-12-09 13:19:00

我的工作示例

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文