[shotwell/wip/cleanup-facedetect: 15/15] wip: breaks vala
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/cleanup-facedetect: 15/15] wip: breaks vala
- Date: Sun, 14 Aug 2022 15:32:30 +0000 (UTC)
commit 7a9b553c3e598d4c722b6516a429b20c7f9365e6
Author: Jens Georg <mail jensge org>
Date: Sun Aug 14 17:32:02 2022 +0200
wip: breaks vala
.../shotwell-facedetect/facedetect-opencv.cpp | 24 ++++++++++++++--------
...cascade.xml => haarcascade_frontalface_alt.xml} | 0
subprojects/shotwell-facedetect/meson.build | 2 +-
.../org.gnome.ShotwellFaces1.xml | 5 +++--
4 files changed, 20 insertions(+), 11 deletions(-)
---
diff --git a/subprojects/shotwell-facedetect/facedetect-opencv.cpp
b/subprojects/shotwell-facedetect/facedetect-opencv.cpp
index 209f9e6d..e5f55e95 100644
--- a/subprojects/shotwell-facedetect/facedetect-opencv.cpp
+++ b/subprojects/shotwell-facedetect/facedetect-opencv.cpp
@@ -16,21 +16,26 @@ static cv::dnn::Net faceRecogNet;
static cv::dnn::Net faceDetectNet;
#endif
+static cv::CascadeClassifier cascade;
+static bool disableDnn{ true };
+
constexpr char OPENFACE_RECOG_TORCH_NET[]{ "openface.nn4.small2.v1.t7" };
constexpr char RESNET_DETECT_CAFFE_NET[]{ "res10_300x300_ssd_iter_140000_fp16.caffemodel" };
+constexpr char HAARCASCADE[]{ "haarcascade_frontalface_alt.xml" };
std::vector<cv::Rect> detectFacesMat(cv::Mat img);
std::vector<double> faceToVecMat(cv::Mat img);
// Detect faces in a photo
std::vector<FaceRect> detectFaces(cv::String inputName, cv::String cascadeName, double scale, bool infer =
false) {
- cv::CascadeClassifier cascade;
- if (!cascade.load(cascadeName)) {
- std::cout << "error;Could not load classifier cascade. Filename: \"" << cascadeName << "\"" <<
std::endl;
- }
+ if(cascade.empty()) {
+ g_warning("No cascade file loaded. Did you call loadNet()?");
+ return {};
+ }
if (inputName.empty()) {
- std::cout << "error;You must specify the file to process." << std::endl;
+ g_warning("No file to process. aborting");
+ return {};
}
cv::Mat img = cv::imread(inputName, 1);
@@ -40,7 +45,6 @@ std::vector<FaceRect> detectFaces(cv::String inputName, cv::String cascadeName,
std::vector<cv::Rect> faces;
cv::Size smallImgSize;
- static bool disableDnn;
#ifdef HAS_OPENCV_DNN
disableDnn = faceDetectNet.empty();
@@ -89,6 +93,7 @@ std::vector<FaceRect> detectFaces(cv::String inputName, cv::String cascadeName,
// Load network into global var
bool loadNet(cv::String baseDir) {
+ cascade.load(baseDir + "/" + HAARCASCADE);
#ifdef HAS_OPENCV_DNN
try {
faceDetectNet = cv::dnn::readNetFromCaffe(baseDir + "/deploy.prototxt",
@@ -96,16 +101,19 @@ bool loadNet(cv::String baseDir) {
faceRecogNet = cv::dnn::readNetFromTorch(baseDir + "/" + OPENFACE_RECOG_TORCH_NET);
} catch(cv::Exception &e) {
std::cout << "File load failed: " << e.msg << std::endl;
- return false;
+ disableDnn = true;
}
+
if (faceRecogNet.empty() || faceDetectNet.empty()) {
std::cout << "Loading open-face net failed!" << std::endl;
+ disableDnn = true;
return false;
} else {
+ disableDnn = false;
return true;
}
#else
- return true;
+ return not cascade.empty();
#endif
}
diff --git a/subprojects/shotwell-facedetect/facedetect-haarcascade.xml
b/subprojects/shotwell-facedetect/haarcascade_frontalface_alt.xml
similarity index 100%
rename from subprojects/shotwell-facedetect/facedetect-haarcascade.xml
rename to subprojects/shotwell-facedetect/haarcascade_frontalface_alt.xml
diff --git a/subprojects/shotwell-facedetect/meson.build b/subprojects/shotwell-facedetect/meson.build
index 77adb5b7..3cbe5e32 100644
--- a/subprojects/shotwell-facedetect/meson.build
+++ b/subprojects/shotwell-facedetect/meson.build
@@ -42,7 +42,7 @@ executable('shotwell-facedetect',
install : true,
include_directories: config_incdir,
install_dir : libexecdir)
-install_data('facedetect-haarcascade.xml',
+install_data('haarcascade_frontalface_alt.xml',
install_dir : join_paths(get_option('datadir'), 'shotwell'))
configure_file(
diff --git a/subprojects/shotwell-facedetect/org.gnome.ShotwellFaces1.xml
b/subprojects/shotwell-facedetect/org.gnome.ShotwellFaces1.xml
index 2391bf6f..3bf10717 100644
--- a/subprojects/shotwell-facedetect/org.gnome.ShotwellFaces1.xml
+++ b/subprojects/shotwell-facedetect/org.gnome.ShotwellFaces1.xml
@@ -10,8 +10,9 @@
<!--
DetectFaces
@image: Image file to run face detection on
- @cascade: Cascade XML file
+ @cascade: Cascade XML file - unused
@scale: Scaling to apply on image
+ @infer: Provide an
Returns an array of face bounding boxes (x,y,w,h) in dimensionless units
-->
<method name="DetectFaces">
@@ -24,7 +25,7 @@
<!--
LoadNet
- @net: Torch t7 net file
+ @net: path to folder containing the DNN
Returns non-zero on any error
-->
<method name="LoadNet">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]