c++ - OpenCV 和 GoPro - VideoCapture 流中的空帧

标签 c++ opencv ffmpeg video-capture gopro

我有一台连接到视频采集卡 (AverMedia Game Broadcaster HD) 的 GoPro Hero 3+(黑色)。我只是想在 OpenCV 中获取视频流。使用罗技网络摄像头没有任何问题。使用的代码如下。

VideoCapture cap;
cap.open(0);

waitKey(300);

//cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
//cap.set(CV_CAP_PROP_FRAME_HEIGHT, 720);

if (cap.isOpened()){
    cout << "Cam identified" << endl;
}

namedWindow("dst", 1);

while (1){

Mat frame;

if (!cap.read(frame)) {
    std::cout << "Unable to read frame from video stream" << std::endl;
    continue;
}

imshow("dst", frame);

[...]

}

对于 GoPro,会发生以下情况:OpenCV 能够打开 VideoCapture(“已识别摄像头”)但无法读取任何帧(只有灰色屏幕和输出:“无法从视频流中读取帧”)。我还使用 frame.empty(); 进行了检查。

我知道视频采集卡工作正常,因为 Unity 打开带有 GoPro 流的 WebCamTexture 没有任何问题。我阅读了 OpenCv 中的编解码器问题,因此我已经尝试使用 FFMPEG 支持编译 OpenCV。现在可以显示 GoPro 录制的 MP4 视频,但仍然无法播放。

我使用 OpenCV 2.48、Windows 7 和 Visual Studio 2013。


编辑:这是 libVLC 解决方案的代码:

struct ctx
{
uint8_t* pixeldata;
std::mutex imagemutex;
};

static void display(void *data, void *id);
static void unlock(void *data, void *id, void *const *p_pixels);
static void *lock(void *data, void **p_pixels);

struct ctx ctx;

libvlc_instance_t *inst;
libvlc_media_player_t *mp;
libvlc_media_t *m;

int main(int argc, char* argv[])
{
    ctx.pixeldata = new uint8_t[1280 * 720 * 3];

    char const *vlc_argv[] =
    {
        "-vvv",
        "--no-audio", /* skip any audio track */
        "--no-xlib", /* tell VLC to not use Xlib */
    };

    int vlc_argc = sizeof(vlc_argv) / sizeof(*vlc_argv);
    inst = libvlc_new(vlc_argc, vlc_argv);

    const char *options[] =
    {
        ":dshow-vdev=AVerMedia HD Capture",
        ":dshow-adev=none",
        //":dshow-size=1280x720",
        ":dshow-fps=24",
        ":dshow-chroma=YUY2",
        ":dshow-video-input=1",
        ":dshow-video-output=1",
        ":dshow-aspect-ratio=16\:9",
        ":live-caching=80",
        NULL
    };

    m = libvlc_media_new_location(inst, "dshow://");
    for (const char **opt = options; *opt; opt++)
        libvlc_media_add_option(m, *opt);

    mp = libvlc_media_player_new_from_media(m);
    libvlc_media_release(m);
    libvlc_video_set_callbacks(mp, lock, unlock, display, &ctx);
    libvlc_video_set_format(mp, "RV24", 1280, 720, 1280 * 3);
    libvlc_media_player_play(mp);

    namedWindow("all", 1);

    Mat frame(720, 1280, CV_8UC3);

    while (1){

        ctx.imagemutex.lock();
        memcpy(gesamt.data, ctx.pixeldata, 1280 * 720 * sizeof(uint8_t) * 3);
        ctx.imagemutex.unlock();

        imshow("all", gesamt);

        if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
        {
            cout << "esc key is pressed by user" << endl;
            break;
        }

    }

    libvlc_media_player_stop(mp);
    libvlc_media_player_release(mp);
    libvlc_release(inst);
    delete[] ctx.pixeldata;

    return 0;
}

void display(void *data, void *id){
    (void)data;
    assert(id == NULL);
}

void unlock(void *data, void *id, void *const *p_pixels){
    struct ctx *ctx = (struct ctx*)data;
    ctx->imagemutex.unlock();
    assert(id == NULL);
}

void *lock(void *data, void **p_pixels){
    struct ctx *ctx = (struct ctx*)data;
    ctx->imagemutex.lock();
    *p_pixels = ctx->pixeldata;
    return NULL;
}

最佳答案

我在尝试通过 Avermedia 采集卡流式传输 Sony 运动摄像机时遇到了同样的问题。一个快速修复似乎是使用 DVDrive,它使您的采集卡输出看起来像一个网络摄像头。我已经成功地将其用作解决方法。

关于c++ - OpenCV 和 GoPro - VideoCapture 流中的空帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23345286/

相关文章:

c++ - 什么是好的返回类型 ` boost::shared_ptr<StructA>` ?

python-3.x - 如何使用python函数迭代从另一个函数接收的文件

c++ - 使用 C++ 和 OpenCV 将 RGB 转换为 LMS 模型

c++ - 从文件中并行读取图像

internet-explorer - 使用 FFMPEG 编码时,Internet Explorer 无法播放 WEBM

javascript - PhoneGap : Get orientation of captured video?

C++:直接在参数列表中使用数组文字的对象构造函数

java - 如何编译Java原生库?

c++ - enable_shared_from_this : Sharing the use count in member

node.js - 网络摄像头显示在 LAN 上而不是互联网