Logo Detection detects popular product logos within an image.
Logo detection requests
Set up your GCP project and authentication
Detect logos in a local image
The Vision API can perform feature detection on a local image file by sending the contents of the image file as a base64 encoded string in the body of your request.Command-line
To make a logo detection request using curl from the Linux
or MacOS command line,
make a POST request to the
https://vision.googleapis.com/v1/images:annotate endpoint and specify
LOGO_DETECTION as the value of features.type, as shown in the following
example:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
https://vision.googleapis.com/v1/images:annotate -d "{
'requests': [
{
"image": {
"content": "/9j/7QBEUGhvdG9zaG9...base64-encoded-image-content...fXNWzvDEeYxxxzj/Coa6Bax//Z"
},
'features': [
{
'type': 'LOGO_DETECTION'
},
]
}
]
}"
See the AnnotateImageRequest
reference documentation for more information on configuring the request body.
If the request is successful, the server returns a 200 OK HTTP status code and
the response in JSON format.
Response:
{
"responses": [
{
"logoAnnotations": [
{
"mid": "/m/045c7b",
"description": "google",
"score": 0.980325,
"boundingPoly": {
"vertices": [
{
"x": 12,
"y": 42
},
{
"x": 439,
"y": 42
},
{
"x": 439,
"y": 285
},
{
"x": 12,
"y": 285
}
]
}
}
]
}
]
}
C#
Before trying this sample, follow the C# setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API C# API reference documentation .
Go
Before trying this sample, follow the Go setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Go API reference documentation .
Java
Before trying this sample, follow the Java setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Java API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Node.js API reference documentation .
PHP
Before trying this sample, follow the PHP setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API PHP API reference documentation .
Python
Before trying this sample, follow the Python setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Python API reference documentation .
Ruby
Before trying this sample, follow the Ruby setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Ruby API reference documentation .
Detect Logos in a remote image
For your convenience, the Vision API can perform feature detection directly on an image file located in Google Cloud Storage or on the Web without the need to send the contents of the image file in the body of your request.Command-line
To make a logo detection request using curl from the Linux or
MacOS command
line,
make a POST request to the
https://vision.googleapis.com/v1/images:annotate endpoint and specify
LOGO_DETECTION as the value of features.type, as shown in the following
example:
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
https://vision.googleapis.com/v1/images:annotate -d "{
'requests': [
{
'image': {
'source': {
'gcsImageUri': 'gs://cloud-samples-data/vision/logo/google_logo.jpg'
}
},
'features': [
{
'type': 'LOGO_DETECTION'
},
]
}
]
}"
See the AnnotateImageRequest
reference documentation for more information on configuring the request body.
If the request is successful, the server returns a 200 OK HTTP status code and
the response in JSON format.
Response:
{
"responses": [
{
"logoAnnotations": [
{
"mid": "/m/045c7b",
"description": "google",
"score": 0.980325,
"boundingPoly": {
"vertices": [
{
"x": 12,
"y": 42
},
{
"x": 439,
"y": 42
},
{
"x": 439,
"y": 285
},
{
"x": 12,
"y": 285
}
]
}
}
]
}
]
}
C#
Before trying this sample, follow the C# setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API C# API reference documentation .
Go
Before trying this sample, follow the Go setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Go API reference documentation .
Java
Before trying this sample, follow the Java setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Java API reference documentation .
Node.js
Before trying this sample, follow the Node.js setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Node.js API reference documentation .
PHP
Before trying this sample, follow the PHP setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API PHP API reference documentation .
Python
Before trying this sample, follow the Python setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Python API reference documentation .
Ruby
Before trying this sample, follow the Ruby setup instructions in the Vision API Quickstart Using Client Libraries . For more information, see the Vision API Ruby API reference documentation .
PowerShell
To make a logo detection request using Windows PowerShell,
make a POST request to the
https://vision.googleapis.com/v1/images:annotate endpoint and specify
LOGO_DETECTION as the value of features.type, as shown in the following
example:
$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }
Invoke-WebRequest `
-Method Post `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-Body "{
'requests': [
{
'image': {
'source': {
'imageUri': 'gs://cloud-samples-data/vision/logo/google_logo.jpg'
}
},
'features': [
{
'type': 'LOGO_DETECTION'
}
]
}
]
}" `
-Uri "https://vision.googleapis.com/v1/images:annotate" | Select-Object -Expand Content
See the AnnotateImageRequest
reference documentation for more information on configuring the request body.
GCLOUD COMMAND
To perform image property detection, use the
gcloud ml vision detect-logos
command as shown in the following example:
gcloud ml vision detect-logos gs://cloud-samples-data/vision/logo/google_logo.jpg
Try it
Try logo detection below. You can use the
image specified already (gs://cloud-samples-data/vision/logo/google_logo.jpg)
or specify your own image in its place. Send the request by selecting
Execute.



