Web Detection detects Web references to an image.
| Category | Responses |
|---|---|
| Web entities |
|
| Full matching images |
|
| Partial matching images |
|
| Pages with matching images |
|
| Visually similar images |
|
| Best guess labels | rio carnival 2019 dancers |
Web detection requests
Set up your GCP project and authentication
Detect Web entities with 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 Web 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
WEB_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': [
{
'maxResults': 10,
'type': 'WEB_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.
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 Web entities with 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 Web 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
WEB_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/web/carnaval.jpeg'
}
},
'features': [
{
'maxResults': 10,
'type': 'WEB_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:
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 Web entities detection request using Windows PowerShell,
make a POST request to the
https://vision.googleapis.com/v1/images:annotate endpoint and specify
WEB_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/web/carnaval.jpeg'
}
},
'features': [
{
'type': 'WEB_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 Web detection, use the
gcloud ml vision detect-web
command as shown in the following example:
gcloud ml vision detect-web gs://cloud-samples-data/vision/web/carnaval.jpeg
Using geographic metadata
The Vision API can access geotag metadata in your image files to return more
relevant web entities and pages. To allow geotag usage, specify
'includeGeoResults': true in your request.
Command-line
To make a Web 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
WEB_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/web/carnaval.jpeg'
}
},
'features': [
{
'type': 'WEB_DETECTION'
}
],
'imageContext': {
'webDetectionParams': {
'includeGeoResults': true
}
}
}
]
}"
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:
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 .
PowerShell
To make a Web entities detection request using Windows PowerShell,
make a POST request to the
https://vision.googleapis.com/v1/images:annotate endpoint and specify
WEB_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/web/carnaval.jpeg'
}
},
'features': [
{
'type': 'WEB_DETECTION'
}
],
'imageContext': {
'webDetectionParams': {
'includeGeoResults': true
}
}
}
]
}" `
-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 Web detection, use the
gcloud ml vision detect-web
command as shown in the following example:
gcloud ml vision detect-web gs://cloud-samples-data/vision/web/carnaval.jpeg
Try it
Try Web entities detection below. You can use the
image specified already (gs://cloud-samples-data/vision/web/carnaval.jpeg)
or specify your own image in its place. Send the request by selecting
Execute.
Try repeating the request with includeGeoResults set to false.


