[shotwell/wip/cleanup-facedetect: 3/15] Let FaceRect serialize itself to Variant
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [shotwell/wip/cleanup-facedetect: 3/15] Let FaceRect serialize itself to Variant
- Date: Sun, 14 Aug 2022 15:32:29 +0000 (UTC)
commit e44bc730d7ed6550db8b7974e9e1b19d4d6b8022
Author: Jens Georg <mail jensge org>
Date: Sat Aug 13 17:21:26 2022 +0200
Let FaceRect serialize itself to Variant
.../shotwell-facedetect/facedetect-opencv.cpp | 2 ++
.../shotwell-facedetect/shotwell-facedetect.cpp | 27 ++++++++++++++--------
.../shotwell-facedetect/shotwell-facedetect.hpp | 8 ++++---
3 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/subprojects/shotwell-facedetect/facedetect-opencv.cpp
b/subprojects/shotwell-facedetect/facedetect-opencv.cpp
index 3191c548..8504437e 100644
--- a/subprojects/shotwell-facedetect/facedetect-opencv.cpp
+++ b/subprojects/shotwell-facedetect/facedetect-opencv.cpp
@@ -8,6 +8,8 @@
#include <opencv2/dnn.hpp>
#endif
+#include <iostream>
+
// Global variable for DNN to generate vector out of face
#ifdef HAS_OPENCV_DNN
static cv::dnn::Net faceRecogNet;
diff --git a/subprojects/shotwell-facedetect/shotwell-facedetect.cpp
b/subprojects/shotwell-facedetect/shotwell-facedetect.cpp
index 9031dfc3..cfca3e99 100644
--- a/subprojects/shotwell-facedetect/shotwell-facedetect.cpp
+++ b/subprojects/shotwell-facedetect/shotwell-facedetect.cpp
@@ -11,9 +11,26 @@
#include "shotwell-facedetect.hpp"
#include "dbus-interface.h"
+#include <gio/gio.h>
+#include <glib.h>
+
+#include <iostream>
+
const char* FACEDETECT_INTERFACE_NAME = "org.gnome.Shotwell.Faces1";
const char* FACEDETECT_PATH = "/org/gnome/shotwell/faces";
+GVariant *FaceRect::serialize() const
+{
+ GVariantBuilder *arr_builder = g_variant_builder_new(G_VARIANT_TYPE("ad"));
+ for(std::vector<double>::const_iterator v = vec.begin(); v != vec.end(); v++) {
+ GVariant *d = g_variant_new("d", *v);
+ g_variant_builder_add(arr_builder, "d", d);
+ }
+ GVariant *vec = g_variant_new("ad", arr_builder);
+ g_variant_builder_unref(arr_builder);
+ return g_variant_new("(dddd@ad)", x, y, width, height, vec);
+}
+
// DBus binding functions
static gboolean on_handle_detect_faces(ShotwellFaces1 *object,
GDBusMethodInvocation *invocation,
@@ -28,15 +45,7 @@ static gboolean on_handle_detect_faces(ShotwellFaces1 *object,
// Construct return value
builder = g_variant_builder_new(G_VARIANT_TYPE ("a(ddddad)"));
for (std::vector<FaceRect>::const_iterator r = rects.begin(); r != rects.end(); r++) {
- GVariantBuilder *arr_builder = g_variant_builder_new(G_VARIANT_TYPE ("ad"));
- for (std::vector<double>::const_iterator v = r->vec.begin(); v != r->vec.end(); v++) {
- GVariant *d = g_variant_new("d", *v);
- g_variant_builder_add(arr_builder, "d", d);
- }
- GVariant *vec = g_variant_new("ad", arr_builder);
- g_variant_builder_unref(arr_builder);
- GVariant *rect = g_variant_new("(dddd@ad)", r->x, r->y, r->width, r->height, vec);
- g_variant_builder_add(builder, "@(ddddad)", rect);
+ g_variant_builder_add(builder, "@(ddddad)", r->serialize());
g_debug("Returning %f,%f-%f", r->x, r->y, r->vec.back());
}
faces = g_variant_new("a(ddddad)", builder);
diff --git a/subprojects/shotwell-facedetect/shotwell-facedetect.hpp
b/subprojects/shotwell-facedetect/shotwell-facedetect.hpp
index ae6f18dc..a3b0af74 100644
--- a/subprojects/shotwell-facedetect/shotwell-facedetect.hpp
+++ b/subprojects/shotwell-facedetect/shotwell-facedetect.hpp
@@ -11,9 +11,9 @@
#include <opencv2/core/core.hpp>
-#include <algorithm>
-#include <iostream>
-#include <stdio.h>
+#include <gio/gio.h>
+
+#include <vector>
struct FaceRect {
FaceRect()
@@ -25,6 +25,8 @@ struct FaceRect {
float width{ 0.0F };
float height{ 0.0F };
std::vector<double> vec;
+
+ GVariant *serialize() const;
};
bool loadNet(cv::String netFile);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]