July14 ‐ 18 - gideonSamzz/Empetror_gs_docx GitHub Wiki

Label Detection code:

import asyncio import io from dotenv import load_dotenv from google.cloud import videointelligence

async def main(): video_client = videointelligence.VideoIntelligenceServiceAsyncClient()

features = [videointelligence.Feature.LABEL_DETECTION]

with open('./resource/dogs with owners.mp4', 'rb') as media_file:
    input_content = media_file.read()

operation = await video_client.annotate_video(
    request={
        'features': features,
        'input_content': input_content,
    }
)

print('\nProcessing video for label annotations:')
result = await operation.result(timeout=180)
print('\nFinished Processing')

segment_labels = result.annotation_results[0].segment_label_annotations

for segment_label in segment_labels:
    print('Video label description: {}'.format(segment_label.entity.description))

    for category_entity in segment_label.category_entities:
        print('\tLabel category: {}'.format(category_entity.description))

    for i, segment in enumerate(segment_label.segments):
        start_time = (segment.segment.start_time_offset.seconds + segment.segment.start_time_offset.microseconds / 1e6)
        end_time = (segment.segment.end_time_offset.seconds + segment.segment.end_time_offset.microseconds / 1e6)
        positions = '{}s to {}s'.format(start_time, end_time)
        confidence = segment.confidence
        print('\tsegment {}: {}'.format(i, positions))
        print('\tconfidence: {}'.format(confidence))
    print('\n')

if name == 'main': load_dotenv() asyncio.run(main())

output: Processing video for label annotations:

Finished Processing Video label description: pet Label category: animal segment 0: 0.0s to 11.745066s confidence: 0.8934332132339478

Video label description: sled dog Label category: dog segment 0: 0.0s to 11.745066s confidence: 0.6183649301528931

Video label description: alaskan malamute Label category: dog segment 0: 0.0s to 11.745066s confidence: 0.3922326862812042

Video label description: animal segment 0: 0.0s to 11.745066s confidence: 0.8232283592224121

Video label description: dog Label category: pet segment 0: 0.0s to 11.745066s confidence: 0.9907904863357544

Video label description: siberian husky Label category: dog segment 0: 0.0s to 11.745066s confidence: 0.4710979759693146

    confidence: 0.4710979759693146

    confidence: 0.4710979759693146
    confidence: 0.4710979759693146
    confidence: 0.4710979759693146
    confidence: 0.4710979759693146