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/uuid.h>
12 #include <nx/sdk/analytics/rect.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 };
58 
59 struct Issues
60 {
61  std::set<Issue> errors;
62  std::set<Issue> warnings;
63 };
64 
65 struct StreamInfo
66 {
67  std::map<int, std::vector<Object>> objectsByFrameNumber;
68  std::set<std::string> objectTypeIds;
69 };
70 
71 StreamInfo parseObjectStreamFile(const std::string& filePath, Issues* outIssues);
72 
73 bool parseCommonFields(
74  const nx::kit::Json& objectDescription,
75  Object* outObject,
76  Issues* outIssues);
77 
78 bool parseBoundingBox(
79  const nx::kit::Json& objectDescription,
80  nx::sdk::analytics::Rect* outBoundingBox,
81  Issues* outIssues);
82 
83 bool parseAttributes(
84  const nx::kit::Json& objectDescription,
85  std::map<std::string, std::string>* outAttributes,
86  Issues* outIssues);
87 
88 bool parseTimestamp(
89  const nx::kit::Json& objectDescription,
90  int64_t* outTimestamp,
91  Issues* outIssues);
92 
93 bool parseImageSource(
94  const nx::kit::Json& objectDescription,
95  std::string* outImageSource,
96  Issues* outIssues);
97 
98 std::string issueToString(Issue issue);
99 
100 } // namespace object_streamer
101 } // namespace stub
102 } // namespace analytics
103 } // namespace vms_server_plugins
104 } // namespace nx
Definition: json.cpp:80
Definition: uuid.h:22
Definition: apple_utils.h:6
Definition: rect.h:11