A partire dal 14 settembre 2026, l'API Video Intelligence è ufficialmente ritirata e non sarà più supportata. Puoi continuare a utilizzare l'API Video Intelligence fino al 14 settembre 2027, data in cui verrà ritirata. Ti consigliamo di eseguire la migrazione alla famiglia di modelli Gemini.
Google utilizza la tecnologia AI per tradurre i contenuti nella tua lingua preferita. Le traduzioni generate dall'AI potrebbero contenere errori.
Monitoraggio oggetti
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Il monitoraggio degli oggetti tiene traccia di più oggetti rilevati in un video di input.
Utilizzare i dati video AutoML
Prima di iniziare
Per informazioni di base sulla creazione di un modello AutoML, consulta la Guida introduttiva a Vertex AI
. Per
istruzioni su come creare il modello AutoML, inizia con "Creare un set di dati"
utilizzando la console
o l'API.
Usare il modello AutoML
Il seguente esempio di codice mostra come utilizzare il modello
AutoML
per il monitoraggio degli oggetti utilizzando la libreria client di streaming.
importcom.google.api.gax.rpc.BidiStream;importcom.google.cloud.videointelligence.v1p3beta1.ObjectTrackingAnnotation;importcom.google.cloud.videointelligence.v1p3beta1.ObjectTrackingFrame;importcom.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoRequest;importcom.google.cloud.videointelligence.v1p3beta1.StreamingAnnotateVideoResponse;importcom.google.cloud.videointelligence.v1p3beta1.StreamingAutomlObjectTrackingConfig;importcom.google.cloud.videointelligence.v1p3beta1.StreamingFeature;importcom.google.cloud.videointelligence.v1p3beta1.StreamingVideoAnnotationResults;importcom.google.cloud.videointelligence.v1p3beta1.StreamingVideoConfig;importcom.google.cloud.videointelligence.v1p3beta1.StreamingVideoIntelligenceServiceClient;importcom.google.protobuf.ByteString;importio.grpc.StatusRuntimeException;importjava.io.IOException;importjava.nio.file.Files;importjava.nio.file.Path;importjava.nio.file.Paths;importjava.util.Arrays;classStreamingAutoMlObjectTracking{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringfilePath="YOUR_VIDEO_FILE";StringprojectId="YOUR_PROJECT_ID";StringmodelId="YOUR_AUTOML_OBJECT_TRACKING_MODEL_ID";streamingAutoMlObjectTracking(filePath,projectId,modelId);}// Perform streaming video object tracking with an AutoML ModelstaticvoidstreamingAutoMlObjectTracking(StringfilePath,StringprojectId,StringmodelId)throwsStatusRuntimeException,IOException{try(StreamingVideoIntelligenceServiceClientclient=StreamingVideoIntelligenceServiceClient.create()){Pathpath=Paths.get(filePath);byte[]data=Files.readAllBytes(path);// Set the chunk size to 5MB (recommended less than 10MB).intchunkSize=5*1024*1024;intnumChunks=(int)Math.ceil((double)data.length/chunkSize);StringmodelPath=String.format("projects/%s/locations/us-central1/models/%s",projectId,modelId);StreamingAutomlObjectTrackingConfigstreamingAutomlObjectTrackingConfig=StreamingAutomlObjectTrackingConfig.newBuilder().setModelName(modelPath).build();StreamingVideoConfigstreamingVideoConfig=StreamingVideoConfig.newBuilder().setFeature(StreamingFeature.STREAMING_AUTOML_OBJECT_TRACKING).setAutomlObjectTrackingConfig(streamingAutomlObjectTrackingConfig).build();BidiStream<StreamingAnnotateVideoRequest,StreamingAnnotateVideoResponse>call=client.streamingAnnotateVideoCallable().call();// The first request must **only** contain the audio configuration:call.send(StreamingAnnotateVideoRequest.newBuilder().setVideoConfig(streamingVideoConfig).build());// Subsequent requests must **only** contain the audio data.// Send the requests in chunksfor(inti=0;i < numChunks;i++){call.send(StreamingAnnotateVideoRequest.newBuilder().setInputContent(ByteString.copyFrom(Arrays.copyOfRange(data,i*chunkSize,i*chunkSize+chunkSize))).build());}// Tell the service you are done sending datacall.closeSend();for(StreamingAnnotateVideoResponseresponse:call){StreamingVideoAnnotationResultsannotationResults=response.getAnnotationResults();for(ObjectTrackingAnnotationobjectAnnotations:annotationResults.getObjectAnnotationsList()){Stringentity=objectAnnotations.getEntity().getDescription();floatconfidence=objectAnnotations.getConfidence();longtrackId=objectAnnotations.getTrackId();System.out.format("%s: %f (ID: %d)\n",entity,confidence,trackId);// In streaming, there is always one frame.ObjectTrackingFrameframe=objectAnnotations.getFrames(0);doubleoffset=frame.getTimeOffset().getSeconds()+frame.getTimeOffset().getNanos()/1e9;System.out.format("Offset: %f\n",offset);System.out.println("Bounding Box:");System.out.format("\tLeft: %f\n",frame.getNormalizedBoundingBox().getLeft());System.out.format("\tTop: %f\n",frame.getNormalizedBoundingBox().getTop());System.out.format("\tRight: %f\n",frame.getNormalizedBoundingBox().getRight());System.out.format("\tBottom: %f\n",frame.getNormalizedBoundingBox().getBottom());}}System.out.println("Video streamed successfully.");}}}
/** * TODO(developer): Uncomment these variables before running the sample. */// const path = 'Local file to analyze, e.g. ./my-file.mp4';// const modelId = 'AutoML model'// const projectId = 'Your GCP Project'const{StreamingVideoIntelligenceServiceClient}=require('@google-cloud/video-intelligence').v1p3beta1;constfs=require('fs');// Instantiates a clientconstclient=newStreamingVideoIntelligenceServiceClient();// Streaming configurationconstmodelName=`projects/${projectId}/locations/us-central1/models/${modelId}`;constconfigRequest={videoConfig:{feature:'STREAMING_AUTOML_OBJECT_TRACKING',automlObjectTrackingConfig:{modelName:modelName,},},};constreadStream=fs.createReadStream(path,{highWaterMark:5*1024*1024,//chunk size set to 5MB (recommended less than 10MB)encoding:'base64',});//Load file content// Note: Input videos must have supported video codecs. See// https://cloud.google.com/video-intelligence/docs/streaming/streaming#supported_video_codecs// for more details.constchunks=[];readStream.on('data',chunk=>{constrequest={inputContent:chunk.toString(),};chunks.push(request);}).on('close',()=>{// configRequest should be the first in the stream of requestsstream.write(configRequest);for(leti=0;i < chunks.length;i++){stream.write(chunks[i]);}stream.end();});conststream=client.streamingAnnotateVideo().on('data',response=>{//Gets annotations for videoconstannotations=response.annotationResults;constobjects=annotations.objectAnnotations;objects.forEach(object=>{console.log(`Entity description: ${object.entity.description}`);console.log(`Entity id: ${object.entity.entityId}`);console.log(`Track id: ${object.trackId}`);console.log(`Confidence: ${object.confidence}`);console.log(`Time offset for the frame: ${object.frames[0].timeOffset.seconds||0}`+`.${(object.frames[0].timeOffset.nanos/1e6).toFixed(0)}s`);//Every annotation has only one frame.constbox=object.frames[0].normalizedBoundingBox;console.log('Bounding box position:');console.log(`\tleft: ${box.left}`);console.log(`\ttop: ${box.top}`);console.log(`\tright: ${box.right}`);console.log(`\tbottom: ${box.bottom}`);});});
importiofromgoogle.cloudimportvideointelligence_v1p3beta1asvideointelligence# path = 'path_to_file'# project_id = 'project_id'# model_id = 'automl_object_tracking_model_id'client=videointelligence.StreamingVideoIntelligenceServiceClient()model_path="projects/{}/locations/us-central1/models/{}".format(project_id,model_id)automl_config=videointelligence.StreamingAutomlObjectTrackingConfig(model_name=model_path)video_config=videointelligence.StreamingVideoConfig(feature=videointelligence.StreamingFeature.STREAMING_AUTOML_OBJECT_TRACKING,automl_object_tracking_config=automl_config,)# config_request should be the first in the stream of requests.config_request=videointelligence.StreamingAnnotateVideoRequest(video_config=video_config)# Set the chunk size to 5MB (recommended less than 10MB).chunk_size=5*1024*1024# Load file content.# Note: Input videos must have supported video codecs. See# https://cloud.google.com/video-intelligence/docs/streaming/streaming#supported_video_codecs# for more details.stream=[]withio.open(path,"rb")asvideo_file:whileTrue:data=video_file.read(chunk_size)ifnotdata:breakstream.append(data)defstream_generator():yieldconfig_requestforchunkinstream:yieldvideointelligence.StreamingAnnotateVideoRequest(input_content=chunk)requests=stream_generator()# streaming_annotate_video returns a generator.# The default timeout is about 300 seconds.# To process longer videos it should be set to# larger than the length (in seconds) of the stream.responses=client.streaming_annotate_video(requests,timeout=900)# Each response corresponds to about 1 second of video.forresponseinresponses:# Check for errors.ifresponse.error.message:print(response.error.message)breakobject_annotations=response.annotation_results.object_annotations# object_annotations could be emptyifnotobject_annotations:continueforannotationinobject_annotations:# Each annotation has one frame, which has a timeoffset.frame=annotation.frames[0]time_offset=(frame.time_offset.seconds+frame.time_offset.microseconds/1e6)description=annotation.entity.descriptionconfidence=annotation.confidence# track_id tracks the same object in the video.track_id=annotation.track_id# description is in Unicodeprint("{}s".format(time_offset))print("\tEntity description: {}".format(description))print("\tTrack Id: {}".format(track_id))ifannotation.entity.entity_id:print("\tEntity id: {}".format(annotation.entity.entity_id))print("\tConfidence: {}".format(confidence))# Every annotation has only one frameframe=annotation.frames[0]box=frame.normalized_bounding_boxprint("\tBounding box position:")print("\tleft : {}".format(box.left))print("\ttop : {}".format(box.top))print("\tright : {}".format(box.right))print("\tbottom: {}\n".format(box.bottom))
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2026-10-14 UTC."],[],[]]