Bug#841411: libkf5kface: FTBFS: error with opencv 3.1
Hola Maximiliano,
I have investigated a bit to compile libkf5kface against opencv3.1. I have found
one patch from upstream and another to activate CMake to build against opencv 3.1.
With this two patches libkf5kface builds but fail in the test:
/usr/bin/ctest --force-new-ctest-process -j8
Test project
/srv/drp/packages/opencv/transition/libkf5kface/libkf5kface-15.12.0/obj-x86_64-linux-gnu
Start 1: appstreamtest
1/1 Test #1: appstreamtest ....................***Failed 0.01 sec
CMake Error at /usr/share/ECM/kde-modules/appstreamtest.cmake:1 (file):
file failed to open for reading (No such file or directory):
/srv/drp/packages/opencv/transition/libkf5kface/libkf5kface-15.12.0/obj-x86_64-linux-gnu/install_manifest.txt
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.01 sec
The following tests FAILED:
1 - appstreamtest (Failed)
as it seems to be something more specific of the package, please could you check
it it the solution is trivial?
Thanks,
Leopold
--
--
Linux User 152692 GPG: 05F4A7A949A2D9AA
Catalonia
-------------------------------------
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?
>From ec6e82328cac37c9d59b49245b18c3f0abee4d8f Mon Sep 17 00:00:00 2001
From: Xuetian Weng <wengxt@gmail.com>
Date: Sun, 6 Nov 2016 20:25:15 +0100
Subject: Add opencv 3.1 support
REVIEW: 126833
---
src/recognition-opencv-lbph/facerec_borrowed.cpp | 41 ++++++++++++++++++++++--
src/recognition-opencv-lbph/facerec_borrowed.h | 9 ++++++
2 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/src/recognition-opencv-lbph/facerec_borrowed.cpp b/src/recognition-opencv-lbph/facerec_borrowed.cpp
index 748691e..3c37ce2 100644
--- a/src/recognition-opencv-lbph/facerec_borrowed.cpp
+++ b/src/recognition-opencv-lbph/facerec_borrowed.cpp
@@ -36,6 +36,8 @@
*
* ============================================================ */
+#define QT_NO_EMIT
+
#include "facerec_borrowed.h"
// C++ includes
@@ -375,7 +377,11 @@ void LBPHFaceRecognizer::train(InputArrayOfArrays _in_src, InputArray _inm_label
}
}
+#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 @@ void LBPHFaceRecognizer::predict(InputArray _src, int &minClass, double &minDist
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 @@ void LBPHFaceRecognizer::predict(InputArray _src, int &minClass, double &minDist
{
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 @@ void LBPHFaceRecognizer::predict(InputArray _src, int &minClass, double &minDist
// 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 @@ void LBPHFaceRecognizer::predict(InputArray _src, int &minClass, double &minDist
double mean = sum / it->second.size();
s += QString::fromLatin1("%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
}
qCDebug(LIBKFACE_LOG) << s;
@@ -462,7 +487,7 @@ void LBPHFaceRecognizer::predict(InputArray _src, int &minClass, double &minDist
// 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 @@ void LBPHFaceRecognizer::predict(InputArray _src, int &minClass, double &minDist
scoreMap[it->second]++;
}
+#if OPENCV_TEST_VERSION(3,1,0)
minDist = 0;
+#endif
QString s = QString::fromLatin1("Nearest Neighbor score: ");
for (std::map<int,int>::iterator it = scoreMap.begin(); it != scoreMap.end(); ++it)
@@ -488,17 +515,26 @@ void LBPHFaceRecognizer::predict(InputArray _src, int &minClass, double &minDist
double score = double(it->second) / countMap.at(it->first);
s += QString::fromLatin1("%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
}
qCDebug(LIBKFACE_LOG) << s;
}
}
+#if OPENCV_TEST_VERSION(3,1,0)
int LBPHFaceRecognizer::predict(InputArray _src) const
{
int label;
@@ -506,6 +542,7 @@ int LBPHFaceRecognizer::predict(InputArray _src) const
predict(_src, label, dummy);
return label;
}
+#endif
// Static method ----------------------------------------------------
diff --git a/src/recognition-opencv-lbph/facerec_borrowed.h b/src/recognition-opencv-lbph/facerec_borrowed.h
index 27ad77a..f197d22 100644
--- a/src/recognition-opencv-lbph/facerec_borrowed.h
+++ b/src/recognition-opencv-lbph/facerec_borrowed.h
@@ -125,6 +125,8 @@ public:
*/
void update(cv::InputArrayOfArrays src, cv::InputArray labels);
+
+#if OPENCV_TEST_VERSION(3,1,0)
/**
* Predicts the label of a query image in src.
*/
@@ -134,6 +136,13 @@ public:
* 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().
--
cgit v0.11.2
--- a/CMakeLists.txt 2017-06-29 17:02:37.554773456 +0200
+++ b/CMakeLists.txt 2017-06-29 17:02:48.242714074 +0200
@@ -9,7 +9,7 @@
message(STATUS "----------------------------------------------------------------------------------")
message(STATUS "Starting CMake configuration for: ${PROJECT_NAME}")
-option(ENABLE_OPENCV3 "Build libkface with OpenCV3 instead OpenCV2 (default=OFF)" OFF)
+option(ENABLE_OPENCV3 "Build libkface with OpenCV3 instead OpenCV2 (default=OFF)" ON)
set(CMAKE_MIN_VERSION "2.8.12")
set(ECM_MIN_VERSION "1.1.0")
Reply to: