[packages/digikam] - fix building with opencv 3.1 - rel 2

baggins baggins at pld-linux.org
Tue Mar 22 17:54:02 CET 2016


commit e028b4c57dc75a02f67112f2029cfff8472eea1f
Author: Jan Rękorajski <baggins at pld-linux.org>
Date:   Tue Mar 22 17:53:42 2016 +0100

    - fix building with opencv 3.1
    - rel 2

 digikam.spec  |   5 +-
 opencv3.patch | 822 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 826 insertions(+), 1 deletion(-)
---
diff --git a/digikam.spec b/digikam.spec
index cd4270a..f6d48e2 100644
--- a/digikam.spec
+++ b/digikam.spec
@@ -6,13 +6,14 @@ Summary:	A KDE frontend for gphoto2
 Summary(pl.UTF-8):	Interfejs KDE do gphoto2
 Name:		digikam
 Version:	4.13.0
-Release:	1
+Release:	2
 License:	GPL
 Group:		X11/Applications/Graphics
 Source0:	http://download.kde.org/stable/digikam/%{name}-%{version}.tar.bz2
 # Source0-md5:	930b9a89244afd1f28490d0acabbecc5
 Patch0:		%{name}-build.patch
 Patch1:		sendimages-icedove.diff
+Patch2:		opencv3.patch
 URL:		http://www.digikam.org/
 BuildRequires:	ImageMagick-devel
 BuildRequires:	Qt3Support-devel >= %{qtver}
@@ -85,6 +86,7 @@ Interfejs KDE do gphoto2 - pliki nagłówkowe.
 %setup -q
 %patch0 -p1
 %patch1 -p1
+%patch2 -p1
 
 # use kde one
 rm cmake/modules/FindK{Sane,exiv2,ipi}.cmake
@@ -99,6 +101,7 @@ cd build
 	-DDIGIKAMSC_COMPILE_LIBKGEOMAP:BOOL=ON \
 	-DDIGIKAMSC_COMPILE_LIBMEDIAWIKI:BOOL=ON \
 	-DDIGIKAMSC_COMPILE_LIBKVKONTAKTE:BOOL=ON \
+	-DENABLE_OPENCV3:BOOL=ON \
 	../
 
 %{__make}
diff --git a/opencv3.patch b/opencv3.patch
new file mode 100644
index 0000000..bd28d7f
--- /dev/null
+++ b/opencv3.patch
@@ -0,0 +1,822 @@
+diff -urN digikam-4.13.0/core/app/utils/libopencv.h digikam-4.13.0-opencv3/core/app/utils/libopencv.h
+--- digikam-4.13.0/core/app/utils/libopencv.h	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/core/app/utils/libopencv.h	2016-03-22 17:06:26.155608182 +0100
+@@ -7,7 +7,7 @@
+  * @date   2010-06-16
+  * @brief  Wrapper for OpenCV header files
+  *
+- * @author Copyright (C) 2012-2014 by Gilles Caulier
++ * @author Copyright (C) 2012-2015 by Gilles Caulier
+  *         <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
+  *
+  * This program is free software; you can redistribute it
+@@ -46,17 +46,19 @@
+ 
+ #define OPENCV_MAKE_VERSION(major,minor,patch) (((major) << 16) | ((minor) << 8) | (patch))
+ #define OPENCV_VERSION                         OPENCV_MAKE_VERSION(CV_MAJOR_VERSION,CV_MINOR_VERSION,CV_SUBMINOR_VERSION)
+-#define OPENCV_TEST_VERSION(major,minor,patch) ( OPENCV_VERSION >= OPENCV_MAKE_VERSION(major,minor,patch) )
++#define OPENCV_TEST_VERSION(major,minor,patch) ( OPENCV_VERSION < OPENCV_MAKE_VERSION(major,minor,patch) )
+ 
+-#if OPENCV_TEST_VERSION(2,3,0)
++#if OPENCV_TEST_VERSION(2,5,0)
+ #   include <opencv2/opencv.hpp>
+ #   include <opencv2/legacy/compat.hpp>
+ #   include <opencv/cvaux.h>
++#   include <opencv2/imgproc/imgproc.hpp>
+ #else
+ #   include <opencv/cv.h>
+ #   include <opencv/cvaux.h>
+ #   include <opencv/cxcore.h>
+ #   include <opencv/highgui.h>
++#   include <opencv2/imgproc.hpp>
+ #endif
+ 
+ // Restore warnings
+diff -urN digikam-4.13.0/core/CMakeLists.txt digikam-4.13.0-opencv3/core/CMakeLists.txt
+--- digikam-4.13.0/core/CMakeLists.txt	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/core/CMakeLists.txt	2016-03-22 17:06:26.155608182 +0100
+@@ -12,6 +12,7 @@
+ 
+ option(ENABLE_INTERNALMYSQL     "Build digiKam with internal MySQL server executable (default=OFF)"              OFF)
+ option(ENABLE_LCMS2             "Build digiKam with LCMS2 instead LCMS1 (default=OFF)"                           OFF)
++option(ENABLE_OPENCV3           "Build digiKam with OpenCV3 instead OpenCV2 (default=OFF)"                       OFF)
+ option(ENABLE_BALOOSUPPORT      "Build digiKam with Baloo support (default=ON)"                                  ON)
+ option(ENABLE_KDEPIMLIBSSUPPORT "Build digiKam with Kdepimlibs support (default=OFF)"                            OFF)
+ 
+@@ -122,8 +123,13 @@
+ 
+ # -- check OpenCV --------------------------------------------------------------------------------
+ 
+-set(OPENCV_MIN_VERSION "2.4.9")
+-DETECT_OPENCV(${OPENCV_MIN_VERSION}  core highgui objdetect contrib legacy imgproc)
++if (ENABLE_OPENCV3)
++    set(OPENCV_MIN_VERSION "3.0.0")
++    DETECT_OPENCV(${OPENCV_MIN_VERSION} core face highgui objdetect imgproc)
++else()
++    set(OPENCV_MIN_VERSION "2.4.9")
++    DETECT_OPENCV(${OPENCV_MIN_VERSION} core highgui objdetect contrib legacy imgproc)
++endif()
+ 
+ # -- check the libkdcraw version -----------------------------------------------------------------
+ 
+diff -urN digikam-4.13.0/core/libs/database/imgqsort/imgqsort.cpp digikam-4.13.0-opencv3/core/libs/database/imgqsort/imgqsort.cpp
+--- digikam-4.13.0/core/libs/database/imgqsort/imgqsort.cpp	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/core/libs/database/imgqsort/imgqsort.cpp	2016-03-22 17:06:26.155608182 +0100
+@@ -282,10 +282,15 @@
+ 
+     MixerFilter mixer(&d->image, 0L, settings);
+     mixer.startFilterDirectly();
+-
+     d->image.putImageData(mixer.getTargetImage().bits());
++
++#if OPENCV_TEST_VERSION(3,0,0)
+     d->src      = cvCreateMat(d->image.numPixels(), 3, CV_8UC3); // Create a matrix containing the pixel values of original image
+     d->src_gray = cvCreateMat(d->image.numPixels(), 1, CV_8UC1); // Create a matrix containing the pixel values of grayscaled image
++#else
++    d->src      = Mat(d->image.numPixels(), 3, CV_8UC3); // Create a matrix containing the pixel values of original image
++    d->src_gray = Mat(d->image.numPixels(), 1, CV_8UC1); // Create a matrix containing the pixel values of grayscaled image
++#endif
+ 
+     if (d->imq.detectNoise)
+     {
+@@ -655,7 +660,12 @@
+     int countblocks      = 0;
+     int number_of_blocks = 0;
+     int sum              = 0;
++
++#if OPENCV_TEST_VERSION(3,0,0)
+     vector<int> average_bottom, average_middle, average_top;
++#else
++    std::vector<int> average_bottom, average_middle, average_top;
++#endif
+ 
+     // Go through 8 blocks at a time horizontally
+     // iterating through columns.
+@@ -792,7 +802,13 @@
+ int ImgQSort::exposureamount() const
+ {
+     /// Separate the image in 3 places ( B, G and R )
++
++#if OPENCV_TEST_VERSION(3,0,0)
+     vector<Mat> bgr_planes;
++#else
++    std::vector<Mat> bgr_planes;
++#endif
++
+     split(d->src, bgr_planes);
+ 
+     /// Establish the number of bins
+diff -urN digikam-4.13.0/core/README digikam-4.13.0-opencv3/core/README
+--- digikam-4.13.0/core/README	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/core/README	2016-03-22 17:06:26.155608182 +0100
+@@ -122,6 +122,9 @@
+ Use CMake "-DENABLE_LCMS2=on"             flag to compile digiKam source code using lcms2 instead lcms1                          (disabled by default).
+ Use CMake "-DENABLE_BALOOSUPPORT=on"      flag to compile digiKam with Baloo support                                             (disabled by default).
+ Use CMake "-DENABLE_KDEPIMLIBSSUPPORT=on" flag to compile digiKam with KdePimLibs support                                        (disabled by default).
++Use CMake "-DENABLE_OPENCV3=on"           flag to compile libkface source code using OpenCV3 instead OpenCV2                     (disabled by default).
++                                          OpenCV3 support needs extra contrib modules package, especially 'face'
++                                          and 'legacy' components.
+ 
+ Mysql support options (experimental):
+ 
+diff -urN digikam-4.13.0/extra/kipi-plugins/CMakeLists.txt digikam-4.13.0-opencv3/extra/kipi-plugins/CMakeLists.txt
+--- digikam-4.13.0/extra/kipi-plugins/CMakeLists.txt	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/kipi-plugins/CMakeLists.txt	2016-03-22 17:06:26.155608182 +0100
+@@ -1,4 +1,3 @@
+-cmake_minimum_required(VERSION 2.8.9)
+ #
+ # Copyright (c) 2010-2015, Gilles Caulier, <caulier dot gilles at gmail dot com>
+ #
+@@ -11,16 +10,18 @@
+ message(STATUS "----------------------------------------------------------------------------------")
+ message(STATUS "Starting CMake configuration for: kipi-plugins")
+ 
++option(ENABLE_OPENCV3 "Build kipi-plugins with OpenCV3 instead OpenCV2 (default=OFF)" OFF)
++
+ # =======================================================
+ # Information to update before to release this package.
+ 
+ # kipi-plugins version
+ set(KIPIPLUGINS_MAJOR_VERSION "4")
+-set(KIPIPLUGINS_MINOR_VERSION "13")
++set(KIPIPLUGINS_MINOR_VERSION "14")
+ set(KIPIPLUGINS_PATCH_VERSION "0")
+ 
+ # kipi-plugins release date
+-set(KIPIPLUGINS_RELEASE_DATE "2015-08-30")
++set(KIPIPLUGINS_RELEASE_DATE "2015-09-27")
+ 
+ # Suffix to add at end of version string. Usual values are:
+ # "-git"   : alpha code unstable from git. Do not use in production
+@@ -165,8 +166,14 @@
+ 
+     include(MacroUtils)
+     include(MacroOpenCV)
+-    set(OPENCV_MIN_VERSION "2.4.9")
+-    DETECT_OPENCV(${OPENCV_MIN_VERSION} core highgui objdetect contrib legacy imgproc)
++
++    if (ENABLE_OPENCV3)
++        set(OPENCV_MIN_VERSION "3.0.0")
++        DETECT_OPENCV(${OPENCV_MIN_VERSION} core face highgui objdetect imgproc)
++    else()
++        set(OPENCV_MIN_VERSION "2.4.9")
++        DETECT_OPENCV(${OPENCV_MIN_VERSION} core highgui objdetect contrib legacy imgproc)
++    endif()
+ 
+     include(MacroOptionalDependPackage)
+ 
+diff -urN digikam-4.13.0/extra/kipi-plugins/README digikam-4.13.0-opencv3/extra/kipi-plugins/README
+--- digikam-4.13.0/extra/kipi-plugins/README	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/kipi-plugins/README	2016-03-22 17:06:26.155608182 +0100
+@@ -140,6 +140,12 @@
+ 
+ -- INSTALL ------------------------------------------------------------
+ 
++CMake compilation options to custom digiKam:
++
++Use CMake "-DENABLE_OPENCV3=on"           flag to compile kipi-plugins source code using OpenCV3 instead OpenCV2                     (disabled by default).
++                                          OpenCV3 support needs extra contrib modules package, especially 'face'
++                                          and 'legacy' components.
++
+ In order to compile, especially when QT3/Qt4 are installed at the same time, 
+ just use something like that:
+ 
+diff -urN digikam-4.13.0/extra/kipi-plugins/removeredeyes/CMakeLists.txt digikam-4.13.0-opencv3/extra/kipi-plugins/removeredeyes/CMakeLists.txt
+--- digikam-4.13.0/extra/kipi-plugins/removeredeyes/CMakeLists.txt	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/kipi-plugins/removeredeyes/CMakeLists.txt	2016-03-22 17:06:26.155608182 +0100
+@@ -1,5 +1,5 @@
+ #
+-# Copyright (c) 2010-2014, Gilles Caulier, <caulier dot gilles at gmail dot com>
++# Copyright (c) 2010-2015, Gilles Caulier, <caulier dot gilles at gmail dot com>
+ #
+ # Redistribution and use is allowed according to the terms of the BSD license.
+ # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+diff -urN digikam-4.13.0/extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp digikam-4.13.0-opencv3/extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp
+--- digikam-4.13.0/extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp	2016-03-22 17:06:26.155608182 +0100
+@@ -90,6 +90,15 @@
+ 
+ // --------------------------------------------------------
+ 
++#if !(OPENCV_TEST_VERSION(2,5,0))
++
++static void cvFillImage(CvArr* const mat, double color)
++{
++    cvSet(mat, cvColorToScalar(color, cvGetElemType(mat)), 0);
++}
++
++#endif
++
+ int HaarClassifierLocator::findPossibleEyes(double csf, int ngf, const char* classifierFile)
+ {
+     // eyes sequence will reside in the storage
+diff -urN digikam-4.13.0/extra/kipi-plugins/removeredeyes/plugin/libopencv.h digikam-4.13.0-opencv3/extra/kipi-plugins/removeredeyes/plugin/libopencv.h
+--- digikam-4.13.0/extra/kipi-plugins/removeredeyes/plugin/libopencv.h	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/kipi-plugins/removeredeyes/plugin/libopencv.h	2016-03-22 17:06:26.155608182 +0100
+@@ -7,7 +7,7 @@
+  * @date   2010-06-16
+  * @brief  Wrapper for OpenCV header files
+  *
+- * @author Copyright (C) 2012-2014 by Gilles Caulier
++ * @author Copyright (C) 2012-2015 by Gilles Caulier
+  *         <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
+  *
+  * This program is free software; you can redistribute it
+@@ -53,12 +53,13 @@
+ 
+ #define OPENCV_MAKE_VERSION(major,minor,patch) (((major) << 16) | ((minor) << 8) | (patch))
+ #define OPENCV_VERSION                         OPENCV_MAKE_VERSION(CV_MAJOR_VERSION,CV_MINOR_VERSION,CV_SUBMINOR_VERSION)
+-#define OPENCV_TEST_VERSION(major,minor,patch) ( OPENCV_VERSION >= OPENCV_MAKE_VERSION(major,minor,patch) )
++#define OPENCV_TEST_VERSION(major,minor,patch) ( OPENCV_VERSION < OPENCV_MAKE_VERSION(major,minor,patch) )
+ 
+-#if OPENCV_TEST_VERSION(2,3,0)
++#include <opencv2/core/core_c.h>
++
++#if OPENCV_TEST_VERSION(2,5,0)
+ #include <opencv2/opencv.hpp>
+ #include <opencv2/highgui/highgui_c.h>
+-#include <opencv2/core/core_c.h>
+ #include <opencv2/legacy/compat.hpp>
+ #include <opencv/cvaux.h>
+ #else
+diff -urN digikam-4.13.0/extra/kipi-plugins/removeredeyes/test/CMakeLists.txt digikam-4.13.0-opencv3/extra/kipi-plugins/removeredeyes/test/CMakeLists.txt
+--- digikam-4.13.0/extra/kipi-plugins/removeredeyes/test/CMakeLists.txt	2015-09-03 23:22:45.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/kipi-plugins/removeredeyes/test/CMakeLists.txt	2016-03-22 17:06:26.155608182 +0100
+@@ -1,10 +1,10 @@
+ #
+-# Copyright (c) 2010-2014, Gilles Caulier, <caulier dot gilles at gmail dot com>
++# Copyright (c) 2010-2015, Gilles Caulier, <caulier dot gilles at gmail dot com>
+ #
+ # Redistribution and use is allowed according to the terms of the BSD license.
+ # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+ 
+-if(NOT WIN32)
++if(NOT WIN32 AND (${OpenCV_VERSION} VERSION_LESS 3.0.0))
+ 
+     include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../plugin
+                         ${CMAKE_CURRENT_SOURCE_DIR}/../libcvblobs
+diff -urN digikam-4.13.0/extra/libkface/CMakeLists.txt digikam-4.13.0-opencv3/extra/libkface/CMakeLists.txt
+--- digikam-4.13.0/extra/libkface/CMakeLists.txt	2015-09-03 23:22:44.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/libkface/CMakeLists.txt	2016-03-22 17:06:26.155608182 +0100
+@@ -10,6 +10,8 @@
+ message(STATUS "----------------------------------------------------------------------------------")
+ message(STATUS "Starting CMake configuration for: libkface")
+ 
++option(ENABLE_OPENCV3 "Build libkface with OpenCV3 instead OpenCV2 (default=OFF)" OFF)
++
+ find_package(Qt4 4.6.0 REQUIRED)
+ find_package(KDE4 REQUIRED)
+ 
+@@ -30,7 +32,12 @@
+ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
+ 
+ include(MacroOpenCV)
+-DETECT_OPENCV(2.4.9 core highgui objdetect contrib legacy imgproc)
++
++if (ENABLE_OPENCV3)
++    DETECT_OPENCV(3.0.0 core face highgui objdetect imgproc)
++else()
++    DETECT_OPENCV(2.4.9 core highgui objdetect contrib legacy imgproc)
++endif()
+ 
+ include_directories(${OpenCV_INCLUDE_DIRS})
+ 
+diff -urN digikam-4.13.0/extra/libkface/libkface/CMakeLists.txt digikam-4.13.0-opencv3/extra/libkface/libkface/CMakeLists.txt
+--- digikam-4.13.0/extra/libkface/libkface/CMakeLists.txt	2015-09-03 23:22:44.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/libkface/libkface/CMakeLists.txt	2016-03-22 17:06:26.155608182 +0100
+@@ -1,5 +1,5 @@
+ #
+-# Copyright (c) 2010-2014, Gilles Caulier, <caulier dot gilles at gmail dot com>
++# Copyright (c) 2010-2015, Gilles Caulier, <caulier dot gilles at gmail dot com>
+ #
+ # Redistribution and use is allowed according to the terms of the BSD license.
+ # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+diff -urN digikam-4.13.0/extra/libkface/libkface/detection/opencvfacedetector.cpp digikam-4.13.0-opencv3/extra/libkface/libkface/detection/opencvfacedetector.cpp
+--- digikam-4.13.0/extra/libkface/libkface/detection/opencvfacedetector.cpp	2015-09-03 23:22:44.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/libkface/libkface/detection/opencvfacedetector.cpp	2016-03-22 17:06:26.155608182 +0100
+@@ -18,7 +18,7 @@
+  *         <a href="alexjironkin at gmail dot com">alexjironkin at gmail dot com</a>
+  * @author Copyright (C) 2010 by Aditya Bhatt
+  *         <a href="adityabhatt at gmail dot com">adityabhatt at gmail dot com</a>
+- * @author Copyright (C) 2010-2014 by Gilles Caulier
++ * @author Copyright (C) 2010-2015 by Gilles Caulier
+  *         <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
+  * @author Copyright (C) 2010-2013 by Marcel Wiesweg
+  *         <a href="mailto:marcel dot wiesweg at gmx dot de">marcel dot wiesweg at gmx dot de</a>
+@@ -136,13 +136,14 @@
+ 
+     cv::Size getOriginalWindowSize() const
+     {
++#if OPENCV_VERSION <= OPENCV_MAKE_VERSION(2,4,11)
+         // This is a HACK which may break any time. Work around the fact that getOriginalWindowSize()
+         // always returns (0,0) and we need these values.
+         if (oldCascade)
+         {
+             return oldCascade->orig_window_size;
+         }
+-
++#endif
+         return cv::Size(0, 0);
+     }
+ 
+diff -urN digikam-4.13.0/extra/libkface/libkface/libopencv.h.cmake.in digikam-4.13.0-opencv3/extra/libkface/libkface/libopencv.h.cmake.in
+--- digikam-4.13.0/extra/libkface/libkface/libopencv.h.cmake.in	2015-09-03 23:22:44.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/libkface/libkface/libopencv.h.cmake.in	2016-03-22 17:06:26.155608182 +0100
+@@ -7,7 +7,7 @@
+  * @date   2010-06-16
+  * @brief  Wrapper for OpenCV header files
+  *
+- * @author Copyright (C) 2012-2014 by Gilles Caulier
++ * @author Copyright (C) 2012-2015 by Gilles Caulier
+  *         <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a>
+  *
+  * This program is free software; you can redistribute it
+@@ -31,16 +31,16 @@
+ 
+ // Pragma directives to reduce warnings from OpenCV header files.
+ #if not defined(__APPLE__) && defined(__GNUC__)
+-#pragma GCC diagnostic push
+-#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
+-#pragma GCC diagnostic ignored "-Woverloaded-virtual"
++#   pragma GCC diagnostic push
++#   pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
++#   pragma GCC diagnostic ignored "-Woverloaded-virtual"
+ #endif
+ 
+ #if defined(__APPLE__) && defined(__clang__)
+-#pragma clang diagnostic push
+-#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+-#pragma clang diagnostic ignored "-Woverloaded-virtual"
+-#pragma clang diagnostic ignored "-Wcast-align"
++#   pragma clang diagnostic push
++#   pragma clang diagnostic ignored "-Wnon-virtual-dtor"
++#   pragma clang diagnostic ignored "-Woverloaded-virtual"
++#   pragma clang diagnostic ignored "-Wcast-align"
+ #endif
+ 
+ // OpenCV includes
+@@ -51,23 +51,30 @@
+ #define OPENCV_VERSION                         OPENCV_MAKE_VERSION(CV_MAJOR_VERSION,CV_MINOR_VERSION,CV_SUBMINOR_VERSION)
+ #define OPENCV_TEST_VERSION(major,minor,patch) ( OPENCV_VERSION >= OPENCV_MAKE_VERSION(major,minor,patch) )
+ 
+-#include <opencv2/core/core.hpp>
+-#include <opencv2/core/internal.hpp>
+-#include <opencv2/contrib/contrib.hpp>
++#if OPENCV_TEST_VERSION(3,0,0)
++#   include <opencv2/face.hpp>
++#   include <opencv2/core.hpp>
++#else
++#   include <opencv2/core/core.hpp>
++#   include <opencv2/core/internal.hpp>
++#   include <opencv2/contrib/extra/libkface/contrib.hpp>
++#endif
+ 
+ // for old-style code
++#if OPENCV_VERSION <= OPENCV_MAKE_VERSION(2,4,11)
++#   include <opencv2/legacy/compat.hpp>
++#endif
+ #include <opencv2/opencv.hpp>
+-#include <opencv2/legacy/compat.hpp>
+ #include <opencv2/highgui/highgui_c.h>
+ #include <opencv/cvaux.h>
+ 
+ // Restore warnings
+ #if not defined(__APPLE__) && defined(__GNUC__)
+-#pragma GCC diagnostic pop
++#   pragma GCC diagnostic pop
+ #endif
+ 
+ #if defined(__APPLE__) && defined(__clang__)
+-#pragma clang diagnostic pop
++#   pragma clang diagnostic pop
+ #endif
+ 
+ #endif // LIB_OPEN_CV_H
+diff -urN digikam-4.13.0/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.cpp digikam-4.13.0-opencv3/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.cpp
+--- digikam-4.13.0/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.cpp	2015-09-03 23:22:44.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.cpp	2016-03-22 17:06:39.782444479 +0100
+@@ -36,6 +36,8 @@
+  *
+  * ============================================================ */
+ 
++#define QT_NO_EMIT
++
+ #include "facerec_borrowed.h"
+ 
+ // C++ includes
+@@ -375,7 +377,11 @@
+     }
+ }
+ 
++#if !OPENCV_TEST_VERSION(3,1,0)
+ void LBPHFaceRecognizer::predict(InputArray _src, int &minClass, double &minDist) const
++#else
++void LBPHFaceRecognizer::predict(cv::InputArray _src, cv::Ptr<cv::face::PredictCollector> collector, const int state) const
++#endif
+ {
+     if(m_histograms.empty())
+     {
+@@ -394,8 +400,12 @@
+                                       m_grid_y,                                                          /* grid size y                 */
+                                       true                                                               /* normed histograms           */
+                                      );
++#if !OPENCV_TEST_VERSION(3,1,0)
+     minDist      = DBL_MAX;
+     minClass     = -1;
++#else
++    collector->init((int)m_histograms.size(), state);
++#endif
+ 
+     // This is the standard method
+ 
+@@ -406,11 +416,19 @@
+         {
+             double dist = compareHist(m_histograms[sampleIdx], query, CV_COMP_CHISQR);
+ 
++#if !OPENCV_TEST_VERSION(3,1,0)
+             if((dist < minDist) && (dist < m_threshold))
+             {
+                 minDist  = dist;
+                 minClass = m_labels.at<int>((int) sampleIdx);
+             }
++#else
++            int label = m_labels.at<int>((int) sampleIdx);
++            if (!collector->emit(label, dist, state))
++            {
++                return;
++            }
++#endif
+         }
+     }
+ 
+@@ -422,7 +440,7 @@
+         // Create map "label -> vector of distances to all histograms for this label"
+         std::map<int, std::vector<int> > distancesMap;
+ 
+-        for(size_t sampleIdx = 0; sampleIdx < m_histograms.size(); sampleIdx++) 
++        for(size_t sampleIdx = 0; sampleIdx < m_histograms.size(); sampleIdx++)
+         {
+             double dist                 = compareHist(m_histograms[sampleIdx], query, CV_COMP_CHISQR);
+             std::vector<int>& distances = distancesMap[m_labels.at<int>((int) sampleIdx)];
+@@ -445,11 +463,18 @@
+             double mean = sum / it->second.size();
+             s          += QString("%1: %2 - ").arg(it->first).arg(mean);
+ 
++#if !OPENCV_TEST_VERSION(3,1,0)
+             if((mean < minDist) && (mean < m_threshold))
+             {
+                 minDist = mean;
+                 minClass = it->first;
+             }
++#else
++            if (!collector->emit(it->first, mean, state))
++            {
++                return;
++            }
++#endif
+         }
+ 
+         kDebug() << s;
+@@ -462,7 +487,7 @@
+         // map "label -> number of histograms"
+         std::map<int, int> countMap;
+ 
+-        for(size_t sampleIdx = 0; sampleIdx < m_histograms.size(); sampleIdx++) 
++        for(size_t sampleIdx = 0; sampleIdx < m_histograms.size(); sampleIdx++)
+         {
+             int label   = m_labels.at<int>((int) sampleIdx);
+             double dist = compareHist(m_histograms[sampleIdx], query, CV_COMP_CHISQR);
+@@ -480,7 +505,9 @@
+             scoreMap[it->second]++;
+         }
+ 
++#if !OPENCV_TEST_VERSION(3,1,0)
+         minDist = 0;
++#endif
+         QString s("Nearest Neighbor score: ");
+ 
+         for (std::map<int,int>::iterator it = scoreMap.begin(); it != scoreMap.end(); ++it)
+@@ -488,17 +515,26 @@
+             double score = double(it->second) / countMap.at(it->first);
+             s           += QString("%1/%2 %3  ").arg(it->second).arg(countMap.at(it->first)).arg(score);
+ 
++#if !OPENCV_TEST_VERSION(3,1,0)
+             if (score > minDist)
+             {
+                 minDist  = score;
+                 minClass = it->first;
+             }
++#else
++            // large is better thus it is -score.
++            if (!collector->emit(it->first, -score, state))
++            {
++                return;
++            }
++#endif
+         }
+ 
+         kDebug() << s;
+     }
+ }
+ 
++#if !OPENCV_TEST_VERSION(3,1,0)
+ int LBPHFaceRecognizer::predict(InputArray _src) const
+ {
+     int    label;
+@@ -506,6 +542,7 @@
+     predict(_src, label, dummy);
+     return label;
+ }
++#endif
+ 
+ // Static method ----------------------------------------------------
+ 
+@@ -531,14 +568,16 @@
+     return ptr;
+ }
+ 
+-CV_INIT_ALGORITHM(LBPHFaceRecognizer, "FaceRecognizer.LBPH-KFaceIface",
+-                  obj.info()->addParam(obj, "radius",     obj.m_radius);
+-                  obj.info()->addParam(obj, "neighbors",  obj.m_neighbors);
+-                  obj.info()->addParam(obj, "grid_x",     obj.m_grid_x);
+-                  obj.info()->addParam(obj, "grid_y",     obj.m_grid_y);
+-                  obj.info()->addParam(obj, "threshold",  obj.m_threshold);
+-                  obj.info()->addParam(obj, "histograms", obj.m_histograms);         // modification: Make Read/Write
+-                  obj.info()->addParam(obj, "labels",     obj.m_labels);             // modification: Make Read/Write
+-                  obj.info()->addParam(obj, "statistic",  obj.m_statisticsMode));    // modification: Add parameter
++#if OPENCV_VERSION <= OPENCV_MAKE_VERSION(2,4,11)
++    CV_INIT_ALGORITHM(LBPHFaceRecognizer, "FaceRecognizer.LBPH-KFaceIface",
++                      obj.info()->addParam(obj, "radius",     obj.m_radius);
++                      obj.info()->addParam(obj, "neighbors",  obj.m_neighbors);
++                      obj.info()->addParam(obj, "grid_x",     obj.m_grid_x);
++                      obj.info()->addParam(obj, "grid_y",     obj.m_grid_y);
++                      obj.info()->addParam(obj, "threshold",  obj.m_threshold);
++                      obj.info()->addParam(obj, "histograms", obj.m_histograms);         // modification: Make Read/Write
++                      obj.info()->addParam(obj, "labels",     obj.m_labels);             // modification: Make Read/Write
++                      obj.info()->addParam(obj, "statistic",  obj.m_statisticsMode));    // modification: Add parameter
++#endif
+ 
+ } // namespace KFaceIface
+diff -urN digikam-4.13.0/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.h digikam-4.13.0-opencv3/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.h
+--- digikam-4.13.0/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.h	2015-09-03 23:22:44.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.h	2016-03-22 17:06:39.782444479 +0100
+@@ -45,7 +45,11 @@
+ namespace KFaceIface
+ {
+ 
++#if OPENCV_TEST_VERSION(3,0,0)
++class LBPHFaceRecognizer : public cv::face::FaceRecognizer
++#else
+ class LBPHFaceRecognizer : public cv::FaceRecognizer
++#endif
+ {
+ public:
+ 
+@@ -99,8 +103,13 @@
+ 
+     ~LBPHFaceRecognizer() {}
+ 
++#if OPENCV_TEST_VERSION(3,0,0)
++    using cv::face::FaceRecognizer::save;
++    using cv::face::FaceRecognizer::load;
++#else
+     using cv::FaceRecognizer::save;
+     using cv::FaceRecognizer::load;
++#endif
+ 
+     static cv::Ptr<LBPHFaceRecognizer> create(int radius=1, int neighbors=8, int grid_x=8, int grid_y=8, double threshold = DBL_MAX, PredictionStatistics statistics = NearestNeighbor);
+ 
+@@ -116,6 +125,8 @@
+      */
+     void update(cv::InputArrayOfArrays src, cv::InputArray labels);
+ 
++
++#if !OPENCV_TEST_VERSION(3,1,0)
+     /**
+      * Predicts the label of a query image in src.
+      */
+@@ -125,6 +136,13 @@
+      * Predicts the label and confidence for a given sample.
+      */
+     void predict(cv::InputArray _src, int &label, double &dist) const;
++#else
++    using cv::face::FaceRecognizer::predict;
++    /*
++     * Predict
++     */
++    void predict(cv::InputArray src, cv::Ptr<cv::face::PredictCollector> collector, const int state = 0) const override;
++#endif
+ 
+     /**
+      * See FaceRecognizer::load().
+@@ -139,6 +157,34 @@
+     /**
+      * Getter functions.
+      */
++#if OPENCV_TEST_VERSION(3,0,0)
++
++    int getNeighbors() const                             { return m_neighbors;            }
++    void setNeighbors(int _neighbors)                    { m_neighbors = _neighbors;      }
++
++    int getRadius()    const                             { return m_radius;               }
++    void setRadius(int radius)                           { m_radius = radius;             }
++
++    int getGrid_x()    const                             { return m_grid_x;               }
++    void setGrid_x(int _grid_x)                          { m_grid_x = _grid_x;            }
++
++    int getGrid_y()    const                             { return m_grid_y;               }
++    void setGrid_y(int _grid_y)                          { m_grid_y = _grid_y;            }
++
++    double getThreshold() const                          { return m_threshold;            }
++    void setThreshold(double _threshold)                 { m_threshold = _threshold;      }
++
++    void setHistograms(std::vector<cv::Mat> _histograms) { m_histograms = _histograms;    }
++    std::vector<cv::Mat> getHistograms() const           { return m_histograms;           }
++
++    void setLabels(cv::Mat _labels)                      { m_labels = _labels;            }
++    cv::Mat getLabels() const                            { return m_labels;               }
++
++    void setStatistic(int _statistic)                    { m_statisticsMode = _statistic; }
++    int getStatistic() const                             { return m_statisticsMode;       }
++
++#else
++
+     int neighbors() const { return m_neighbors; }
+     int radius()    const { return m_radius;    }
+     int grid_x()    const { return m_grid_x;    }
+@@ -147,6 +193,8 @@
+     // NOTE: Implementation done through CV_INIT_ALGORITHM macro from OpenCV.
+     cv::AlgorithmInfo* info() const;
+ 
++#endif
++
+ private:
+ 
+     /** Computes a LBPH model with images in src and
+diff -urN digikam-4.13.0/extra/libkface/libkface/recognition-opencv-lbph/lbphfacemodel.cpp digikam-4.13.0-opencv3/extra/libkface/libkface/recognition-opencv-lbph/lbphfacemodel.cpp
+--- digikam-4.13.0/extra/libkface/libkface/recognition-opencv-lbph/lbphfacemodel.cpp	2015-09-03 23:22:44.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/libkface/libkface/recognition-opencv-lbph/lbphfacemodel.cpp	2016-03-22 17:06:26.155608182 +0100
+@@ -61,7 +61,11 @@
+     : cv::Ptr<LBPHFaceRecognizer>(LBPHFaceRecognizer::create()),
+       databaseId(0)
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    ptr()->setThreshold(100.0);
++#else
+     ptr()->set("threshold", 100.0);
++#endif
+ }
+ 
+ LBPHFaceModel::~LBPHFaceModel()
+@@ -80,9 +84,13 @@
+ 
+ const LBPHFaceRecognizer* LBPHFaceModel::ptr() const
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    const LBPHFaceRecognizer* const ptr = cv::Ptr<LBPHFaceRecognizer>::operator KFaceIface::LBPHFaceRecognizer*();
++#else
+     const LBPHFaceRecognizer* const ptr = cv::Ptr<LBPHFaceRecognizer>::operator const KFaceIface::LBPHFaceRecognizer*();
++#endif
+ 
+-    if (!ptr) 
++    if (!ptr)
+         kWarning() << "LBPHFaceRecognizer pointer is null";
+ 
+     return ptr;
+@@ -90,47 +98,83 @@
+ 
+ int LBPHFaceModel::radius() const
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    return ptr()->getRadius();
++#else
+     return ptr()->get<int>("radius");
++#endif
+ }
+ 
+ void LBPHFaceModel::setRadius(int radius)
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    ptr()->setRadius(radius);
++#else
+     ptr()->set("radius", radius);
++#endif
+ }
+ 
+ int LBPHFaceModel::neighbors() const
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    return ptr()->getNeighbors();
++#else
+     return ptr()->get<int>("neighbors");
++#endif
+ }
+ 
+ void LBPHFaceModel::setNeighbors(int neighbors)
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    ptr()->setNeighbors(neighbors);
++#else
+     ptr()->set("neighbors", neighbors);
++#endif
+ }
+ 
+ int LBPHFaceModel::gridX() const
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    return ptr()->getGrid_x();
++#else
+     return ptr()->get<int>("grid_x");
++#endif
+ }
+ 
+ void LBPHFaceModel::setGridX(int grid_x)
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    ptr()->setGrid_x(grid_x);
++#else
+     ptr()->set("grid_x", grid_x);
++#endif
+ }
+ 
+ int LBPHFaceModel::gridY() const
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    return ptr()->getGrid_y();
++#else
+     return ptr()->get<int>("grid_y");
++#endif
+ }
+ 
+ void LBPHFaceModel::setGridY(int grid_y)
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    ptr()->setGrid_y(grid_y);
++#else
+     ptr()->set("grid_y", grid_y);
++#endif
+ }
+ 
+ OpenCVMatData LBPHFaceModel::histogramData(int index) const
+ {
++#if OPENCV_TEST_VERSION(3,0,0)
++    return OpenCVMatData(ptr()->getHistograms().at(index));
++#else
+     return OpenCVMatData(ptr()->get<std::vector<cv::Mat> >("histograms").at(index));
++#endif
+ }
+ 
+ QList<LBPHistogramMetadata> LBPHFaceModel::histogramMetadata() const
+@@ -168,12 +212,24 @@
+         m_histogramMetadata << metadata;
+     }
+ 
++#if OPENCV_TEST_VERSION(3,0,0)
++    std::vector<cv::Mat> currentHistograms = ptr()->getHistograms();
++    cv::Mat currentLabels                  = ptr()->getLabels();
++#else
+     std::vector<cv::Mat> currentHistograms = ptr()->get<std::vector<cv::Mat> >("histograms");
+     cv::Mat currentLabels                  = ptr()->get<cv::Mat>("labels");
++#endif
++
+     currentHistograms.insert(currentHistograms.end(), newHistograms.begin(), newHistograms.end());
+     currentLabels.push_back(newLabels);
++
++#if OPENCV_TEST_VERSION(3,0,0)
++    ptr()->setHistograms(currentHistograms);
++    ptr()->setLabels(currentLabels);
++#else
+     ptr()->set("histograms", currentHistograms);
+-    ptr()->set("labels", currentLabels);
++    ptr()->set("labels",     currentLabels);
++#endif
+ 
+ /*
+     //Most cumbersome and inefficient way through a file storage which we were forced to use if we used standard OpenCV
+@@ -215,7 +271,11 @@
+ 
+     // Update local information
+     // We assume new labels are simply appended
++#if OPENCV_TEST_VERSION(3,0,0)
++    cv::Mat currentLabels = ptr()->getLabels();
++#else
+     cv::Mat currentLabels = ptr()->get<cv::Mat>("labels");
++#endif
+ 
+     for (int i = m_histogramMetadata.size() ; i < currentLabels.rows ; i++)
+     {
+diff -urN digikam-4.13.0/extra/libkface/README digikam-4.13.0-opencv3/extra/libkface/README
+--- digikam-4.13.0/extra/libkface/README	2015-09-03 23:22:44.000000000 +0200
++++ digikam-4.13.0-opencv3/extra/libkface/README	2016-03-22 17:06:26.155608182 +0100
+@@ -21,6 +21,11 @@
+ libkde     >= 4.4.x                    http://www.kde.org
+ libopencv  >= 2.4.9                    http://opencv.willowgarage.com/wiki    (with opencv 'haarcascades' data files)
+ 
++CMake compilation options to custom libkface:
++
++Use CMake "-DENABLE_OPENCV3=on"        flag to compile libkface source code using OpenCV3 instead OpenCV2 (disabled by default).
++                                       OpenCV3 support needs extra contrib modules package, especially 'face' ands 'legacy' components.
++
+ -- INSTALL ------------------------------------------------------------
+ 
+ In order to compile, especially when QT3/Qt4 are installed at the same time,
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/digikam.git/commitdiff/e028b4c57dc75a02f67112f2029cfff8472eea1f



More information about the pld-cvs-commit mailing list