VLC的opencv_example插件不起作用

时间:2014-08-06 09:58:51

标签: c opencv ubuntu vlc

我成功编译了 opencv_example (这是来自 vlc / modules / video_filter 的VLC视频过滤器插件)。但是它不想对我有用 我按以下方式运行 vlc

XXX@XXX:/opt/vlc-2.0.1-td/bin$ vlc --video-filter opencv_example

VLC运行,我打开视频文件,它打开很好(我看到帧)。但是调试总是回答我:

[0x7f3bec792b78] main filter error: corrupt module: /usr/local/lib/vlc/plugins/video_filter/libopencv_example_plugin.so
[0x7f3bec1728f8] main video output error: Failed to create video filter2 'opencv_example'
[0x7f3bec1728f8] main video output error: Failed to add filter 'opencv_example'
[0x7f3bee4b1a88] main filter error: corrupt module: /usr/local/lib/vlc/plugins/video_filter/libopencv_example_plugin.so
[0x7f3bec1728f8] main video output error: Failed to create video filter2 'opencv_example'
[0x7f3bec1728f8] main video output error: Failed to add filter 'opencv_example'

我发现它可能是链接错误,因为当我运行 ldd util时,我看不到 libopencv_example_plugin.so使用的库中任何opencv库的引用

XXX@XXX:/usr/local/lib/vlc/plugins/video_filter$ ldd libopencv_example_plugin.so
linux-vdso.so.1 =>  (0x00007fff947ff000)
libvlccore.so.5 => /usr/local/lib/libvlccore.so.5 (0x00007f9c1b92c000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9c1b56c000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f9c1b327000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9c1b11f000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9c1af02000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9c1acfd000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9c1aa01000)
/lib64/ld-linux-x86-64.so.2 (0x00007f9c1be31000)

因此。上面列出的问题是:如何使 opencv_example 工作? 我正在使用VLC 2.0.1,OpenCV 2.4.9的Ubuntu 12.04 提前感谢大家!

2 个答案:

答案 0 :(得分:1)

最后还是努力工作。运行 opencv_example 的问题很复杂,因此有两个步骤可以解决它:

1链接必要的OpenCV库
我最初的想法是正确的:创建VLC视频过滤器的失败是由未链接的OpenCV库引起的 要链接它们,请打开 configure.ac 进行写入。然后找到以下行:

PKG_ENABLE_MODULES_VLC([OPENCV], [opencv_example opencv_wrapper], [opencv], (OpenCV (computer vision) filter), [off])

这一确切的行告诉VLC NOT 将OpenCV链接到 opencv_example opencv_wrapper 。因此,更改它并添加更多行来检查CV函数的可用性:

PKG_ENABLE_MODULES_VLC([OPENCV], [opencv_example opencv_wrapper], [opencv], (OpenCV (computer vision) filter), [on])
AC_MSG_CHECKING([opencv libs for opencv_example & opencv_wrapper])
AC_CHECK_LIB(opencv_objdetect, cvHaarDetectObjects,
    [
    VLC_ADD_PLUGIN([opencv_wrapper opencv_example])
    VLC_ADD_CFLAGS([opencv_wrapper opencv_example], [$OPENCV_CFLAGS])
    VLC_ADD_LIBS([opencv_wrapper opencv_example],[-lopencv_core -lopencv_objdetect])
    AC_MSG_RESULT([opencv libs added, cvHaarDetectObjects is ok])
    ],
    AC_MSG_ERROR([opencv libs for opencv_example & opencv_wrapper cannot be added!]))

保存此文件,返回VLC目录并执行以下操作:

autoconf
./configure
make
make install

运行 ./ configure 时,终端应显示的其他信息中包含:

checking opencv libs for opencv_example & opencv_wrapper...
checking for cvHaarDetectObjects in -lopencv_objdetect... yes

这是一个很好的唱歌意味着安装了OpenCV并且VLC已准备好将其链接到我们的插件 安装完所有内容( make install )后,通过在 / usr / local / lib / vlc / plugins / video_filter 目录中运行 ldd 实用程序来检查链接(或无论你的VLC插件安装在哪里):

XXX@XXX:/usr/local/lib/vlc/plugins/video_filter# ldd libopencv_example_plugin.so
linux-vdso.so.1 =>  (0x00007fff549cd000)
libvlccore.so.5 => /usr/local/lib/libvlccore.so.5 (0x00007f036aa2a000)
libopencv_core.so.2.4 => /usr/local/lib/libopencv_core.so.2.4 (0x00007f036a5e8000)
libopencv_objdetect.so.2.4 => /usr/local/lib/libopencv_objdetect.so.2.4 (0x00007f036a367000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f0369fa7000)
libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f0369d63000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f0369b5a000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f036993d000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0369739000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f036943c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f0369225000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f0368f25000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0368d0e000)
libopencv_imgproc.so.2.4 => /usr/local/lib/libopencv_imgproc.so.2.4 (0x00007f036884c000)
libopencv_highgui.so.2.4 => /usr/local/lib/libopencv_highgui.so.2.4 (0x00007f03684ae000)
/lib64/ld-linux-x86-64.so.2 (0x00007f036af2f000)
libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f036825d000)
libpng12.so.0 => /lib/x86_64-linux-gnu/libpng12.so.0 (0x00007f0368035000)
libtiff.so.4 => /usr/lib/x86_64-linux-gnu/libtiff.so.4 (0x00007f0367dd0000)
libgtk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007f0367796000)
libgdk-x11-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007f03674e4000)
libgobject-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f0367294000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f0366f9f000)
libdc1394.so.22 => /usr/lib/x86_64-linux-gnu/libdc1394.so.22 (0x00007f0366d2c000)
libv4l1.so.0 => /usr/lib/x86_64-linux-gnu/libv4l1.so.0 (0x00007f0366b25000)
libavcodec.so.53 => /usr/lib/x86_64-linux-gnu/libavcodec.so.53 (0x00007f0365d15000)
libavformat.so.53 => /usr/lib/x86_64-linux-gnu/libavformat.so.53 (0x00007f0365a15000)
libavutil.so.51 => /usr/lib/x86_64-linux-gnu/libavutil.so.51 (0x00007f03657f4000)
libswscale.so.2 => /usr/lib/x86_64-linux-gnu/libswscale.so.2 (0x00007f03655ae000)
libpangocairo-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f03653a1000)
libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f036506c000)
libXfixes.so.3 => /usr/lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f0364e66000)
libatk-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007f0364c43000)
libcairo.so.2 => /usr/lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f0364985000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f0364765000)
libgio-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007f0364415000)
libpangoft2-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007f03641eb000)
libpango-1.0.so.0 => /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f0363fa2000)
libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f0363d6b000)
libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f0363b5a000)
libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f0363950000)
libXinerama.so.1 => /usr/lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f036374c000)
libXi.so.6 => /usr/lib/x86_64-linux-gnu/libXi.so.6 (0x00007f036353d000)
libXrandr.so.2 => /usr/lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f0363335000)
libXcursor.so.1 => /usr/lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f036312a000)
libXcomposite.so.1 => /usr/lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f0362f27000)
libXdamage.so.1 => /usr/lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f0362d24000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007f0362b1b000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f03628de000)
libraw1394.so.11 => /usr/lib/x86_64-linux-gnu/libraw1394.so.11 (0x00007f03626ce000)
libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007f03624bf000)
libv4l2.so.0 => /usr/lib/x86_64-linux-gnu/libv4l2.so.0 (0x00007f03622b3000)
libvpx.so.1 => /usr/lib/libvpx.so.1 (0x00007f036200d000)
libvorbisenc.so.2 => /usr/lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f0361b3e000)
libvorbis.so.0 => /usr/lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f0361912000)
libtheoraenc.so.1 => /usr/lib/x86_64-linux-gnu/libtheoraenc.so.1 (0x00007f03616d4000)
libtheoradec.so.1 => /usr/lib/x86_64-linux-gnu/libtheoradec.so.1 (0x00007f03614b9000)
libspeex.so.1 => /usr/lib/x86_64-linux-gnu/libspeex.so.1 (0x00007f03612a0000)
libschroedinger-1.0.so.0 => /usr/lib/libschroedinger-1.0.so.0 (0x00007f0360fec000)
libgsm.so.1 => /usr/lib/libgsm.so.1 (0x00007f0360dde000)
libva.so.1 => /usr/lib/x86_64-linux-gnu/libva.so.1 (0x00007f0360bc8000)
libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f03609b7000)
libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f036071b000)
libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f03604fc000)
libpixman-1.so.0 => /usr/lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f0360275000)
libxcb-shm.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f0360072000)
libxcb-render.so.0 => /usr/lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f035fe67000)
libgmodule-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f035fc63000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f035fa43000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f035f827000)
libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f035f5fc000)
libv4lconvert.so.0 => /usr/lib/x86_64-linux-gnu/libv4lconvert.so.0 (0x00007f035f387000)
libogg.so.0 => /usr/lib/x86_64-linux-gnu/libogg.so.0 (0x00007f035f180000)
liborc-0.4.so.0 => /usr/lib/x86_64-linux-gnu/liborc-0.4.so.0 (0x00007f035ef04000)
libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f035ed01000)
libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f035eafb000)

看,链接库的数量增加了几倍 第一步完成。您可以通过运行VLC来检查 opencv_example 的加载。但正确的话,你可能面临另一个问题:

...
[0x7f2d741728f8] main video output debug: Adding 'opencv_example' as interactive
[0x7f2d747f7a68] main filter debug: looking for video filter2 module: 1 candidate
[0x7f2d747f7a68] main filter debug: using video filter2 module "opencv_example"
[0x7f2d747f7a68] main filter debug: TIMER module_need() : 149.351 ms - Total 149.351 ms / 1 intvls (Avg 149.351 ms)
[0x7f2d741728f8] main video output debug: Filter 'opencv_example' (0x7f2d747f7a68) appended to chain
[0x7f2d74173cb8] main spu text debug: removing module "freetype"
[0x7f2d74173cb8] main spu text debug: looking for text renderer module: 3 candidates
[0x7f2d74173cb8] freetype spu text debug: Building font databases.
[0x7f2d74173cb8] freetype spu text debug: Took 33 microseconds
[0x7f2d74173cb8] freetype spu text debug: Using Serif Bold as font from file /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf
[0x7f2d74173cb8] freetype spu text debug: using fontsize: 2
[0x7f2d74173cb8] main spu text debug: using text renderer module "freetype"
[0x7f2d74173cb8] main spu text debug: TIMER module_need() : 5.776 ms - Total 5.776 ms / 1 intvls (Avg 5.776 ms)
[0x7f2d8c00d018] main decoder debug: End of video preroll
[0x7f2d8c00d018] main decoder debug: Received first picture
Segmentation fault (core dumped)


2更改opencv_example源代码
因此,正如我所发现的,在将图像从 picture_t (用于存储图像的VLC结构)转换为 IplImage (图像的OpenCV类型)时隐藏了错误:

//(hack) cast the picture_t to array of IplImage*
p_img = (IplImage**) p_pic->p[0].p_pixels;

只需稍微更改此转换以使一切正常。以下是我修改的 opencv_example.c Filter 方法的完整代码:

static picture_t *Filter( filter_t *p_filter, picture_t *p_pic )
{
    IplImage* p_img;
    int i_planes = 0;
    CvPoint pt1, pt2;
    int i, scale = 1;
    filter_sys_t *p_sys = p_filter->p_sys;

    if ((!p_pic))
    {
        msg_Err( p_filter, "no image array" );
        return NULL;
    }

    i_planes = p_pic->i_planes;    
    if (i_planes<1)
    {
        msg_Err( p_filter, "no image planes" );
        return NULL;
    }
    if ((p_pic->format.i_chroma != VLC_CODEC_I420))
    {
        msg_Err( p_filter, "wrong chroma - use I420" );
        return NULL;
    }

    //picture_t to IplImage without segmentation fault
    p_img = cvCreateImageHeader( cvSize( p_pic->p[0].i_pitch, p_pic->p[0].i_visible_lines ),
        IPL_DEPTH_8U, 1 );
    cvSetData( p_img, p_pic->p[0].p_pixels, p_pic->p[0].i_pitch );

    //perform face detection
    cvClearMemStorage(p_sys->p_storage);
    if( p_sys->p_cascade )
    {
        //we should make some of these params config variables
        CvSeq *faces = cvHaarDetectObjects( p_img, p_sys->p_cascade, p_sys->p_storage,
                        1.15, 5, CV_HAAR_DO_CANNY_PRUNING,
                                            cvSize(0, 0), cvSize(20, 20) );
        //create the video_filter_region_info_t struct
        if (faces && (faces->total > 0))
        {
            msg_Dbg( p_filter, "Found %d face(s)", faces->total );
            free( p_sys->event_info.p_region );
            p_sys->event_info.p_region = (video_filter_region_info_t*)
                    calloc( faces->total, sizeof(video_filter_region_info_t));
            if( !p_sys->event_info.p_region )
                return NULL;
            p_sys->event_info.i_region_size = faces->total;
        }

        //populate the video_filter_region_info_t struct
        for( i = 0; i < (faces ? faces->total : 0); i++ )
        {
            CvRect *r = (CvRect*)cvGetSeqElem( faces, i );
            pt1.x = r->x*scale;
            pt2.x = (r->x+r->width)*scale;
            pt1.y = r->y*scale;
            pt2.y = (r->y+r->height)*scale;
            cvRectangle( p_img, pt1, pt2, CV_RGB(0,0,0), 3, 8, 0 );

            *(CvRect*)(&(p_sys->event_info.p_region[i])) = *r;
            p_sys->event_info.p_region[i].i_id = p_sys->i_id++;
            p_sys->event_info.p_region[i].p_description = "Face Detected";
        }

        if (faces && (faces->total > 0))    //raise the video filter event
            var_TriggerCallback( p_filter->p_libvlc, VIDEO_FILTER_EVENT_VARIABLE );
    }
    else
        msg_Err( p_filter, "No cascade - is opencv-haarcascade-file valid?" );

    //IplImage to picture_t without segmentation fault
    cvGetRawData( p_img, (uchar**)&p_pic->p[0].p_pixels, NULL, NULL );

    return p_pic;
}

VLC应该运行良好,以及opencv_example过滤器。如果您有任何与VLC + OpenCV相关的其他问题

,请告诉我们

答案 1 :(得分:0)