diff --git a/0001-Port-OpenCV-facedetect-example-to-C-API.patch b/0001-Port-OpenCV-facedetect-example-to-C-API.patch new file mode 100644 index 0000000..192e7d6 --- /dev/null +++ b/0001-Port-OpenCV-facedetect-example-to-C-API.patch @@ -0,0 +1,201 @@ +From f53677bf35c6b0a669d799182d6383f350d1503d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Stefan=20Br=C3=BCns?= +Date: Sun, 12 Jan 2020 17:37:53 +0100 +Subject: [PATCH] Port OpenCV facedetect example to C++ API + +Tested with: +cvlc --video-filter=opencv_wrapper \ + --opencv-filter-name opencv_example \ + --opencv-chroma RGB32 \ + --opencv-haarcascade-file /tmp/haarcascade_frontalface_default.xml \ + v4l2:///dev/video0 +--- + modules/video_filter/opencv_example.cpp | 117 +++++++++++------------- + 1 file changed, 52 insertions(+), 65 deletions(-) + +diff --git a/modules/video_filter/opencv_example.cpp b/modules/video_filter/opencv_example.cpp +index a7a0bd7821..87a3451f1a 100644 +--- a/modules/video_filter/opencv_example.cpp ++++ b/modules/video_filter/opencv_example.cpp +@@ -40,19 +40,16 @@ + #include + #include "filter_event_info.h" + +-#include +-#include +-#include +-#include +-#include ++#include + + /***************************************************************************** + * filter_sys_t : filter descriptor + *****************************************************************************/ +-struct filter_sys_t ++class filter_sys_t + { +- CvMemStorage* p_storage; +- CvHaarClassifierCascade* p_cascade; ++public: ++ cv::CascadeClassifier cascade; ++ std::vector event_info_storage; + video_filter_event_info_t event_info; + int i_id; + }; +@@ -92,15 +89,15 @@ static int OpenFilter( vlc_object_t *p_this ) + filter_sys_t *p_sys; + + /* Allocate the memory needed to store the decoder's structure */ +- if( ( p_filter->p_sys = p_sys = +- (filter_sys_t *)malloc(sizeof(filter_sys_t)) ) == NULL ) ++ p_filter->p_sys = p_sys = new filter_sys_t; ++ if(p_sys == nullptr) + { + return VLC_ENOMEM; + } + + //init the video_filter_event_info_t struct + p_sys->event_info.i_region_size = 0; +- p_sys->event_info.p_region = NULL; ++ p_sys->event_info.p_region = nullptr; + p_sys->i_id = 0; + + p_filter->pf_video_filter = Filter; +@@ -116,8 +113,9 @@ static int OpenFilter( vlc_object_t *p_this ) + + //OpenCV init specific to this example + char* filename = var_InheritString( p_filter, "opencv-haarcascade-file" ); +- p_sys->p_cascade = (CvHaarClassifierCascade*)cvLoad( filename, 0, 0, 0 ); +- p_sys->p_storage = cvCreateMemStorage(0); ++ if (!p_sys->cascade.load(filename)) { ++ msg_Err( p_filter, "Could not load %s", filename); ++ } + free( filename ); + + return VLC_SUCCESS; +@@ -131,14 +129,7 @@ static void CloseFilter( vlc_object_t *p_this ) + filter_t *p_filter = (filter_t*)p_this; + filter_sys_t *p_sys = p_filter->p_sys; + +- if( p_sys->p_cascade ) +- cvReleaseHaarClassifierCascade( &p_sys->p_cascade ); +- +- if( p_sys->p_storage ) +- cvReleaseMemStorage( &p_sys->p_storage ); +- +- free( p_sys->event_info.p_region ); +- free( p_sys ); ++ delete p_sys; + + var_Destroy( p_filter->obj.libvlc, VIDEO_FILTER_EVENT_VARIABLE); + } +@@ -148,15 +139,13 @@ static void CloseFilter( vlc_object_t *p_this ) + ****************************************************************************/ + static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) + { +- IplImage** p_img = NULL; +- CvPoint pt1, pt2; +- int scale = 1; ++ IplImage** p_img = nullptr; + filter_sys_t *p_sys = p_filter->p_sys; +- ++ + if ((!p_pic) ) + { + msg_Err( p_filter, "no image array" ); +- return NULL; ++ return nullptr; + } + //(hack) cast the picture_t to array of IplImage* + p_img = (IplImage**) p_pic; +@@ -165,50 +154,48 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) + if ((!p_img[0])) //1st plane is 'I' i.e. greyscale + { + msg_Err( p_filter, "no image" ); +- return NULL; ++ return nullptr; + } ++ // Wrapper for IplImage* -> cv::Mat (reference, not copy) ++ cv::Mat gray = cv::cvarrToMat(p_img[0]); + + //perform face detection +- cvClearMemStorage(p_sys->p_storage); +- if( p_sys->p_cascade ) ++ if (p_sys->cascade.empty()) ++ msg_Err( p_filter, "No cascade - is opencv-haarcascade-file valid?" ); ++ ++ //we should make some of these params config variables ++ std::vector faces; ++ p_sys->cascade.detectMultiScale(gray, faces, ++ 1.15, 5, ++ CV_HAAR_DO_CANNY_PRUNING, ++ cv::Size(20, 20)); ++ //create the video_filter_region_info_t struct ++ if (faces.empty()) ++ return p_pic; ++ ++ //msg_Dbg( p_filter, "Found %d face(s)", faces.size()); ++ p_sys->event_info_storage.resize(faces.size()); ++ p_sys->event_info.i_region_size = faces.size(); ++ p_sys->event_info.p_region = p_sys->event_info_storage.data(); ++ if( !p_sys->event_info.p_region ) ++ return nullptr; ++ ++ //populate the video_filter_region_info_t struct ++ for( int i = 0; i < faces.size(); i++ ) + { +- //we should make some of these params config variables +- CvSeq *faces = cvHaarDetectObjects( p_img[0], p_sys->p_cascade, +- p_sys->p_storage, 1.15, 5, +- CV_HAAR_DO_CANNY_PRUNING, +- 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( int 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[0], 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->obj.libvlc, VIDEO_FILTER_EVENT_VARIABLE ); ++ const cv::Rect& r = faces[i]; ++ cv::rectangle(gray, r, CV_RGB(0,0,0), 3); ++ ++ p_sys->event_info.p_region[i].i_x = r.x; ++ p_sys->event_info.p_region[i].i_y = r.y; ++ p_sys->event_info.p_region[i].i_width = r.width; ++ p_sys->event_info.p_region[i].i_height = r.height; ++ ++ p_sys->event_info.p_region[i].i_id = p_sys->i_id++; ++ p_sys->event_info.p_region[i].p_description = "Face Detected"; + } +- else +- msg_Err( p_filter, "No cascade - is opencv-haarcascade-file valid?" ); ++ ++ var_TriggerCallback( p_filter->obj.libvlc, VIDEO_FILTER_EVENT_VARIABLE ); + + return p_pic; + } +-- +2.24.1 + diff --git a/vlc.changes b/vlc.changes index 6e2bee2..4208d3f 100644 --- a/vlc.changes +++ b/vlc.changes @@ -1,3 +1,13 @@ +------------------------------------------------------------------- +Sun Jan 12 16:47:46 UTC 2020 - Stefan Brüns + +- Port away from obsolete OpenCV C API, fixes build with OpenCV 3.4.9, + add 0001-Port-OpenCV-facedetect-example-to-C-API.patch +- Move OpenCV plugins to subpackage, as libopencv has a quite large + footprint. +- Remove __DATE__/__TIME__ workaround, current GCC respects + SOURCE_DATE_EPOCH. + ------------------------------------------------------------------- Wed Sep 25 09:13:24 UTC 2019 - Martin Liška diff --git a/vlc.spec b/vlc.spec index 69e3554..cdbb5bd 100644 --- a/vlc.spec +++ b/vlc.spec @@ -1,7 +1,7 @@ # # spec file for package vlc # -# Copyright (c) 2019 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2020 SUSE LLC # Copyright (c) 2012 Dominique Leuenberger, Amsterdam, The Netherlands # # All modifications and additions to the file contributed by third parties @@ -40,8 +40,6 @@ License: GPL-2.0-or-later AND LGPL-2.1-or-later Group: Productivity/Multimedia/Video/Players URL: http://www.videolan.org Source: http://download.videolan.org/%{name}/%{version}/%{name}-%{version}.tar.xz -# Add vlc.changes as source, so we can reproducibly extract the date from it during build -Source1: %{name}.changes Source2: %{name}-rpmlintrc # PATCH-FIX-UPSTREAM vlc.a52.patch https://trac.videolan.org/vlc/ticket/3731 dimstar@opensuse.org -- Support new version of liba52 Patch0: vlc.a52.patch @@ -57,6 +55,8 @@ Patch100: vlc-projectM-qt5.patch Patch101: 0001-Fix-leaking-AvahiServiceResolver-in-the-error-paths.patch # PATCH-FIX-UPSTREAM 0002-Add-Avahi-implementation-for-chromecast-renderer-dis.patch -- Use Avahi for discovery, microdns is not available Patch102: 0002-Add-Avahi-implementation-for-chromecast-renderer-dis.patch +# PATCH-FIX-UPSTREAM -- Use OpenCV C++ API +Patch103: 0001-Port-OpenCV-facedetect-example-to-C-API.patch BuildRequires: Mesa-devel BuildRequires: aalib-devel BuildRequires: alsa-devel >= 1.0.24 @@ -376,6 +376,23 @@ Conflicts: %{conflicts}-qt This subpackage provides a Qt interface for VLC and selects it by default when `vlc` is invoked from an X session. +%package opencv +Summary: OpenCV plugins for VLC media player +Group: Productivity/Multimedia/Video/Players +Requires: %{name}-noX = %{version}-%{release} +# We need the noX package first, as it contains vlc-cache-gen +Requires(post): %{name}-noX +# Package split +Provides: %{name}:%{_libdir}/vlc/plugins/video_filter/libopencv_example_plugin.so +Conflicts: %{name} < %{version}-%{release} +Supplements: packageand(%{name}-noX:opencv3) +# Data required for face detection +Recommends: opencv3 + +%description opencv +This subpackage provides a wrapper plugin for OpenCV for +OpenCV based video filters and a face detection example. + %prep %setup -q %patch0 -p1 @@ -386,6 +403,7 @@ default when `vlc` is invoked from an X session. %endif %patch101 -p1 %patch102 -p1 +%patch103 -p1 ### And LUA 5.3.1 has some more API changes if pkg-config --atleast-version 5.3.1 lua; then @@ -396,12 +414,6 @@ fi # We do not rely on contrib but make use of system libraries rm -rf contrib -# fix builddate info -# Remove build time references so build-compare can do its work -FAKE_BUILDTIME=$(LC_ALL=C date -u -r %{SOURCE1} '+%%H:%%M') -FAKE_BUILDDATE=$(LC_ALL=C date -u -r %{SOURCE1} '+%%b %%e %%Y') -sed -e "s/__TIME__/\"$FAKE_BUILDTIME\"/" -i modules/gui/qt/dialogs/help.cpp src/config/help.c -sed -e "s/__DATE__/\"$FAKE_BUILDDATE\"/" -i modules/gui/qt/dialogs/help.cpp src/config/help.c %build %define _lto_cflags %{nil} @@ -562,6 +574,12 @@ done %postun -n %{name}-vdpau %{_libdir}/vlc/vlc-cache-gen %{_libdir}/vlc/plugins +%post -n %{name}-opencv +%{_libdir}/vlc/vlc-cache-gen %{_libdir}/vlc/plugins + +%postun -n %{name}-opencv +%{_libdir}/vlc/vlc-cache-gen %{_libdir}/vlc/plugins + %files %exclude %{_libdir}/vlc/libcompat.a # The presence of the .desktop file is what gives AppStream the @@ -604,10 +622,6 @@ done %{_libdir}/vlc/plugins/text_renderer/libfreetype_plugin.so %{_libdir}/vlc/plugins/text_renderer/libsvg_plugin.so %{_libdir}/vlc/plugins/video_chroma/libswscale_plugin.so -%if 0%{?is_opensuse} -%{_libdir}/vlc/plugins/video_filter/libopencv_example_plugin.so -%{_libdir}/vlc/plugins/video_filter/libopencv_wrapper_plugin.so -%endif %{_libdir}/vlc/plugins/video_output/libaa_plugin.so %{_libdir}/vlc/plugins/video_output/libcaca_plugin.so %{_libdir}/vlc/plugins/video_output/libegl_x11_plugin.so @@ -1124,6 +1138,12 @@ done %{_libdir}/vlc/plugins/vdpau/libvdpau_sharpen_plugin.so %{_libdir}/vlc/plugins/video_output/libglconv_vdpau_plugin.so +%if 0%{?is_opensuse} +%files opencv +%{_libdir}/vlc/plugins/video_filter/libopencv_example_plugin.so +%{_libdir}/vlc/plugins/video_filter/libopencv_wrapper_plugin.so +%endif + %files -n libvlc%{libvlc} %{_libdir}/libvlc.so.%{libvlc}*