wangrong
2025-01-03 2c4b8838f89bebca97615c5f0bac2c58e0349771
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#pragma once
 
/*
* define EXTERNAL archive functions for objects which need to be serialized by cereal library in VideoPipe.
* refer to `https://uscilab.github.io/cereal/serialization_functions.html` for more details.
*/
 
// object types
#include "../../../objects/vp_frame_target.h"
#include "../../../objects/vp_frame_face_target.h"
#include "../../../objects/vp_frame_text_target.h"
#include "../../../objects/vp_frame_pose_target.h"
#include "../../../objects/vp_sub_target.h"
#include "../../../objects/ba/vp_ba_result.h"
#include "../../../objects/shapes/vp_point.h"
 
/* extend for more types of objects in VideoPipe. */
 
// headers from cereal
#include "../../../third_party/cereal/cereal.hpp"
#include "../../../third_party/cereal/types/vector.hpp"
#include "../../../third_party/cereal/types/memory.hpp"
#include "../../../third_party/cereal/types/string.hpp"
#include "../../../third_party/cereal/types/utility.hpp"
#include "../../../third_party/cereal/archives/json.hpp"
#include "../../../third_party/cereal/archives/xml.hpp"
 
/* same namespace as object types */
namespace vp_objects {
    /* vp_frame_target */
    template<typename Archive>
    void serialize(Archive& archive, vp_frame_target& target) {
        // define the form of structured data for vp_frame_target
        archive(cereal::make_nvp("x", target.x),
                cereal::make_nvp("y", target.y),
                cereal::make_nvp("width", target.width),
                cereal::make_nvp("height", target.height),
                cereal::make_nvp("primary_class_id", target.primary_class_id),
                cereal::make_nvp("primary_score", target.primary_score),
                cereal::make_nvp("primary_label", target.primary_label),
                cereal::make_nvp("channel_index", target.channel_index),
                cereal::make_nvp("frame_index", target.frame_index),
                cereal::make_nvp("track_id", target.track_id),
                cereal::make_nvp("secondary_class_ids", target.secondary_class_ids),
                cereal::make_nvp("secondary_scores", target.secondary_scores),
                cereal::make_nvp("secondary_labels", target.secondary_labels),
                cereal::make_nvp("sub_targets", target.sub_targets),
                cereal::make_nvp("embeddings", target.embeddings));
    }
 
    template<typename Archive>
    void serialize(Archive& archive, vp_sub_target& target) {
        // define the form of structured data for vp_sub_target
        archive(cereal::make_nvp("x", target.x),
                cereal::make_nvp("y", target.y),
                cereal::make_nvp("width", target.width),
                cereal::make_nvp("height", target.height),
                cereal::make_nvp("class_id", target.class_id),
                cereal::make_nvp("score", target.score),
                cereal::make_nvp("label", target.label),
                cereal::make_nvp("frame_index", target.frame_index),
                cereal::make_nvp("channel_index", target.channel_index),
                cereal::make_nvp("attachments", target.attachments));
    }
    /* END OF vp_frame_target */
 
 
    /* vp_frame_face_target */
    template<typename Archive>
    void serialize(Archive& archive, vp_frame_face_target& target) {
        // define the form of structured data for vp_frame_face_target
        archive(cereal::make_nvp("x", target.x),
                cereal::make_nvp("y", target.y),
                cereal::make_nvp("width", target.width),
                cereal::make_nvp("height", target.height),
                cereal::make_nvp("score", target.score),
                cereal::make_nvp("embeddings", target.embeddings),
                cereal::make_nvp("key_points", target.key_points),
                cereal::make_nvp("track_id", target.track_id));
    }
    /* END OF vp_frame_face_target */
 
 
    /* vp_frame_text_target */
    template<typename Archive>
    void serialize(Archive& archive, vp_frame_text_target& target) {
        // define the form of structured data for vp_frame_text_target
        archive(cereal::make_nvp("text", target.text),
                cereal::make_nvp("score", target.score),
                cereal::make_nvp("region", target.region_vertexes),
                cereal::make_nvp("flags", target.flags));
    }
    /* END OF vp_frame_text_target */
 
    /* vp_ba_result */
    template<typename Archive>
    void serialize(Archive& archive, vp_ba_result& result) {
        // define the form of structured data for vp_ba_result
        archive(cereal::make_nvp("type", result.type),
                cereal::make_nvp("involve_target_ids_in_frame", result.involve_target_ids_in_frame),
                cereal::make_nvp("involve_region_in_frame", result.involve_region_in_frame),
                cereal::make_nvp("channel_index", result.channel_index),
                cereal::make_nvp("frame_index", result.frame_index),
                cereal::make_nvp("ba_label", result.ba_label),
                cereal::make_nvp("record_image_name", result.record_image_name),
                cereal::make_nvp("record_video_name", result.record_video_name));
    }
    /* END OF vp_ba_result */
 
    template<typename Archive>
    void serialize(Archive& archive,vp_point& point) {
        archive(CEREAL_NVP(point.x),CEREAL_NVP(point.y));
    }
 
 
    /* vp_frame_pose_target */
    template<typename Archive>
    void serialize(Archive& archive, vp_frame_pose_target& target) {
        // define the form of structured data for vp_frame_pose_target
 
    }
    /* END OF vp_frame_pose_target */
}