nx_metadata_sdk  1.0
Metadata SDK
stream_parser.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2 
3 #pragma once
4 
5 #include <map>
6 #include <set>
7 #include <string>
8 #include <vector>
9 
10 #include <nx/kit/json.h>
11 #include <nx/sdk/analytics/rect.h>
12 #include <nx/sdk/uuid.h>
13 
14 namespace nx {
15 namespace vms_server_plugins {
16 namespace analytics {
17 namespace stub {
18 namespace object_streamer {
19 
20 struct Object
21 {
22  enum class EntryType
23  {
24  regular,
25  bestShot,
26  };
27 
28  std::string typeId;
29  nx::sdk::Uuid trackId;
30  std::string trackIdRef;
31  nx::sdk::analytics::Rect boundingBox;
32  std::map<std::string, std::string> attributes;
33  int frameNumberToGenerateObject = 0;
34  int64_t timestampUs = -1;
35  EntryType entryType = EntryType::regular;
36  std::string imageSource;
37 };
38 
39 enum class Issue
40 {
41  objectStreamIsNotAValidJson,
42  objectStreamIsNotAJsonArray,
43  objectItemIsNotAJsonObject,
44  trackIdIsNotAString,
45  trackIdIsNotAUuid,
46  typeIdIsNotAString,
47  frameNumberIsNotANumber,
48  boundingBoxIsNotAJsonObject,
49  topLeftXIsNotANumber,
50  topLeftYIsNotANumber,
51  widthIsNotANumber,
52  heightIsNotANumber,
53  objectIsOutOfBounds,
54  attributesFieldIsNotAJsonObject,
55  attributeValueIsNotAString,
56  timestampIsNotANumber,
57  objectEntryTypeIsNotAString,
58  objectEntryTypeIsUnknown,
59  imageSourceIsNotAString,
60 };
61 
62 struct Issues
63 {
64  std::set<Issue> errors;
65  std::set<Issue> warnings;
66 };
67 
68 struct StreamInfo
69 {
70  std::map<int, std::vector<Object>> objectsByFrameNumber;
71  std::set<std::string> objectTypeIds;
72 };
73 
74 StreamInfo parseObjectStreamFile(const std::string& filePath, Issues* issues);
75 
76 bool parseTrackId(
77  const nx::kit::Json& objectDescription,
78  Object* outObject,
79  Issues* issues);
80 
81 bool parseCommonFields(
82  const nx::kit::Json& objectDescription,
83  Object* outObject,
84  Issues* issues);
85 
86 bool parseBoundingBox(
87  const nx::kit::Json& objectDescription,
88  nx::sdk::analytics::Rect* outBoundingBox,
89  Issues* issues);
90 
91 bool parseAttributes(
92  const nx::kit::Json& objectDescription,
93  std::map<std::string, std::string>* outAttributes,
94  Issues* issues);
95 
96 bool parseTimestamp(
97  const nx::kit::Json& objectDescription,
98  int64_t* outTimestamp,
99  Issues* issues);
100 
101 bool parseImageSource(
102  const nx::kit::Json& objectDescription,
103  std::string* outImageSource,
104  Issues* issues);
105 
106 std::string issueToString(Issue issue);
107 
108 } // namespace object_streamer
109 } // namespace stub
110 } // namespace analytics
111 } // namespace vms_server_plugins
112 } // namespace nx
Definition: json.cpp:80
Definition: uuid.h:22
Definition: apple_utils.h:6
Definition: rect.h:9