Bug 349601 - digikam compile fine with OpenCV 2.X but not with 3.x
Summary: digikam compile fine with OpenCV 2.X but not with 3.x
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Portability-Compilation (show other bugs)
Version: 4.9.0
Platform: MacPorts macOS
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-25 15:22 UTC by Detlef
Modified: 2017-08-19 20:58 UTC (History)
12 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.14.0


Attachments
incomplete patch (8.55 KB, patch)
2015-07-23 11:48 UTC, Jozef Mlich
Details
completed patch (9.38 KB, patch)
2015-08-18 01:52 UTC, Adam Stylinski
Details
libkface-15.04.2-opencv3.patch (10.20 KB, patch)
2015-08-18 16:48 UTC, Viktor Jancik
Details
digikam-4.12.0-opencv3.patch (5.55 KB, patch)
2015-08-18 17:07 UTC, Viktor Jancik
Details
libkface-15.04.2-opencv3.patch (10.20 KB, patch)
2015-08-19 05:29 UTC, Viktor Jancik
Details
attachment-30477-0.html (119 bytes, text/html)
2015-09-02 21:53 UTC, Adam Stylinski
Details
attachment-30931-0.html (349 bytes, text/html)
2015-09-02 22:02 UTC, Adam Stylinski
Details
libkface OpenCV3 support patch version 3 (15.12 KB, patch)
2015-09-05 17:20 UTC, caulier.gilles
Details
digiKam core OpenCV3 support patch version 3 (5.43 KB, patch)
2015-09-05 18:58 UTC, caulier.gilles
Details
kipi-plugins OpenCV3 support patch version 3 (5.66 KB, patch)
2015-09-05 19:16 UTC, caulier.gilles
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Detlef 2015-06-25 15:22:12 UTC
Installing digikam via MacPort is building a binary very well, but now has MacPort an upgrade of opencv from 2.x to 3.x and now it is impossible to compile digikam. Every time there come an error for an not existing library "opencv/legacy/compat.hpp" not found. deactivating opencv 3.x and activating opencv 2.x and then compiling digikam works fine.

Probing the running of digikam with binaries of a package for version 4.10.x and 4.11.x gives a crash while starting the digikam.app.

Reproducible: Always

Steps to Reproduce:
1. port Activate opencv @3.0.0
2. port clean digikam; port build digikam
3. Error while compiling
4. port activate opencv 2.x
5. port clean digikam; port install digikam
6. Now exist a running digikam

Actual Results:  
I can't use opencv 3.x

Expected Results:  
A running digikam while opencv is upgraded
Comment 1 demm 2015-06-29 23:28:19 UTC
Same error if trying to compile on Linux with OpenCV 3.0.0
Comment 2 Jozef Mlich 2015-07-23 11:48:23 UTC
Created attachment 93709 [details]
incomplete patch

According to OpenCV Transition Guide [1] was CV_INIT_ALGORITHM macro removed. I have started writing of patch for that. It is not finished, but it may help someone.

[1] http://docs.opencv.org/master/db/dfa/tutorial_transition_guide.html
Comment 3 Nirvandil 2015-08-09 17:06:10 UTC
Same problem in Gentoo ~amd64, when compiling libkface-4.12.0 with opencv-3.0.0 I've got error:
/var/tmp/portage/media-libs/libkface-4.12.0/work/libkface-4.12.0_build/libkface/libopencv.h:55:37: fatal error: opencv2/core/internal.hpp: No such file or directory
 #include <opencv2/core/internal.hpp>
Comment 4 Adam Stylinski 2015-08-18 01:52:47 UTC
Created attachment 94088 [details]
completed patch

If anyone's interested, I may have this completed?  It compiles, I haven't tested it just yet, though.  The CV_ALGORITHM_INIT macro is now gone, but I'm not sure if/where I'd need to call the new factory they are providing in facerec.hpp (OpenCV's semantics for defining an algorithm are kind of confusing in C++).  

I've attached the updated patch if anyone's interested.  It's against the 14.12 branch in git, but it will likely work in later ones as well.
Comment 5 Adam Stylinski 2015-08-18 04:59:01 UTC
Just finally got around to testing this (digikam is using the legacy API for some reason in imgqsort, the change is extremely minor to make it compile and work).  Libkface is not working properly, it's claiming the model hasn't been trained a lot and eventually it crashes from all the openCV exceptions.  I suspect that we'll need to find the analog to CV_ALGORITHM_INIT.
Comment 6 Viktor Jancik 2015-08-18 16:48:14 UTC
Created attachment 94096 [details]
libkface-15.04.2-opencv3.patch

I found an additional error,

The haarcascade files are located in /usr/share/OpenCV/haarcascades, which can be seen by running:
rpm -ql opencv

If you have opencv version 3 installed.

However the original ${OpenCV_DIR} points to the base of the OpenCV library directory.
As described here: http://code.opencv.org/attachments/196/FindOpenCV.cmake
Specifically /usr/lib64/OpenCV

Instead, {OpenCV_SHARED} should be used which points to /usr/share/OpenCV as described here: https://github.com/Itseez/opencv/blob/master/cmake/OpenCVConfig.cmake

The values of these variables can be verified after building by looking at CMake Cache.txt

Additionally I changed the minimum required version to 3.0.0 because I am not sure if the changes also build for OpenCV version 2.4, this needs to be checked.

And lastly I included face.hpp instead of face/facerec.hpp but they include each other so it's the same.


The successful build with these changes can be seen here:
https://copr.fedoraproject.org/coprs/vjancik/opencv3-deps/build/109623/
Comment 7 caulier.gilles 2015-08-18 16:49:42 UTC
In the pass, i accidentally checkout OpenCV from master which correspond to current 3.0 (while 2.x was stable release).

I discovered that CV_ALGORITHM_INIT disappear. Thinking about working with 2.x, i tried to fix the problem. The only solution was to import this macro into libkface as well.

Of course, when i discovered that i don't work with right OpenCV  branch i cancelled my work as well. Sound like this must be re-iterate if we want to not re-write whole implementation about face management from libkface.

Gilles Caulier
Comment 8 Viktor Jancik 2015-08-18 17:07:40 UTC
Created attachment 94097 [details]
digikam-4.12.0-opencv3.patch

This patch doesn't contain fixes for libkface directly, because digikam is configured to build with the system version of libkface, so instead I created a separate patch that fixes the system version of libkface.

Despite that fix, digikam still wouldn't build against OpenCV 3 and had numerous errors.

cvCreateMat returns cvMat but variable d is of type Mat, a 1 to 1 replacement was possible with the Mat constructor.
In core/libs/database/imgqsort/imgqsort.cpp vector containers were missing the std:: namespace prefix. How did it build before?
In extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp I had to add a definition of cvFillImage because it was removed from OpenCV 3. The definition is exactly the same as it was in OpenCV 2.4.11.
I had to conditionally disable the building of ipptest because it used a function that no longer exists in OpenCV 3 (cvGetModuleInfo) and I couldn't find / create a replacement. As a consequence, I am not sure if the tests pass properly, because I am not sure if this is a good way to disable a test.
And lastly, I had to modify the includes in 2 libopencv.h files and modify the OPENCV_TEST_VERSION macros as they didn't work as intended for versions 2.3.0 up to 2.4.X Yes, there are two libopencv.h files.
Comment 9 Viktor Jancik 2015-08-18 17:12:59 UTC
Successful build with patched digikam and patched libkface can be seen here:
https://copr.fedoraproject.org/coprs/vjancik/opencv3-deps/build/109686/
Comment 10 caulier.gilles 2015-08-18 17:13:35 UTC
I don't checked your patch yet, but did you take a care about to wrap current implementation with a relevant pre-processor macro depending of OpenCV version ?

Typically, OpenCV 2 -> 3 transition will take a time and we can be necessary to support both versions at the same time for a while.

Another solution is only to dedicate your patch to next digiKam 5.0.0 release (frameworks branches) and to only support OpenCV 3 with this version. digiKam 4.x will only support OpenCV 2. As 5.0.0 is planed next year, this can be acceptable.

Note that first solution will increase complexity of code.

Your viewpoint ?

Gilles Caulier
Comment 11 Adam Stylinski 2015-08-18 17:21:19 UTC
I see the first solution is worth the added complexity.  The changes are relatively minor at the API level and the core algorithms generally behave the same.  I think the missing haarcascades may have been why my version when compiled would complain about lack of training data.  I'll try Viktor's patches when I get home.
Comment 12 Viktor Jancik 2015-08-18 17:27:18 UTC
Yes, I believe the digikam changes will work for both OpenCV 2.4 and 3. You can see, that most if not all of my modifications are preceded with a OpenCV version conditional.

I didn't try to build it against 2.4, so there might be some slight error.

As for the libkface patch, I am fairly positive it won't build against OpenCV 2.4. There was no obvious infrastructure in place for such branching, and I didn't want to commit work to making it build with 2.4, since I am not too familiar with the project or the coding guidelines, which means it would have to be reworked anyways.
Comment 13 Adam Stylinski 2015-08-18 17:45:47 UTC
It may require a lot of preprocessor statements but making libkface work with both 3.x and 2.x is doable.  Many distributions are including 3, and 3 is supposed be mainly a progression of the version 2 API (unlike OpenCV's earlier version jumps).  Maybe the solution to being 2.4 compatible is writing a separate source file for the FaceRecognizer and let CMake conditionally compile it.
Comment 14 Adam Stylinski 2015-08-18 22:40:52 UTC
Viktor, just applied your patches, still having the same problem I was before.  After doing the face detect, libkface prints the following error:

OpenCV Error: Bad argument (This LBPH model is not computed yet. Did you call the train method?) in predict, file /scratchdir/tmp/portage/media-libs/libkface-4.12.0-r2/work/digikam-4.12.0/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.cpp, line 384
digikam(17371)/KFACE: cv::Exception: /scratchdir/tmp/portage/media-libs/libkface-4.12.0-r2/work/digikam-4.12.0/extra/libkface/libkface/recognition-opencv-lbph/facerec_borrowed.cpp:384: error: (-5) This LBPH model is not computed yet. Did you call the train method? in function predict
Comment 15 Adam Stylinski 2015-08-19 00:00:53 UTC
Hmm that error could have been innocuous (based on some searches with Google - some more training data may have been needed to be supplied), but I get a very real hard crash if I let it run long enough, with a double free:

*** Error in `digikam': free(): invalid next size (normal): 0x00007fe0b84a6bf0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7237c)[0x7fe0fb95337c]
/lib64/libc.so.6(+0x779ae)[0x7fe0fb9589ae]
/lib64/libc.so.6(+0x7818b)[0x7fe0fb95918b]
/usr/lib64/libopencv_imgproc.so.3.0(_ZN2cv5CannyERKNS_11_InputArrayERKNS_12_OutputArrayEddib+0x5ca)[0x7fe0ffab408a]
/usr/lib64/libopencv_imgproc.so.3.0(cvCanny+0x19b)[0x7fe0ffab5ecb]
/usr/lib64/libopencv_objdetect.so.3.0(_Z25cvHaarDetectObjectsForROCPKvP23CvHaarClassifierCascadeP12CvMemStorageRSt6vectorIiSaIiEERS5_IdSaIdEEdii6CvSizeSC_b+0x215f)[0x7fe0f7e1a29f]
/usr/lib64/libopencv_objdetect.so.3.0(+0x40b90)[0x7fe0f7e33b90]
/usr/lib64/libopencv_objdetect.so.3.0(+0x41082)[0x7fe0f7e34082]
/usr/lib64/libopencv_objdetect.so.3.0(+0x2cf3b)[0x7fe0f7e1ff3b]
/usr/lib64/libopencv_objdetect.so.3.0(_ZN2cv17CascadeClassifier16detectMultiScaleERKNS_11_InputArrayERSt6vectorINS_5Rect_IiEESaIS6_EEdiiNS_5Size_IiEESB_+0xc6)[0x7fe0f7e32fb6]
/usr/lib64/libkface.so.3(+0x1b742)[0x7fe0ffe96742]
/usr/lib64/libkface.so.3(+0x1e029)[0x7fe0ffe99029]
/usr/lib64/libkface.so.3(_ZN10KFaceIface12FaceDetector11detectFacesERK6QImageRK5QSize+0x9c)[0x7fe0ffe89d0c]
digikam[0x7a8a60]
digikam[0x7a8e12]
/usr/lib64/qt4/libQtCore.so.4(_ZN7QObject5eventEP6QEvent+0x25e)[0x7fe0fc3e632e]
/usr/lib64/qt4/libQtGui.so.4(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0x8c)[0x7fe0fcb4effc]
/usr/lib64/qt4/libQtGui.so.4(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x1c1)[0x7fe0fcb57d21]
/usr/lib64/libkdeui.so.5(_ZN12KApplication6notifyEP7QObjectP6QEvent+0x33)[0x7fe0fe173b43]
/usr/lib64/qt4/libQtCore.so.4(_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent+0x75)[0x7fe0fc3c70d5]
/usr/lib64/qt4/libQtCore.so.4(_ZN23QCoreApplicationPrivate16sendPostedEventsEP7QObjectiP11QThreadData+0x1ea)[0x7fe0fc3cbd2a]
/usr/lib64/qt4/libQtCore.so.4(+0x1ea0ae)[0x7fe0fc3ff0ae]
/usr/lib64/libglib-2.0.so.0(g_main_context_dispatch+0x27c)[0x7fe0f4c2610c]
/usr/lib64/libglib-2.0.so.0(+0x54398)[0x7fe0f4c26398]
/usr/lib64/libglib-2.0.so.0(g_main_context_iteration+0x2c)[0x7fe0f4c2643c]
/usr/lib64/qt4/libQtCore.so.4(_ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE+0x7e)[0x7fe0fc3fe01e]
/usr/lib64/qt4/libQtCore.so.4(_ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE+0x38)[0x7fe0fc3c50b8]
/usr/lib64/qt4/libQtCore.so.4(_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE+0x185)[0x7fe0fc3c53d5]
/usr/lib64/libdigikamcore.so.4.12.0(+0x3a0a58)[0x7fe101569a58]
/usr/lib64/qt4/libQtCore.so.4(+0x7389b)[0x7fe0fc28889b]
/usr/lib64/qt4/libQtCore.so.4(+0x83327)[0x7fe0fc298327]
/lib64/libpthread.so.0(+0x7304)[0x7fe0fa7a4304]
/lib64/libc.so.6(clone+0x6d)[0x7fe0fb9c8c1d]
Comment 16 Viktor Jancik 2015-08-19 00:06:04 UTC
That error message gets created if the member variable m_histograms of the class LBPHFaceRecognizer which is of type std::vector<cv::Mat> is empty.
Unless the getter/setter methods we created are not working (which they have no reason not to) I have no idea why that vector is empty.

Could you try building and running the tests of the patched libkface? Separately from digikam? A few of them use the train method, and should fail if we broke it.
Comment 17 Adam Stylinski 2015-08-19 01:35:02 UTC
My feature vectors are also being serialized into a MySQL database for my backend instead of the default sqlite3, so that could also have something to do with it.  I'll try your tests but if your unit tests work I assume mine probably will too.  The issues I'm seeing admittedly could have been there all along, I haven't heavily used this feature.  The face detect seems to be working right now, I manually gave it a ton of training data so I'm trying the facial recognition right now.  I did the detect and recognize option when it was churning forever (and eventually crashed).
Comment 18 Adam Stylinski 2015-08-19 01:38:13 UTC
I have what looks like 12,014 HaarMatrices:

SELECT COUNT(*) FROM digikam.ImageHaarMatrix;
12014

I'm assuming some of these I had generated prior to updating.  Hopefully OpenCV didn't modify how these things are serialized...
Comment 19 caulier.gilles 2015-08-19 04:48:12 UTC
No HaarMatrix are not generated by libkface, but by digiKam through FindDupplicates items feature. This has nothing to see with faces managament.

The Faces database is Sqlite3 only located in a dedicated database file. Look API doc for details :

http://api.kde.org/4.x-api/kdegraphics-apidocs/libs/libkface/libkface/html/index.html

Gilles Caulier
Comment 20 caulier.gilles 2015-08-19 04:55:25 UTC
m_histograms dysfunction is certainly due to  haar cascade files from OpenCV not loaded. But in this case, libkexiv2 must generate a warning in the console.

Also, take a care that harr cascade XML files from openCV 3 can be different than OpenCV 2, and placed at a different place (OpenCV is a big puzzle). Perhaps the path to parse from system to find haar cascade files must be patch to support OpenCV 3.

Note: haar cascades files included in libkface as well are for Windows only, as under windows, OpenCV 2 do not install these files...

Gilles Caulier
Comment 21 Viktor Jancik 2015-08-19 05:29:31 UTC
Created attachment 94108 [details]
libkface-15.04.2-opencv3.patch

I messed up. After better inspection, OpenCV_SHARED is a boolean variable, which is used inside the Config script as an identifier whether OpenCV was build as a shared library or static. So it has nothing to do with the shared files path.

I found no other CMake variable pointing to the shared directory so I hardcoded the path for now. Both OpenCV 2.4 and OpenCV 3 put haarcascades in this folder on Fedora.

It should definitely find them now. Does that fix the issue?
Comment 22 caulier.gilles 2015-08-19 09:08:06 UTC
Victor,

To make whole digiKam Software collection compatible with OpenCV 3, there are 2 others parts to port :

- Kipi-plugins : there are OpenCV API used in RemoveRedEyes tool (can be long to do but more simpler in all cases than libkface).
- digiKam : in tests code some implementations use OpenCV API (nothing hard to do). To enable test code compilation with digiKam use -DKDE4_BUILD_TESTS=ON" cmake flag at configuration time.

Gilles Caulier
Comment 23 Adam Stylinski 2015-08-20 01:44:07 UTC
Welp, at 40% so far (churning on all cores) for detect and recognize option in kface plugin.  Hasn't crashed yet, we'll see how this turns out.  I chose the "merge" scan instead of skip (and after forcing the algorithm it retrain, building a new local database).  

A lot of false positives on the faces, but a lot of true ones too, so I would say that that portion is working.  Given the size of my training set and the percentage threshold a specified it unsurprisingly is not trying to tag many of my images.  It's tagged a few, mostly wrong but a few right, but I may be expecting way too much from a machine learning technique (having implemented a few computer vision algorithms myself, I know how finnicky they can be). 

I'm guessing this is the status quo with KFace (judging based on the "experimental" label on the radio button).  Would I be wrong?
Comment 24 Viktor Jancik 2015-09-01 10:57:10 UTC
Adam,

Thank you for your help. Could I ask you for one more test?

Would you try comparing the face recognition in the patched Digikam and libkface with OpenCV 3 against the original ones with OpenCV 2? That should decide how badly it's broken.
Comment 25 Adam Stylinski 2015-09-01 17:35:56 UTC
Detection or recognition?  I think it will be hard to determine what degree of correctness either of them have for recognition considering it's a machine learning algorithm.  I can give it the same faces to train on but I suspect the results won't be qualitatively different.  It may need to wait until later in the week when I have some time in the evening.  Is there a good way to throw out all of the tags digikam assigned during the recognition phase without manually going through each person tag and removing the tag?
Comment 26 Willy Sudiarto Raharjo 2015-09-02 06:21:37 UTC
Hi

If OpenCV 3.0 built with IPP feature turned ON (which is by default, unless turned OFF with WITH_IPP=OFF), will cause digikam failed to build at linking process. If IPP feature are turned OFF, digikam can be compiled nicely, but it will require DIGIKAMSC_COMPILE_LIBKFACE=OFF to be set and this will make digikam loose it's face detection feature.

I used Viktor's digikam-4.12.0-opencv3.patch to build digiKam in SBo repository
http://slackbuilds.org/cgit/slackbuilds/commit/?h=opencv-review&id=6042dbc90c29beb20290d9a2d5cb92dc44e1480f

i tried to include  libkface-15.04.2-opencv3.patch as well, but it still failed to build.
Comment 27 Willy Sudiarto Raharjo 2015-09-02 21:15:14 UTC
Here's the failure point

[  1%] Building CXX object extra/libkface/libkface/CMakeFiles/kface.dir/facedetector.cpp.o
cd /tmp/SBo/digikam-4.12.0/build/extra/libkface/libkface && /usr/bin/c++   -DKDE4_CMAKE_TOPLEVEL_DIR_LENGTH=8 -DKDE_DEFAULT_DEBUG_AREA=51005 -DKDE_DEPRECATED_WARNINGS -DMAKE_KFACE_LIB -DQT_NO_CAST_TO_ASCII -DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_REENTRANT -D_XOPEN_SOURCE=500 -lMagick++-6.Q16 -lMagickWand-6.Q16 -lMagickCore-6.Q16 -Wnon-virtual-dtor -Wno-long-long -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -DQT_NO_EXCEPTIONS -fno-check-new -fno-common -Woverloaded-virtual -fno-threadsafe-statics -fvisibility=hidden -Werror=return-type -fvisibility-inlines-hidden -O2 -DNDEBUG -DQT_NO_DEBUG -fPIC -I/tmp/SBo/digikam-4.12.0/build/extra/libkface/libkface -I/tmp/SBo/digikam-4.12.0/extra/libkface/libkface -I/tmp/SBo/digikam-4.12.0/extra/libkface/libkface/database -I/tmp/SBo/digikam-4.12.0/extra/libkface/libkface/detection -I/tmp/SBo/digikam-4.12.0/extra/libkface/libkface/recognition-opencv-lbph -I/tmp/SBo/digikam-4.12.0/extra/libkface/libkface/alignment-congealing -I/usr/include/KDE -I/usr/lib/qt/include/QtXmlPatterns -I/usr/lib/qt/include/QtXml -I/usr/lib/qt/include/QtWebKit -I/usr/lib/qt/include/QtUiTools -I/usr/lib/qt/include/QtTest -I/usr/lib/qt/include/QtSvg -I/usr/lib/qt/include/QtSql -I/usr/lib/qt/include/QtScriptTools -I/usr/lib/qt/include/QtScript -I/usr/lib/qt/include/QtOpenGL -I/usr/lib/qt/include/QtNetwork -I/usr/lib/qt/include/QtMultimedia -I/usr/lib/qt/include/QtHelp -I/usr/lib/qt/include/QtDesigner -I/usr/lib/qt/include/QtDeclarative -I/usr/lib/qt/include/QtDBus -I/usr/lib/qt/include/Qt3Support -I/usr/lib/qt/include/QtGui -I/usr/lib/qt/include/QtCore -I/usr/lib/qt/include/Qt -I/usr/lib/qt/mkspecs/default -I/usr/include/opencv    -fexceptions -UQT_NO_EXCEPTIONS -D_GNU_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -o CMakeFiles/kface.dir/facedetector.cpp.o -c /tmp/SBo/digikam-4.12.0/extra/libkface/libkface/facedetector.cpp
In file included from /tmp/SBo/digikam-4.12.0/extra/libkface/libkface/detection/opencvfacedetector.h:40:0,
                 from /tmp/SBo/digikam-4.12.0/extra/libkface/libkface/facedetector.cpp:29:
/tmp/SBo/digikam-4.12.0/build/extra/libkface/libkface/libopencv.h:54:36: fatal error: opencv2/face/facerec.hpp: No such file or directory
 #include <opencv2/face/facerec.hpp>
                                    ^
compilation terminated.
make[2]: *** [extra/libkface/libkface/CMakeFiles/kface.dir/facedetector.cpp.o] Error 1
make[2]: Leaving directory `/tmp/SBo/digikam-4.12.0/build'
make[1]: *** [extra/libkface/libkface/CMakeFiles/kface.dir/all] Error 2
make[1]: Leaving directory `/tmp/SBo/digikam-4.12.0/build'
make: *** [all] Error 2
Comment 28 Adam Stylinski 2015-09-02 21:53:41 UTC
Created attachment 94358 [details]
attachment-30477-0.html

It doesn't appear you've applied both patches. Can you paste the output of
your patch command?
Comment 29 Willy Sudiarto Raharjo 2015-09-02 21:56:48 UTC
cat opencv.patch libkface.patch 
diff -up digikam-4.12.0/core/app/utils/libopencv.h.opencv3 digikam-4.12.0/core/app/utils/libopencv.h
--- digikam-4.12.0/core/app/utils/libopencv.h.opencv3   2015-08-18 15:32:24.635326685 +0200
+++ digikam-4.12.0/core/app/utils/libopencv.h   2015-08-18 16:51:00.716761209 +0200
@@ -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 -up digikam-4.12.0/core/libs/database/imgqsort/imgqsort.cpp.opencv3 digikam-4.12.0/core/libs/database/imgqsort/imgqsort.cpp
--- digikam-4.12.0/core/libs/database/imgqsort/imgqsort.cpp.opencv3     2015-08-18 17:17:24.003431310 +0200
+++ digikam-4.12.0/core/libs/database/imgqsort/imgqsort.cpp     2015-08-18 17:25:14.761703338 +0200
@@ -284,8 +284,8 @@ void ImgQSort::readImage() const
     mixer.startFilterDirectly();
 
     d->image.putImageData(mixer.getTargetImage().bits());
-    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
+    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
 
     if (d->imq.detectNoise)
     {
@@ -660,7 +660,7 @@ int ImgQSort::compressiondetector() cons
     int countblocks      = 0;
     int number_of_blocks = 0;
     int sum              = 0;
-    vector<int> average_bottom, average_middle, average_top;
+    std::vector<int> average_bottom, average_middle, average_top;
 
     // Go through 8 blocks at a time horizontally
     // iterating through columns.
@@ -797,7 +797,7 @@ int ImgQSort::compressiondetector() cons
 int ImgQSort::exposureamount() const
 {
     /// Separate the image in 3 places ( B, G and R )
-    vector<Mat> bgr_planes;
+    std::vector<Mat> bgr_planes;
     split(d->src, bgr_planes);
 
     /// Establish the number of bins
diff -up digikam-4.12.0/core/libs/database/imgqsort/imgqsort.h.opencv3 digikam-4.12.0/core/libs/database/imgqsort/imgqsort.h
--- digikam-4.12.0/core/libs/database/imgqsort/imgqsort.h.opencv3       2015-08-18 17:17:54.923383497 +0200
+++ digikam-4.12.0/core/libs/database/imgqsort/imgqsort.h       2015-08-18 17:27:54.225449446 +0200
@@ -25,6 +25,10 @@
 #ifndef IMGQSORT_H
 #define IMGQSORT_H
 
+// Global includes
+
+#include <vector>
+
 // Local includes
 
 #include "dimg.h"
diff -up digikam-4.12.0/extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp.opencv3 digikam-4.12.0/extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp
--- digikam-4.12.0/extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp.opencv3 2015-08-18 16:06:08.240514617 +0200
+++ digikam-4.12.0/extra/kipi-plugins/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp 2015-08-18 16:19:07.774476511 +0200
@@ -89,6 +89,13 @@ const QString HaarClassifierLocator::Pri
 const QString HaarClassifierLocator::Private::configClassifierEntry("Classifier");
 
 // --------------------------------------------------------
+#if !(OPENCV_TEST_VERSION(2,5,0))
+static void cvFillImage( CvArr* mat, double color)
+{
+    cvSet( mat, cvColorToScalar(color, cvGetElemType(mat)), 0);
+}
+#endif
+
 
 int HaarClassifierLocator::findPossibleEyes(double csf, int ngf, const char* classifierFile)
 {
diff -up digikam-4.12.0/extra/kipi-plugins/removeredeyes/plugin/libopencv.h.opencv3 digikam-4.12.0/extra/kipi-plugins/removeredeyes/plugin/libopencv.h
--- digikam-4.12.0/extra/kipi-plugins/removeredeyes/plugin/libopencv.h.opencv3  2015-08-18 13:43:10.380772123 +0200
+++ digikam-4.12.0/extra/kipi-plugins/removeredeyes/plugin/libopencv.h  2015-08-18 14:18:27.999977347 +0200
@@ -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 -up digikam-4.12.0/extra/kipi-plugins/removeredeyes/test/CMakeLists.txt.opencv3 digikam-4.12.0/extra/kipi-plugins/removeredeyes/test/CMakeLists.txt
--- digikam-4.12.0/extra/kipi-plugins/removeredeyes/test/CMakeLists.txt.opencv3 2015-08-18 15:08:31.973733608 +0200
+++ digikam-4.12.0/extra/kipi-plugins/removeredeyes/test/CMakeLists.txt 2015-08-18 15:22:40.113991709 +0200
@@ -4,7 +4,7 @@
 # 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 --git a/CMakeLists.txt b/CMakeLists.txt
index 4e83c8b..e399a25 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,7 +30,7 @@ add_definitions(-DKDE_DEFAULT_DEBUG_AREA=${LIBKFACE_AREA_CODE_GENERAL})
 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)
+DETECT_OPENCV(2.4.9 core highgui objdetect face legacy imgproc)
 
 include_directories(${OpenCV_INCLUDE_DIRS})
 
diff --git a/cmake/modules/modules_opencv/FindOpenCV.cmake b/cmake/modules/modules_opencv/FindOpenCV.cmake
index 7580b32..6d3da76 100644
--- a/cmake/modules/modules_opencv/FindOpenCV.cmake
+++ b/cmake/modules/modules_opencv/FindOpenCV.cmake
@@ -173,7 +173,6 @@ find_library(OpenCV_ML_LIBRARY
 find_library(OpenCV_TRS_LIBRARY  
     NAMES trs
     PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
-
 #
 # Logic selecting required libs and headers
 #
diff --git a/libkface/detection/opencvfacedetector.cpp b/libkface/detection/opencvfacedetector.cpp
index 7c420ae..28edeea 100644
--- a/libkface/detection/opencvfacedetector.cpp
+++ b/libkface/detection/opencvfacedetector.cpp
@@ -138,11 +138,12 @@ public:
     {
         // 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;
         }
-
+*/
         return cv::Size(0, 0);
     }
 
diff --git a/libkface/libopencv.h.cmake.in b/libkface/libopencv.h.cmake.in
index 0a1a958..e70fc0c 100644
--- a/libkface/libopencv.h.cmake.in
+++ b/libkface/libopencv.h.cmake.in
@@ -51,13 +51,11 @@
 #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>
+#include <opencv2/face/facerec.hpp>
+#include <opencv2/core.hpp>
 
 // for old-style code
 #include <opencv2/opencv.hpp>
-#include <opencv2/legacy/compat.hpp>
 #include <opencv2/highgui/highgui_c.h>
 #include <opencv/cvaux.h>
 
diff --git a/libkface/recognition-opencv-lbph/facerec_borrowed.cpp b/libkface/recognition-opencv-lbph/facerec_borrowed.cpp
index 935a3d0..11aee02 100644
--- a/libkface/recognition-opencv-lbph/facerec_borrowed.cpp
+++ b/libkface/recognition-opencv-lbph/facerec_borrowed.cpp
@@ -531,14 +531,5 @@ Ptr<LBPHFaceRecognizer> LBPHFaceRecognizer::create(int radius, int neighbors, in
     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
 
 } // namespace KFaceIface
diff --git a/libkface/recognition-opencv-lbph/facerec_borrowed.h b/libkface/recognition-opencv-lbph/facerec_borrowed.h
index dd1ab16..22b14ac 100644
--- a/libkface/recognition-opencv-lbph/facerec_borrowed.h
+++ b/libkface/recognition-opencv-lbph/facerec_borrowed.h
@@ -45,7 +45,7 @@
 namespace KFaceIface
 {
 
-class LBPHFaceRecognizer : public cv::FaceRecognizer
+class LBPHFaceRecognizer : public cv::face::FaceRecognizer
 {
 public:
 
@@ -99,8 +99,8 @@ public:
 
     ~LBPHFaceRecognizer() {}
 
-    using cv::FaceRecognizer::save;
-    using cv::FaceRecognizer::load;
+    using cv::face::FaceRecognizer::save;
+    using cv::face::FaceRecognizer::load;
 
     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);
 
@@ -139,13 +139,31 @@ public:
     /**
      * Getter functions.
      */
-    int neighbors() const { return m_neighbors; }
-    int radius()    const { return m_radius;    }
-    int grid_x()    const { return m_grid_x;    }
-    int grid_y()    const { return m_grid_y;    }
+    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; }
 
-    // NOTE: Implementation done through CV_INIT_ALGORITHM macro from OpenCV.
-    cv::AlgorithmInfo* info() const;
 
 private:
 
diff --git a/libkface/recognition-opencv-lbph/lbphfacemodel.cpp b/libkface/recognition-opencv-lbph/lbphfacemodel.cpp
index af8c6a5..75c5863 100644
--- a/libkface/recognition-opencv-lbph/lbphfacemodel.cpp
+++ b/libkface/recognition-opencv-lbph/lbphfacemodel.cpp
@@ -61,7 +61,7 @@ LBPHFaceModel::LBPHFaceModel()
     : cv::Ptr<LBPHFaceRecognizer>(LBPHFaceRecognizer::create()),
       databaseId(0)
 {
-    ptr()->set("threshold", 100.0);
+    ptr()->setThreshold(100.0);
 }
 
 LBPHFaceModel::~LBPHFaceModel()
@@ -70,7 +70,7 @@ LBPHFaceModel::~LBPHFaceModel()
 
 LBPHFaceRecognizer* LBPHFaceModel::ptr()
 {
-    LBPHFaceRecognizer* const ptr = cv::Ptr<LBPHFaceRecognizer>::operator KFaceIface::LBPHFaceRecognizer*();
+    LBPHFaceRecognizer* const ptr = get();
 
     if (!ptr) 
         kWarning() << "LBPHFaceRecognizer pointer is null";
@@ -80,7 +80,7 @@ LBPHFaceRecognizer* LBPHFaceModel::ptr()
 
 const LBPHFaceRecognizer* LBPHFaceModel::ptr() const
 {
-    const LBPHFaceRecognizer* const ptr = cv::Ptr<LBPHFaceRecognizer>::operator const KFaceIface::LBPHFaceRecognizer*();
+    const LBPHFaceRecognizer* const ptr = get();
 
     if (!ptr) 
         kWarning() << "LBPHFaceRecognizer pointer is null";
@@ -90,47 +90,47 @@ const LBPHFaceRecognizer* LBPHFaceModel::ptr() const
 
 int LBPHFaceModel::radius() const
 {
-    return ptr()->get<int>("radius");
+    return ptr()->getRadius();
 }
 
 void LBPHFaceModel::setRadius(int radius)
 {
-    ptr()->set("radius", radius);
+    ptr()->setRadius(radius);
 }
 
 int LBPHFaceModel::neighbors() const
 {
-    return ptr()->get<int>("neighbors");
+    return ptr()->getNeighbors();
 }
 
 void LBPHFaceModel::setNeighbors(int neighbors)
 {
-    ptr()->set("neighbors", neighbors);
+    ptr()->setNeighbors(neighbors);
 }
 
 int LBPHFaceModel::gridX() const
 {
-    return ptr()->get<int>("grid_x");
+    return ptr()->getGrid_x();
 }
 
 void LBPHFaceModel::setGridX(int grid_x)
 {
-    ptr()->set("grid_x", grid_x);
+    ptr()->setGrid_x(grid_x);
 }
 
 int LBPHFaceModel::gridY() const
 {
-    return ptr()->get<int>("grid_y");
+    return ptr()->getGrid_y();
 }
 
 void LBPHFaceModel::setGridY(int grid_y)
 {
-    ptr()->set("grid_y", grid_y);
+    ptr()->setGrid_y(grid_y);
 }
 
 OpenCVMatData LBPHFaceModel::histogramData(int index) const
 {
-    return OpenCVMatData(ptr()->get<std::vector<cv::Mat> >("histograms").at(index));
+    return OpenCVMatData(ptr()->getHistograms().at(index));
 }
 
 QList<LBPHistogramMetadata> LBPHFaceModel::histogramMetadata() const
@@ -168,12 +168,12 @@ void LBPHFaceModel::setHistograms(const QList<OpenCVMatData>& histograms, const
         m_histogramMetadata << metadata;
     }
 
-    std::vector<cv::Mat> currentHistograms = ptr()->get<std::vector<cv::Mat> >("histograms");
-    cv::Mat currentLabels                  = ptr()->get<cv::Mat>("labels");
+    std::vector<cv::Mat> currentHistograms = ptr()->getHistograms();
+    cv::Mat currentLabels                  = ptr()->getLabels();
     currentHistograms.insert(currentHistograms.end(), newHistograms.begin(), newHistograms.end());
     currentLabels.push_back(newLabels);
-    ptr()->set("histograms", currentHistograms);
-    ptr()->set("labels", currentLabels);
+    ptr()->setHistograms(currentHistograms);
+    ptr()->setLabels(currentLabels);
 
 /*
     //Most cumbersome and inefficient way through a file storage which we were forced to use if we used standard OpenCV
@@ -215,7 +215,7 @@ void LBPHFaceModel::update(const std::vector<cv::Mat>& images, const std::vector
 
     // Update local information
     // We assume new labels are simply appended
-    cv::Mat currentLabels = ptr()->get<cv::Mat>("labels");
+    cv::Mat currentLabels = ptr()->getLabels();
 
     for (int i = m_histogramMetadata.size() ; i < currentLabels.rows ; i++)
     {
Comment 30 Adam Stylinski 2015-09-02 22:02:01 UTC
Created attachment 94359 [details]
attachment-30931-0.html

Right, those are the patch files, can you give me the output from the patch
command when using these patch files? If the patches applied successfully
and you have all of opencv 3 installed (including the shared libs from the
separate contrib repo), then it should compile without issue. My money says
you are missing opencv-contrib.
Comment 31 Willy Sudiarto Raharjo 2015-09-02 22:21:39 UTC
here's the cmake for opencv
mkdir -p build
cd build
  cmake \
    -DCMAKE_C_FLAGS="$SLKCFLAGS" \
    -DCMAKE_CXX_FLAGS="$SLKCFLAGS" \
    -DCMAKE_BUILD_TYPE="Release" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DINSTALL_MAN_DIR=man \
    -DINSTALL_DOC_DIR=doc/$PRGNAM-$VERSION \
    -DBUILD_SHARED_LIBS=ON \
    -DENABLE_PRECOMPILED_HEADERS=OFF \
    -DWITH_QT=ON \
    -DWITH_IPP=OFF \
    -DLIB_SUFFIX=$LIBDIRSUFFIX \
    -DLIB_INSTALL_DIR=/usr/lib$LIBDIRSUFFIX \
    ..
  make VERBOSE=1
  make install DESTDIR=$PKG

anything i miss to build opencv-contrib?
Comment 32 Willy Sudiarto Raharjo 2015-09-02 22:33:53 UTC
Ohh they move it to another project : https://github.com/Itseez/opencv_contrib/
i will try to add this on top of my opencv installation and see if it works
Comment 33 Willy Sudiarto Raharjo 2015-09-03 14:29:19 UTC
Hi all

I have tested to build opencv_contrib as part of opencv and rebuilt digiKam along with  digikam-4.12.0-opencv3.patch and libkface-15.04.2-opencv3.patch and i confirmed that the face detection is now working again

Thanks to all
Comment 34 caulier.gilles 2015-09-03 16:33:02 UTC
Thanks for the feedback to all.

I will review the patch and integrate it to next 4.14.0 release. 4.13.0 is under packaging for release time.

Gilles Caulier
Comment 35 caulier.gilles 2015-09-05 16:28:39 UTC
Comment on attachment 94088 [details]
completed patch

>diff --git a/CMakeLists.txt b/CMakeLists.txt
>index 4e83c8b..e399a25 100644
>--- a/CMakeLists.txt
>+++ b/CMakeLists.txt
>@@ -30,7 +30,7 @@ add_definitions(-DKDE_DEFAULT_DEBUG_AREA=${LIBKFACE_AREA_CODE_GENERAL})
> 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)
>+DETECT_OPENCV(2.4.9 core highgui objdetect face legacy imgproc)
> 
> include_directories(${OpenCV_INCLUDE_DIRS})
> 
>diff --git a/cmake/modules/modules_opencv/FindOpenCV.cmake b/cmake/modules/modules_opencv/FindOpenCV.cmake
>index 7580b32..6d3da76 100644
>--- a/cmake/modules/modules_opencv/FindOpenCV.cmake
>+++ b/cmake/modules/modules_opencv/FindOpenCV.cmake
>@@ -173,7 +173,6 @@ find_library(OpenCV_ML_LIBRARY
> find_library(OpenCV_TRS_LIBRARY  
>     NAMES trs
>     PATHS ${OpenCV_ROOT_DIR}  PATH_SUFFIXES ${OpenCV_LIBDIR_SUFFIXES} )
>-
> #
> # Logic selecting required libs and headers
> #
>diff --git a/libkface/detection/opencvfacedetector.cpp b/libkface/detection/opencvfacedetector.cpp
>index 7c420ae..28edeea 100644
>--- a/libkface/detection/opencvfacedetector.cpp
>+++ b/libkface/detection/opencvfacedetector.cpp
>@@ -138,11 +138,12 @@ public:
>     {
>         // 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;
>         }
>-
>+*/
>         return cv::Size(0, 0);
>     }
> 
>diff --git a/libkface/libopencv.h.cmake.in b/libkface/libopencv.h.cmake.in
>index 0a1a958..e70fc0c 100644
>--- a/libkface/libopencv.h.cmake.in
>+++ b/libkface/libopencv.h.cmake.in
>@@ -51,13 +51,11 @@
> #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>
>+#include <opencv2/face/facerec.hpp>
>+#include <opencv2/core.hpp>
> 
> // for old-style code
> #include <opencv2/opencv.hpp>
>-#include <opencv2/legacy/compat.hpp>
> #include <opencv2/highgui/highgui_c.h>
> #include <opencv/cvaux.h>
> 
>diff --git a/libkface/recognition-opencv-lbph/facerec_borrowed.cpp b/libkface/recognition-opencv-lbph/facerec_borrowed.cpp
>index 935a3d0..11aee02 100644
>--- a/libkface/recognition-opencv-lbph/facerec_borrowed.cpp
>+++ b/libkface/recognition-opencv-lbph/facerec_borrowed.cpp
>@@ -531,14 +531,5 @@ Ptr<LBPHFaceRecognizer> LBPHFaceRecognizer::create(int radius, int neighbors, in
>     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
> 
> } // namespace KFaceIface
>diff --git a/libkface/recognition-opencv-lbph/facerec_borrowed.h b/libkface/recognition-opencv-lbph/facerec_borrowed.h
>index dd1ab16..22b14ac 100644
>--- a/libkface/recognition-opencv-lbph/facerec_borrowed.h
>+++ b/libkface/recognition-opencv-lbph/facerec_borrowed.h
>@@ -45,7 +45,7 @@
> namespace KFaceIface
> {
> 
>-class LBPHFaceRecognizer : public cv::FaceRecognizer
>+class LBPHFaceRecognizer : public cv::face::FaceRecognizer
> {
> public:
> 
>@@ -99,8 +99,8 @@ public:
> 
>     ~LBPHFaceRecognizer() {}
> 
>-    using cv::FaceRecognizer::save;
>-    using cv::FaceRecognizer::load;
>+    using cv::face::FaceRecognizer::save;
>+    using cv::face::FaceRecognizer::load;
> 
>     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);
> 
>@@ -139,13 +139,31 @@ public:
>     /**
>      * Getter functions.
>      */
>-    int neighbors() const { return m_neighbors; }
>-    int radius()    const { return m_radius;    }
>-    int grid_x()    const { return m_grid_x;    }
>-    int grid_y()    const { return m_grid_y;    }
>+    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; }
> 
>-    // NOTE: Implementation done through CV_INIT_ALGORITHM macro from OpenCV.
>-    cv::AlgorithmInfo* info() const;
> 
> private:
> 
>diff --git a/libkface/recognition-opencv-lbph/lbphfacemodel.cpp b/libkface/recognition-opencv-lbph/lbphfacemodel.cpp
>index af8c6a5..75c5863 100644
>--- a/libkface/recognition-opencv-lbph/lbphfacemodel.cpp
>+++ b/libkface/recognition-opencv-lbph/lbphfacemodel.cpp
>@@ -61,7 +61,7 @@ LBPHFaceModel::LBPHFaceModel()
>     : cv::Ptr<LBPHFaceRecognizer>(LBPHFaceRecognizer::create()),
>       databaseId(0)
> {
>-    ptr()->set("threshold", 100.0);
>+    ptr()->setThreshold(100.0);
> }
> 
> LBPHFaceModel::~LBPHFaceModel()
>@@ -70,7 +70,7 @@ LBPHFaceModel::~LBPHFaceModel()
> 
> LBPHFaceRecognizer* LBPHFaceModel::ptr()
> {
>-    LBPHFaceRecognizer* const ptr = cv::Ptr<LBPHFaceRecognizer>::operator KFaceIface::LBPHFaceRecognizer*();
>+    LBPHFaceRecognizer* const ptr = get();
> 
>     if (!ptr) 
>         kWarning() << "LBPHFaceRecognizer pointer is null";
>@@ -80,7 +80,7 @@ LBPHFaceRecognizer* LBPHFaceModel::ptr()
> 
> const LBPHFaceRecognizer* LBPHFaceModel::ptr() const
> {
>-    const LBPHFaceRecognizer* const ptr = cv::Ptr<LBPHFaceRecognizer>::operator const KFaceIface::LBPHFaceRecognizer*();
>+    const LBPHFaceRecognizer* const ptr = get();
> 
>     if (!ptr) 
>         kWarning() << "LBPHFaceRecognizer pointer is null";
>@@ -90,47 +90,47 @@ const LBPHFaceRecognizer* LBPHFaceModel::ptr() const
> 
> int LBPHFaceModel::radius() const
> {
>-    return ptr()->get<int>("radius");
>+    return ptr()->getRadius();
> }
> 
> void LBPHFaceModel::setRadius(int radius)
> {
>-    ptr()->set("radius", radius);
>+    ptr()->setRadius(radius);
> }
> 
> int LBPHFaceModel::neighbors() const
> {
>-    return ptr()->get<int>("neighbors");
>+    return ptr()->getNeighbors();
> }
> 
> void LBPHFaceModel::setNeighbors(int neighbors)
> {
>-    ptr()->set("neighbors", neighbors);
>+    ptr()->setNeighbors(neighbors);
> }
> 
> int LBPHFaceModel::gridX() const
> {
>-    return ptr()->get<int>("grid_x");
>+    return ptr()->getGrid_x();
> }
> 
> void LBPHFaceModel::setGridX(int grid_x)
> {
>-    ptr()->set("grid_x", grid_x);
>+    ptr()->setGrid_x(grid_x);
> }
> 
> int LBPHFaceModel::gridY() const
> {
>-    return ptr()->get<int>("grid_y");
>+    return ptr()->getGrid_y();
> }
> 
> void LBPHFaceModel::setGridY(int grid_y)
> {
>-    ptr()->set("grid_y", grid_y);
>+    ptr()->setGrid_y(grid_y);
> }
> 
> OpenCVMatData LBPHFaceModel::histogramData(int index) const
> {
>-    return OpenCVMatData(ptr()->get<std::vector<cv::Mat> >("histograms").at(index));
>+    return OpenCVMatData(ptr()->getHistograms().at(index));
> }
> 
> QList<LBPHistogramMetadata> LBPHFaceModel::histogramMetadata() const
>@@ -168,12 +168,12 @@ void LBPHFaceModel::setHistograms(const QList<OpenCVMatData>& histograms, const
>         m_histogramMetadata << metadata;
>     }
> 
>-    std::vector<cv::Mat> currentHistograms = ptr()->get<std::vector<cv::Mat> >("histograms");
>-    cv::Mat currentLabels                  = ptr()->get<cv::Mat>("labels");
>+    std::vector<cv::Mat> currentHistograms = ptr()->getHistograms();
>+    cv::Mat currentLabels                  = ptr()->getLabels();
>     currentHistograms.insert(currentHistograms.end(), newHistograms.begin(), newHistograms.end());
>     currentLabels.push_back(newLabels);
>-    ptr()->set("histograms", currentHistograms);
>-    ptr()->set("labels", currentLabels);
>+    ptr()->setHistograms(currentHistograms);
>+    ptr()->setLabels(currentLabels);
> 
> /*
>     //Most cumbersome and inefficient way through a file storage which we were forced to use if we used standard OpenCV
>@@ -215,7 +215,7 @@ void LBPHFaceModel::update(const std::vector<cv::Mat>& images, const std::vector
> 
>     // Update local information
>     // We assume new labels are simply appended
>-    cv::Mat currentLabels = ptr()->get<cv::Mat>("labels");
>+    cv::Mat currentLabels = ptr()->getLabels();
> 
>     for (int i = m_histogramMetadata.size() ; i < currentLabels.rows ; i++)
>     {
Comment 36 caulier.gilles 2015-09-05 16:32:58 UTC
I mofified libkface-15.04.2-opencv3.patch to support OpenCV 2 and 3 and to be ready to integrate on next digiKam 4.14.0. 

Willy,

How did your configure OpenCV3 through cmake option :

-DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>

...to integrate opencv contrib modules at compilation time ?

Gilles Cauliert
Comment 37 Willy Sudiarto Raharjo 2015-09-05 16:34:50 UTC
i just followed instructions on their github:
https://github.com/Itseez/opencv_contrib/

You can build OpenCV, so it will include the modules from this repository. Here is the CMake command for you:

$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5

As the result, OpenCV will be built in the <opencv_build_directory> with all modules from opencv_contrib repository.
Comment 38 Willy Sudiarto Raharjo 2015-09-05 16:37:34 UTC
Here's the cmake for opencv

mkdir -p build
cd build
  cmake \
    -DCMAKE_C_FLAGS="$SLKCFLAGS" \
    -DCMAKE_CXX_FLAGS="$SLKCFLAGS" \
    -DCMAKE_BUILD_TYPE="Release" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DINSTALL_MAN_DIR=man \
    -DINSTALL_DOC_DIR=doc/$PRGNAM-$VERSION \
    -DBUILD_SHARED_LIBS=ON \
    -DENABLE_PRECOMPILED_HEADERS=OFF \
    -DWITH_QT=ON \
    -DWITH_IPP=OFF \
    -DLIB_SUFFIX=$LIBDIRSUFFIX \
    -DLIB_INSTALL_DIR=/usr/lib$LIBDIRSUFFIX \
    -DOPENCV_EXTRA_MODULES_PATH=$PRGNAM2-$VERSION/modules .. \
    ..
  make VERBOSE=1
  make install DESTDIR=$PKG
cd ..

i put the opencv_contrib directory inside opencv's directory so one level above "build" directory
Comment 39 caulier.gilles 2015-09-05 16:39:28 UTC
What's $PRGNAM2-$VERSION with  "-DOPENCV_EXTRA_MODULES_PATH=$PRGNAM2-$VERSION/modules .."

Gilles Caulier
Comment 40 Willy Sudiarto Raharjo 2015-09-05 16:41:04 UTC
opencv_contrib-3.0.0 (name of the directory extracted from opencv_contrib tarball)
Comment 41 caulier.gilles 2015-09-05 17:20:00 UTC
Created attachment 94414 [details]
libkface OpenCV3 support patch version 3

This new version of patch introduce a new cmake option to turn on/off OpenCV3 support. From README :

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.

Gilles Caulier
Comment 42 caulier.gilles 2015-09-05 18:58:48 UTC
Created attachment 94419 [details]
digiKam core OpenCV3 support patch version 3

digiKam core OpenCV3 support patch version 3

As libkface, this new version of patch introduce a new cmake option to turn on/off OpenCV3 support.

Gilles Caulier
Comment 43 caulier.gilles 2015-09-05 19:16:49 UTC
Created attachment 94420 [details]
kipi-plugins OpenCV3 support patch version 3

Kipi-plugins OpenCV3 support patch version 3

As libkface, this new version of patch introduce a new cmake option to turn
on/off OpenCV3 support.
Comment 44 caulier.gilles 2015-09-05 19:19:54 UTC
Git commit 685c5f7380df0666335220809d40f137f4bd39a1 by Gilles Caulier.
Committed on 05/09/2015 at 19:19.
Pushed by cgilles into branch 'master'.

add new OpenCV3 support option

M  +2    -1    bootstrap.linux
M  +2    -1    bootstrap.local
M  +1    -0    bootstrap.macports
M  +1    -0    bootstrap.msvc.bat

http://commits.kde.org/scratch/mwiesweg/digikam-sc/685c5f7380df0666335220809d40f137f4bd39a1
Comment 45 caulier.gilles 2015-09-05 19:20:54 UTC
Git commit a53bcebbfc4e6c42ee73adddc41f8c2f8f8f39c8 by Gilles Caulier.
Committed on 05/09/2015 at 19:20.
Pushed by cgilles into branch 'master'.

apply patch #94414 to support OpenCV3

M  +8    -1    CMakeLists.txt
M  +5    -0    README
M  +1    -1    libkface/CMakeLists.txt
M  +3    -2    libkface/detection/opencvfacedetector.cpp
M  +21   -14   libkface/libopencv.h.cmake.in
M  +11   -9    libkface/recognition-opencv-lbph/facerec_borrowed.cpp
M  +39   -0    libkface/recognition-opencv-lbph/facerec_borrowed.h
M  +62   -2    libkface/recognition-opencv-lbph/lbphfacemodel.cpp

http://commits.kde.org/libkface/a53bcebbfc4e6c42ee73adddc41f8c2f8f8f39c8
Comment 46 caulier.gilles 2015-09-05 19:21:37 UTC
Git commit 7d3f1e045ba42ed84ec0fc3c5fc523da82da6bbd by Gilles Caulier.
Committed on 05/09/2015 at 19:21.
Pushed by cgilles into branch 'master'.

apply patch #94419 to support OpenCV3

M  +10   -4    CMakeLists.txt
M  +3    -0    README
M  +5    -3    app/utils/libopencv.h
M  +17   -1    libs/database/imgqsort/imgqsort.cpp

http://commits.kde.org/digikam/7d3f1e045ba42ed84ec0fc3c5fc523da82da6bbd
Comment 47 caulier.gilles 2015-09-05 19:22:43 UTC
Git commit e8e2cab66ae0079586400e21244444fff20bfcf3 by Gilles Caulier.
Committed on 05/09/2015 at 19:22.
Pushed by cgilles into branch 'master'.

apply patch #94420 to support OpenCV3
FIXED-IN: 4.14.0

M  +12   -5    CMakeLists.txt
M  +6    -0    README
M  +1    -1    removeredeyes/CMakeLists.txt
M  +9    -0    removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp
M  +5    -4    removeredeyes/plugin/libopencv.h
M  +2    -2    removeredeyes/test/CMakeLists.txt

http://commits.kde.org/kipi-plugins/e8e2cab66ae0079586400e21244444fff20bfcf3
Comment 48 caulier.gilles 2015-09-05 21:36:25 UTC
Git commit d61c07bf6213774fa06380c466e7dc5438c03745 by Gilles Caulier.
Committed on 05/09/2015 at 21:35.
Pushed by cgilles into branch 'master'.

add rules if not right OpenCV version is found

M  +15   -1    CMakeLists.txt

http://commits.kde.org/libkface/d61c07bf6213774fa06380c466e7dc5438c03745
Comment 49 caulier.gilles 2015-09-05 21:37:03 UTC
Git commit 9a1c86cb5bf0b9d673df2a289d5f19270055af39 by Gilles Caulier.
Committed on 05/09/2015 at 21:36.
Pushed by cgilles into branch 'master'.

add rules if not right OpenCV version is found

M  +15   -1    CMakeLists.txt

http://commits.kde.org/kipi-plugins/9a1c86cb5bf0b9d673df2a289d5f19270055af39
Comment 50 caulier.gilles 2015-09-05 21:37:38 UTC
Git commit e589c74a4347f4e6a90cab6fe03ba1314d22293f by Gilles Caulier.
Committed on 05/09/2015 at 21:37.
Pushed by cgilles into branch 'master'.

add rules if not right OpenCV version is found

M  +15   -1    CMakeLists.txt

http://commits.kde.org/digikam/e589c74a4347f4e6a90cab6fe03ba1314d22293f
Comment 51 Willy Sudiarto Raharjo 2015-09-05 23:38:51 UTC
Seems i made a mistake on opencv cmake parameter. It should be like this (path problem)

mkdir -p build
cd build
  cmake \
    -DCMAKE_C_FLAGS="$SLKCFLAGS" \
    -DCMAKE_CXX_FLAGS="$SLKCFLAGS" \
    -DCMAKE_BUILD_TYPE="Release" \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DINSTALL_MAN_DIR=man \
    -DINSTALL_DOC_DIR=doc/$PRGNAM-$VERSION \
    -DBUILD_SHARED_LIBS=ON \
    -DENABLE_PRECOMPILED_HEADERS=OFF \
    -DWITH_QT=ON \
    -DWITH_IPP=OFF \
    -DLIB_SUFFIX=$LIBDIRSUFFIX \
    -DLIB_INSTALL_DIR=/usr/lib$LIBDIRSUFFIX \
    -DOPENCV_EXTRA_MODULES_PATH=../$PRGNAM2-$VERSION/modules ..
  make VERBOSE=1
  make install DESTDIR=$PKG
cd ..
Comment 52 caulier.gilles 2015-09-06 08:14:28 UTC
Git commit dc62c0e0ea55d189d918501cce4d92f4198a1a0c by Gilles Caulier.
Committed on 06/09/2015 at 08:13.
Pushed by cgilles into branch 'master'.

use same OpenCV logic than digiKam and kipi-plugins

M  +1    -1    CMakeLists.txt
M  +1    -1    libkface/detection/opencvfacedetector.cpp
M  +5    -5    libkface/libopencv.h.cmake.in
M  +1    -1    libkface/recognition-opencv-lbph/facerec_borrowed.cpp
M  +15   -15   libkface/recognition-opencv-lbph/facerec_borrowed.h
M  +30   -30   libkface/recognition-opencv-lbph/lbphfacemodel.cpp

http://commits.kde.org/libkface/dc62c0e0ea55d189d918501cce4d92f4198a1a0c
Comment 53 caulier.gilles 2015-09-06 13:11:31 UTC
Git commit 60b88b4cb278ec58b63c013ce8be29069258a5ae by Gilles Caulier.
Committed on 06/09/2015 at 13:10.
Pushed by cgilles into branch 'frameworks'.

backport commit #a53bcebbfc4e6c42ee73adddc41f8c2f8f8f39c8 from git/master to frameworks branch

M  +24   -2    CMakeLists.txt
M  +5    -0    README
M  +1    -1    src/CMakeLists.txt
M  +2    -1    src/detection/opencvfacedetector.cpp
M  +22   -16   src/libopencv.h.cmake.in
M  +11   -10   src/recognition-opencv-lbph/facerec_borrowed.cpp
M  +39   -0    src/recognition-opencv-lbph/facerec_borrowed.h
M  +61   -1    src/recognition-opencv-lbph/lbphfacemodel.cpp

http://commits.kde.org/libkface/60b88b4cb278ec58b63c013ce8be29069258a5ae
Comment 54 caulier.gilles 2015-09-06 13:13:44 UTC
Git commit cad46af57d8277071bd7485ffecabe5209d8759e by Gilles Caulier.
Committed on 06/09/2015 at 13:13.
Pushed by cgilles into branch 'frameworks'.

backport commit #685c5f7380df0666335220809d40f137f4bd39a1 from git/master to frameworks branch

M  +1    -0    bootstrap.linux
M  +1    -0    bootstrap.macports
M  +1    -0    bootstrap.msvc.bat

http://commits.kde.org/scratch/mwiesweg/digikam-sc/cad46af57d8277071bd7485ffecabe5209d8759e
Comment 55 caulier.gilles 2015-09-06 13:21:48 UTC
Git commit 76750be898b6c83922eedad062f22f4df2f75c53 by Gilles Caulier.
Committed on 06/09/2015 at 13:21.
Pushed by cgilles into branch 'frameworks'.

backport commit #7d3f1e045ba42ed84ec0fc3c5fc523da82da6bbd from git/master to frameworks branch

M  +1    -0    CMakeLists.txt
M  +4    -1    README
M  +4    -2    app/utils/libopencv.h
M  +17   -1    libs/database/imgqsort/imgqsort.cpp

http://commits.kde.org/digikam/76750be898b6c83922eedad062f22f4df2f75c53
Comment 56 caulier.gilles 2015-09-06 13:31:42 UTC
Git commit 02b7cdb415dce8c76c0276c2173a0a8c27274171 by Gilles Caulier.
Committed on 06/09/2015 at 13:31.
Pushed by cgilles into branch 'frameworks'.

backport commit #e8e2cab66ae0079586400e21244444fff20bfcf3 from git/master to frameworks branch

M  +9    -0    PORT.KF5/PENDING/removeredeyes/detection/locators/haarclassifier/haarclassifierlocator.cpp
M  +4    -3    PORT.KF5/PENDING/removeredeyes/libcvblobs/libopencv.h
M  +2    -2    PORT.KF5/PENDING/removeredeyes/test/CMakeLists.txt

http://commits.kde.org/kipi-plugins/02b7cdb415dce8c76c0276c2173a0a8c27274171