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