How to use the Google Cloud Vision API to detect violence or nudity?

3.5k views Asked by At

WHAT I CHECKED:

I went through the docs: https://cloud.google.com/vision/docs/

And saw this example: https://github.com/thesandlord/samples/blob/master/cloud-vision-nodejs/index.js


WHAT I AM TRYING TO ACHIEVE:

I would like to analyse every image uploaded by my users before they are saved to my google cloud bucket.

How can I detect violence or nudity using the Cloud Vision API?

1

There are 1 answers

2
Konstantin Kreft On BEST ANSWER

You can make use of inappropriate content detection via the Google Cloud Vision API. To make use of this feature, just add SAFE_SEARCH_DETECTION to your API request:

 {
    "image": {
          "content": "base64ImageString"
     },
    "features": [
      {
        "type": "SAFE_SEARCH_DETECTION"
      },
     // More feature detection types….
    ]
 }

You get an response like this:

"safeSearchAnnotation" : {
    "spoof" : "VERY_UNLIKELY",
    "medical" : "UNLIKELY",
    "adult" : "VERY_UNLIKELY",
    "violence" : "VERY_UNLIKELY"
 }

To read more about this feature, read the blog article by Google.