Open alxbouchard opened 1 year ago
hey @alxbouchard ! The timestamp formats in the API JSONs have changed since the app was created -> so you need a hack to go around that to change new ts format into old ts format:
def get_paths(d):
def recur(d):
if isinstance(d, dict):
for key, value in d.items():
yield f'.{key}'
yield from (f'.{key}{p}' for p in get_paths(value))
elif isinstance(d, list):
for i, value in enumerate(d):
yield f'.{i}'
yield from (f'.{i}{p}' for p in get_paths(value))
list_paths = (p for p in recur(d))
return list_paths
list_paths = [path[1:] for path in list(get_paths(annotation_results_json))]`
# get ts paths:
ts_paths = [path for path in list_paths if "time_offset" in path]
def json_ts_change(json_file, path):
_original_value = glom.glom(json_file, path)
_ts_list = _original_value[:-1].split('.')
if len(_ts_list) == 1:
_s = int(_ts_list[0])
_nanos = 0
else:
_s, _ms = _ts_list
_s = int(_s)
_nanos = int(int(_ms)*1e6)
return {'seconds': _s, 'nanos': _nanos}
for path in ts_paths:
try:
_json_ts_change = json_ts_change(annotation_results_json, path)
_ = glom.assign(annotation_results_json, path, _json_ts_change)
except (TypeError, ValueError) as e:
print(path)
Hi @alxbouchard and @bbolint , a thing to note is that the json output from the Cloud Video Intelligence API is different if you call it interactively like you're doing here VS getting it to output to cloud storage which the demo is designed to work with. By specifying the output_uri like i do in the example script https://github.com/ZackAkil/video-intelligence-api-visualiser/blob/main/run_video_intelligence.py you should not need to make edits to the json. Hope this helps
Thanks guys! It works!
Hi!
The json file from this Qwik Start doesnt work : https://www.cloudskillsboost.google/focuses/603?parent=catalog&qlcampaign=77-18-gcpd-921&utm_source=gcp&utm_campaign=vintelligence&utm_medium=documentation
Any hints please?
Here's my Json file
{ "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse", "annotationResults": [ { "input_uri": "/video-ai-zap/test.mp4", "segment": { "endTimeOffset": "93.343250s", "start_time_offset": "0s" }, "segmentLabelAnnotations": [ { "categoryEntities": [ { "description": "car", "entityId": "/m/0k4j", "languageCode": "en-US" } ], "entity": { "description": "off road vehicle", "entityId": "/m/035f_j", "languageCode": "en-US" }, "segments": [ { "confidence": 0.61001694, "segment": { "endTimeOffset": "93.343250s", "startTimeOffset": "0s" } } ] }....,