Google Cloud Video Intelligence 提供以下代码来解析带有对象跟踪的注释结果:
features = [videointelligence.Feature.OBJECT_TRACKING]
context = videointelligence.VideoContext(segments=None)
request = videointelligence.AnnotateVideoRequest(input_uri=gs_video_path, features=features, video_context=context, output_uri=output_uri)
operation = video_client.annotate_video(request)
result = operation.result(timeout=3600)
object_annotations = result.annotation_results[0].object_annotations
for object_annotation in object_annotations:
print('Entity description: {}'.format(object_annotation.entity.description))
print('Segment: {}s to {}s'.format(
object_annotation.segment.start_time_offset.total_seconds(),
object_annotation.segment.end_time_offset.total_seconds()))
print('Confidence: {}'.format(object_annotation.confidence))
# Here we print only the bounding box of the first frame_annotation in the segment
frame_annotation = object_annotation.frames[0]
box = frame_annotation.normalized_bounding_box
timestamp = frame_annotation.time_offset.total_seconds()
timestamp_end = object_annotation.segment.end_time_offset.total_seconds()
print('Time offset of the first frame_annotation: {}s'.format(timestamp))
print('Bounding box position:')
print('\tleft : {}'.format(box.left))
print('\ttop : {}'.format(box.top))
print('\tright : {}'.format(box.right))
print('\tbottom: {}'.format(box.bottom))
print('\n')
但是,我想解析通过 output_uri 生成的 json 文件。json文件的格式如下:
{
"annotation_results": [ {
"input_uri": "/production.supereye.co.uk/video/54V5x8q0CRU/videofile.mp4",
"segment": {
"start_time_offset": {
},
"end_time_offset": {
"seconds": 22,
"nanos": 966666000
}
},
"object_annotations": [ {
"entity": {
"entity_id": "/m/01yrx",
"description": "cat",
"language_code": "en-US"
},
"confidence": 0.91939145,
"frames": [ {
"normalized_bounding_box": {
"left": 0.17845993,
"top": 0.44048917,
"right": 0.5315634,
"bottom": 0.7752136
},
"time_offset": {
}
}, {
如何使用示例代码解析 output_uri 提供的 JSON?这需要什么样的转换?