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  std::string typeId;
23  nx::sdk::Uuid trackId;
24  nx::sdk::analytics::Rect boundingBox;
25  std::map<std::string, std::string> attributes;
26  int frameNumberToGenerateObject = 0;
27  int64_t timestampUs = -1;
28 };
29 
30 enum class Issue
31 {
32  objectStreamIsNotAValidJson,
33  objectStreamIsNotAJsonArray,
34  objectItemIsNotAJsonObject,
35  trackIdIsNotAString,
36  trackIdIsNotAUuid,
37  typeIdIsNotAString,
38  frameNumberIsNotANumber,
39  boundingBoxIsNotAJsonObject,
40  topLeftXIsNotANumber,
41  topLeftYIsNotANumber,
42  widthIsNotANumber,
43  heightIsNotANumber,
44  objectIsOutOfBounds,
45  attributesFieldIsNotAJsonObject,
46  attributeValueIsNotAString,
47  timestampIsNotANumber,
48 };
49 
50 struct Issues
51 {
52  std::set<Issue> errors;
53  std::set<Issue> warnings;
54 };
55 
56 struct StreamInfo
57 {
58  std::map<int, std::vector<Object>> objectsByFrameNumber;
59  std::set<std::string> objectTypeIds;
60 };
61 
62 StreamInfo parseObjectStreamFile(const std::string& filePath, Issues* outIssues);
63 
64 bool parseCommonFields(
65  const nx::kit::Json& objectDescription,
66  Object* outObject,
67  Issues* outIssues);
68 
69 bool parseBoundingBox(
70  const nx::kit::Json& objectDescription,
71  nx::sdk::analytics::Rect* outBoundingBox,
72  Issues* outIssues);
73 
74 bool parseAttributes(
75  const nx::kit::Json& objectDescription,
76  std::map<std::string, std::string>* outAttributes,
77  Issues* outIssues);
78 
79 bool parseTimestamp(
80  const nx::kit::Json& objectDescription,
81  int64_t* outTimestamp,
82  Issues* outIssues);
83 
84 std::string issueToString(Issue issue);
85 
86 } // namespace object_streamer
87 } // namespace stub
88 } // namespace analytics
89 } // namespace vms_server_plugins
90 } // namespace nx
Definition: json.cpp:80
Definition: uuid.h:22
Definition: apple_utils.h:6
Definition: rect.h:11