זיהוי תוכן בוטה בסרטונים

זיהוי תוכן בוטה מזהה תוכן למבוגרים בסרטונים. תוכן למבוגרים בלבד בדרך כלל לא מתאים לצופים מתחת לגיל 18, והוא כולל, בין היתר, עירום, פעילות מינית ופורנוגרפיה. גם תוכן כזה שמזוהה בסרטים מצוירים או באנימה מזוהה.

התשובה כוללת ערך סבירות שסווג לדלי, מ-VERY_UNLIKELY עד VERY_LIKELY.

כשמערכת זיהוי התוכן הבוטה בודקת סרטון, היא עושה זאת על בסיס כל פריים בנפרד ומתייחסת רק לתוכן הוויזואלי. רכיב האודיו של הסרטון לא משמש להערכת רמת התוכן הבוטה.

זוהי דוגמה לביצוע ניתוח של סרטון באמצעות התכונות של זיהוי תוכן בוטה בקובץ שנמצא ב-Cloud Storage.

REST

שליחת בקשה להוספת הערה לסרטון

בדוגמה הבאה אפשר לראות איך שולחים בקשת POST לשיטה videos:annotate. בדוגמה נעשה שימוש ב-Google Cloud CLI כדי ליצור אסימון גישה. הוראות להתקנת ה-CLI של gcloud מופיעות במאמר מדריך למתחילים בנושא Video Intelligence API.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • INPUT_URI: קטגוריה של Cloud Storage שמכילה את הקובץ שרוצים להוסיף לו הערות, כולל שם הקובץ. חייב להתחיל ב-gs://.
    לדוגמה: "inputUri": "gs://cloud-videointelligence-demo/assistant.mp4",
  • PROJECT_NUMBER: המזהה המספרי של Google Cloud הפרויקט

ה-method של ה-HTTP וכתובת ה-URL:

POST https://videointelligence.googleapis.com/v1/videos:annotate

תוכן בקשת JSON:

{
  "inputUri": "INPUT_URI",
  "features": ["EXPLICIT_CONTENT_DETECTION"]
}

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID"
}

אם התגובה מצליחה, Video Intelligence API מחזיר את name עבור הפעולה שלכם. בדוגמה שלמעלה אפשר לראות תגובה כזו, שבה:

  • PROJECT_NUMBER: מספר הפרויקט.
  • LOCATION_ID: האזור ב-Cloud שבו צריך להוסיף את ההערה. האזורים הנתמכים בענן הם: us-east1, ‏ us-west1,‏ europe-west1, ‏ asia-east1. אם לא מציינים אזור, המערכת תקבע אזור על סמך המיקום של קובץ הסרטון.
  • OPERATION_ID: המזהה של הפעולה הממושכת שנוצרה עבור הבקשה ומופיע בתגובה כשמתחילים את הפעולה, לדוגמה 12345...

קבלת תוצאות של אנוטציות

כדי לאחזר את תוצאת הפעולה, שולחים בקשת GET באמצעות שם הפעולה שמוחזר מהקריאה אל videos:annotate, כמו בדוגמה הבאה.

לפני שמשתמשים בנתוני הבקשה, צריך להחליף את הנתונים הבאים:

  • OPERATION_NAME: השם של הפעולה כפי שמוחזר על ידי Video Intelligence API. שם הפעולה הוא בפורמט projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID
  • PROJECT_NUMBER: המזהה המספרי של Google Cloud הפרויקט

ה-method של ה-HTTP וכתובת ה-URL:

GET https://videointelligence.googleapis.com/v1/OPERATION_NAME

כדי לשלוח את הבקשה צריך להרחיב אחת מהאפשרויות הבאות:

אתם אמורים לקבל תגובת JSON שדומה לזו:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoProgress",
    "annotationProgress": [
     {
      "inputUri": "/demomaker/gbikes_dinosaur.mp4",
      "progressPercent": 100,
      "startTime": "2020-03-26T00:16:35.112404Z",
      "updateTime": "2020-03-26T00:16:55.937889Z"
     }
    ]
   },
   "done": true,
   "response": {
    "@type": "type.googleapis.com/google.cloud.videointelligence.v1.AnnotateVideoResponse",
    "annotationResults": [
     {
      "inputUri": "/demomaker/gbikes_dinosaur.mp4",
      "explicitAnnotation": {
       "frames": [
        {
         "timeOffset": "0.056149s",
         "pornographyLikelihood": "VERY_UNLIKELY"
        },
        {
         "timeOffset": "1.166841s",
         "pornographyLikelihood": "VERY_UNLIKELY"
        },
            ...
        {
         "timeOffset": "41.678209s",
         "pornographyLikelihood": "VERY_UNLIKELY"
        },
        {
         "timeOffset": "42.596413s",
         "pornographyLikelihood": "VERY_UNLIKELY"
        }
       ]
      }
     }
    ]
   }
  }
הערות לגבי זיהוי צילומים מוחזרות כרשימה shotAnnotations. הערה: השדה done מוחזר רק כשהערך שלו הוא True. הוא לא נכלל בתשובות שהפעולה שלהן לא הושלמה.

הורדת תוצאות ההערות

מעתיקים את ההערה מהמקור לדלי היעד: (ראו העתקת קבצים ואובייקטים)

gcloud storage cp gcs_uri gs://my-bucket

הערה: אם המשתמש מספק את ה-URI של GCS בפלט, ההערה מאוחסנת ב-URI הזה.

Go


func explicitContentURI(w io.Writer, file string) error {
	ctx := context.Background()
	client, err := video.NewClient(ctx)
	if err != nil {
		return err
	}
	defer client.Close()

	op, err := client.AnnotateVideo(ctx, &videopb.AnnotateVideoRequest{
		Features: []videopb.Feature{
			videopb.Feature_EXPLICIT_CONTENT_DETECTION,
		},
		InputUri: file,
	})
	if err != nil {
		return err
	}
	resp, err := op.Wait(ctx)
	if err != nil {
		return err
	}

	// A single video was processed. Get the first result.
	result := resp.AnnotationResults[0].ExplicitAnnotation

	for _, frame := range result.Frames {
		offset, _ := ptypes.Duration(frame.TimeOffset)
		fmt.Fprintf(w, "%s - %s\n", offset, frame.PornographyLikelihood.String())
	}

	return nil
}

Java

כדי לבצע אימות ב-Video Intelligence, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

// Instantiate a com.google.cloud.videointelligence.v1.VideoIntelligenceServiceClient
try (VideoIntelligenceServiceClient client = VideoIntelligenceServiceClient.create()) {
  // Create an operation that will contain the response when the operation completes.
  AnnotateVideoRequest request =
      AnnotateVideoRequest.newBuilder()
          .setInputUri(gcsUri)
          .addFeatures(Feature.EXPLICIT_CONTENT_DETECTION)
          .build();

  OperationFuture<AnnotateVideoResponse, AnnotateVideoProgress> response =
      client.annotateVideoAsync(request);

  System.out.println("Waiting for operation to complete...");
  // Print detected annotations and their positions in the analyzed video.
  for (VideoAnnotationResults result : response.get().getAnnotationResultsList()) {
    for (ExplicitContentFrame frame : result.getExplicitAnnotation().getFramesList()) {
      double frameTime =
          frame.getTimeOffset().getSeconds() + frame.getTimeOffset().getNanos() / 1e9;
      System.out.printf("Location: %.3fs\n", frameTime);
      System.out.println("Adult: " + frame.getPornographyLikelihood());
    }
  }

Node.js

כדי לבצע אימות ב-Video Intelligence, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לסביבת פיתוח מקומית.

// Imports the Google Cloud Video Intelligence library
const video = require('@google-cloud/video-intelligence').v1;

// Creates a client
const client = new video.VideoIntelligenceServiceClient();

/**
 * TODO(developer): Uncomment the following line before running the sample.
 */
// const gcsUri = 'GCS URI of video to analyze, e.g. gs://my-bucket/my-video.mp4';

const request = {
  inputUri: gcsUri,
  features: ['EXPLICIT_CONTENT_DETECTION'],
};

// Human-readable likelihoods
const likelihoods = [
  'UNKNOWN',
  'VERY_UNLIKELY',
  'UNLIKELY',
  'POSSIBLE',
  'LIKELY',
  'VERY_LIKELY',
];

// Detects unsafe content
const [operation] = await client.annotateVideo(request);
console.log('Waiting for operation to complete...');
const [operationResult] = await operation.promise();
// Gets unsafe content
const explicitContentResults =
  operationResult.annotationResults[0].explicitAnnotation;
console.log('Explicit annotation results:');
explicitContentResults.frames.forEach(result => {
  if (result.timeOffset === undefined) {
    result.timeOffset = {};
  }
  if (result.timeOffset.seconds === undefined) {
    result.timeOffset.seconds = 0;
  }
  if (result.timeOffset.nanos === undefined) {
    result.timeOffset.nanos = 0;
  }
  console.log(
    `\tTime: ${result.timeOffset.seconds}` +
      `.${(result.timeOffset.nanos / 1e6).toFixed(0)}s`
  );
  console.log(
    `\t\tPornography likelihood: ${likelihoods[result.pornographyLikelihood]}`
  );
});

Python

מידע נוסף על התקנה ושימוש בספריית הלקוח של Cloud Video Intelligence API ל-Python זמין במאמר ספריות לקוח של Cloud Video Intelligence API.
"""Detects explicit content from the GCS path to a video."""
video_client = videointelligence.VideoIntelligenceServiceClient()
features = [videointelligence.Feature.EXPLICIT_CONTENT_DETECTION]

operation = video_client.annotate_video(
    request={"features": features, "input_uri": path}
)
print("\nProcessing video for explicit content annotations:")

result = operation.result(timeout=90)
print("\nFinished processing.")

# Retrieve first result because a single video was processed
for frame in result.annotation_results[0].explicit_annotation.frames:
    likelihood = videointelligence.Likelihood(frame.pornography_likelihood)
    frame_time = frame.time_offset.seconds + frame.time_offset.microseconds / 1e6
    print("Time: {}s".format(frame_time))
    print("\tpornography: {}".format(likelihood.name))

שפות נוספות

C#‎: צריך לפעול לפי הוראות ההגדרה של C# ‎ בדף של ספריות הלקוח ואז לעבור אל מאמרי העזרה של Video Intelligence בנושא ‎ .NET.

PHP: Please follow the PHP setup instructions on the client libraries page and then visit the Video Intelligence מאמרי עזרה for PHP.

Ruby: צריך לפעול לפי הוראות ההגדרה של Ruby בדף של ספריות הלקוח ואז לעבור אל מסמך העזר של Video Intelligence ל-Ruby.