I am reading documentation on vision API request schema. In image source, I only see option of using url of GCS image paths. Is it possible to use external image url like http://example.com/images/image01.jpg ?
Yes, this is working perfectly fine:
{
"requests": [
{
"features": [
{
"type": "WEB_DETECTION"
}
],
"image": {
"source": {
"imageUri": "http://i3.kym-cdn.com/photos/images/facebook/000/242/592/1c8.jpg"
}
}
}
]
}
Yes it can, but ONLY using google cloud storage urls. Try this:
{
"requests": [
{
"image": {
"source": {
gcsImageUri: 'gs://something.com/image',
},
},
"features": ...
"imageContext": ...
},
]
}
Yes, you can do this with any image as long as it is smaller than 4Mb. It does not have to be on Google Cloud Storage.
Here is an example using the Golang client library:
// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
// [START vision_quickstart]
// Sample vision-quickstart uses the Google Cloud Vision API to label an image.
package main
import (
"fmt"
"log"
// Imports the Google Cloud Vision API client package.
vision "cloud.google.com/go/vision/apiv1"
"golang.org/x/net/context"
)
func main() {
ctx := context.Background()
// Creates a client.
client, err := vision.NewImageAnnotatorClient(ctx)
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
image := vision.NewImageFromURI("https://www.denaligrizzlybear.com/assets/images/scenic-denali.jpg")
labels, err := client.DetectLabels(ctx, image, nil, 10)
if err != nil {
log.Fatalf("Failed to detect labels: %v", err)
}
fmt.Println("Labels:")
for _, label := range labels {
fmt.Println(label.Description)
}
}
Here is the function on the Godoc:https://godoc.org/cloud.google.com/go/vision/apiv1#NewImageFromURI
The docs state:
NewImageFromURI returns an image that refers to an object in Google
Cloud Storage (when the uri is of the form "gs://BUCKET/OBJECT") or at
a public URL.
Answer for python users.
def detect_labels_uri(uri):
"""Detects labels in the file located in Google Cloud Storage or on the
Web."""
from google.cloud import vision
client = vision.ImageAnnotatorClient()
image = vision.types.Image()
image.source.image_uri = uri
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
print(label.description)
# [END vision_label_detection_gcs]
Yes you can use external image URL and even can use BASE64 image content also.
You can find the same in official documentation also.
Documentation URL : https://cloud.google.com/vision/docs/request#json_request_format
I have checked it with all available options and it is working fine for me.
Yes, Google Cloud Vision API DOES accept external URL images. I just used this image to get labels:
python label_sample.py -u "https://upload.wikimedia.org/wikipedia/commons/e/e6/Bleeding_finger.jpg"
Found label: red with 96.47 percent probability!!!!!!!!!!!
Found label: color with 95.46 percent probability!!!!!!!!!!!
Found label: pink with 92.15 percent probability!!!!!!!!!!!
Found label: finger with 91.06 percent probability!!!!!!!!!!!
Found label: hand with 90.45 percent probability!!!!!!!!!!!
Found label: nail with 73.23 percent probability!!!!!!!!!!!
Found label: lip with 73.09 percent probability!!!!!!!!!!!
Found label: jewellery with 68.84 percent probability!!!!!!!!!!!
Found label: produce with 68.39 percent probability!!!!!!!!!!!
Found label: macro photography with 67.86 percent probability!!!!!!!!!!!
You have to give it the url in proper format using urllib library and comment the part of opening an image like this:
url = url_file
opener = urllib.urlopen(url)
# with open(photo_file, 'rb') as image:
image_content = base64.b64encode(opener.read())
Related
I am using the positionning v2 API to locate some assetes using mac Addresses of Accesspoints. It is working well, but sometimes a mac address is not located where it is supposed to. So when I try to locate a position with 5-6 mac Addresses (the location of 1 mac Address is not correct), the API give me that message :
'title': 'Not Found', 'status': 404, 'code': 'E606404', 'action': 'The values provided in the request cannot produce any content for the response. The location of the WLANs and cells in the request is unknown or the locations of the radio measurements are so widely scattered that the location cannot be determined. Make sure that the network measurements are correct and consistent. Try allowing fallbacks area or any for cell positioning and singleWifi for WLAN positioning.', 'cause': 'Position not found'
How can I bypass that kind of error?
Here is the code :
data = {
"wlan": []
}
#for wifi in networks:
entry = {
"mac": "xx:xx:xx:xx:xx:xx",
"rss": -42
}
data["wlan"].append(entry)
entry1 = {
"mac": "yy:yy:yy:yy:yy:yy",
"rss": -54
}
data["wlan"].append(entry1)
entry2 = {
"mac": "zz:zz:zz:zz:zz:zz",
"rss": -76
}
data["wlan"].append(entry2)
#This mac address is not well located (400 kms difference from the real position)
#entry3 = {
# "mac": "vv:vv:vv:vv:vv:vv",
# "rss": -64
#}
#data["wlan"].append(entry3)
import json
import requests
headers = {"Content-Type": "application/json"}
url = "https://positioning.hereapi.com/v2/locate?apiKey=" + "my_api_key" + "&desired=altitude" + "&fallback=singleWifi"
print(data)
response = requests.post(url, headers=headers, data=json.dumps(data))
Could you please try with below sample code. And for best results please follow the tips defined in the document link:
Doc Link: https://developer.here.com/documentation/positioning-api/dev_guide/topics/tips-for-data-accuracy.html
import requests
import json
url = "https://positioning.hereapi.com/v2/locate?apiKey={your_api_key}&desired=altitude&fallback=singleWifi"
payload = json.dumps({
"wlan": [
{
"mac": "xxxxxx"
},
{
"mac": "xxxxxx"
}
]
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
I want to upload Powerpoint files to Google drive. When I do this using the UI (clicking on "Upload File" and uploading a file), things work as I expect. However, when I use the Drive API I get some formatting issues. For example, the shading (text highlight) in my Powerpoint tables is transparent, but when I upload to Drive using the API the shading becomes white.
I have tried to work around this by specifying MIME type as application/vnd.google-apps.file, but when I get the response, the MIME type shows as application/vnd.google-apps.presentation
I am using Google Drive API v3, accessed through the R package googledrive.
Try to use this mimeType : application/vnd.openxmlformats-officedocument.presentationml.presentation
including :
application/vnd.google-apps.file
Here is an example done with NodeJS, try and let me know if it works well for you.
Just in case, try other mimeTypes (url is provided on Reference list, scroll down)
var fileMetadata = {
'name': '___Your File Name Here___',
'mimeType': 'application/vnd.google-apps.file'
};
var media = {
mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
body: fs.createReadStream('___Your File Name Here___.pptx')
};
function uploadFile(auth){
const drive = google.drive({version: 'v3', auth});
drive.files.create({
resource: fileMetadata,
media: media,
fields: 'id'
}, (err, res) => {
if (err) return console.log('The API returned an error: ' + err);
})
}
// RUN script
fs.readFile('credentials.json', (err, content) => {
if (err) {
console.log('Error loading client secret file: ' + err);
return;
}
authorize(JSON.parse(content), uploadFile);
});
References:
Google mimeTypes (Google Reference)
List of mimeTypes (MDN)
I'm creating a dynamic link via API.
How can I specify to open the AppStore if the app is not installed?
here the body for my request:
{
"dynamicLinkInfo": {
"domainUriPrefix": "https://wi.page.link",
"link": "https://wiapp.com.au/faq?promocode=mypromo_code",
"iosInfo": {
"iosBundleId": "com.direce.sr",
"iosFallbackLink":"id1356389392",
"iosAppStoreId":"id1368389392",
},
"socialMetaTagInfo" :{
"socialImageLink":"https://vignette.wikia.nocookie.net/doraemon/images/b/b8/Doraemon_2005.PNG/revision/latest?cb=20151207094313&path-prefix=en",
"socialTitle":"my titu",
"socialDescription":"descripotio"
}
},
"suffix": {
"option":"UNGUESSABLE"
},
}
this works if I create the dynamic link via firebase console, where I can specify what to do if app not installed
Ok!
found the problem, is the
"iosAppStoreId":"id1368389392"
it is different value if creating from the dashboard or for API,
so the correct one when doing from, API should be without the "id"
"iosAppStoreId":"1368389392"
You can add a parameter called iosInfo, which has a property called iosAppStoreId (the app store id).
Check the documentation page here.
I just tested the Google Cloud Vision API to read the text, if exist, in a image.
Until now I installed the Maven Server and the Redis Server. I just follow the instructions in this page.
https://github.com/GoogleCloudPlatform/cloud-vision/tree/master/java/text
Until now I was able to tested with .jpg files, is it possible to do it with tiff files or pdf??
I am using the following command:
java -cp target/text-1.0-SNAPSHOT-jar-with-dependencies.jar com.google.cloud.vision.samples.text.TextApp ../../data/text/
Inside the text directory, I have the files in jpg format.
Then to read the converted file, I don't know how to do that, just I run the following command
java -cp target/text-1.0-SNAPSHOT-jar-with-dependencies.jar com.google.cloud.vision.samples.text.TextApp
And I get the message to enter a word or phrase to search in the converted files. Is there a way to see the whole document transformed?
Thanks!
On April 6, 2018, support for PDF and TIFF files in document text detection was added to Google Cloud Vision API (see Release Notes).
According to the documentation:
The Vision API can detect and transcribe text from PDF and TIFF
files stored in Google Cloud Storage.
Document text detection from PDF and TIFF must be requested using the
asyncBatchAnnotate function, which performs an asynchronous request and provides its status using the operations resources.
Output from a PDF/TIFF request is written to a JSON file created in the specified Google Cloud Storage bucket.
Example:
1) Upload a file to your Google Cloud Storage
2) Make a POST request to perform PDF/TIFF document text detection
Request:
POST https://vision.googleapis.com/v1p2beta1/files:asyncBatchAnnotate
Authorization: Bearer <your access token>
{
"requests":[
{
"inputConfig": {
"gcsSource": {
"uri": "gs://<your bucket name>/input.pdf"
},
"mimeType": "application/pdf"
},
"features": [
{
"type": "DOCUMENT_TEXT_DETECTION"
}
],
"outputConfig": {
"gcsDestination": {
"uri": "gs://<your bucket name>/output/"
},
"batchSize": 1
}
}
]
}
Response:
{
"name": "operations/9b1f9d773d216406"
}
3) Make a GET request to check if document text detection is done
Request:
GET https://vision.googleapis.com/v1/operations/9b1f9d773d216406
Authorization: Bearer <your access token>
Response:
{
"name": "operations/9b1f9d773d216406",
"metadata": {
"#type": "type.googleapis.com/google.cloud.vision.v1p2beta1.OperationMetadata",
"state": "RUNNING",
"updateTime": "2018-06-17T20:18:09.117787733Z"
},
"done": true,
"response": {
"#type": "type.googleapis.com/google.cloud.vision.v1p2beta1.AsyncBatchAnnotateFilesResponse",
"responses": [
{
"outputConfig": {
"gcsDestination": {
"uri": "gs://<your bucket name>/output/"
},
"batchSize": 1
}
}
]
}
}
4) Check the results in the specified Google Cloud Storage folder
In 2016 PDF and TIFF formats was not supported for Cloud Vision.
The accepted formats are : (taken from the the doc)
JPEG
PNG8
PNG24
GIF
Animated GIF (first frame only)
BMP
WEBP
RAW
ICO
But now are added.
Docs for jpg:
https://cloud.google.com/vision/docs/ocr
Docs for pdf
https://cloud.google.com/vision/docs/pdf
https://cloud.google.com/vision/docs/pdf
I know this question is old, but now Google Vision released support for PDF!
Now google cloud vision text detection is available in for pdf file as well which detect text in pdf file immediately in synchronous way and doesn't require file to be in google storage it can be in base 64 format.
HTTP method and URL:
POST https://vision.googleapis.com/v1/files:annotate
Request JSON body:
{
"requests": [
{
"inputConfig": {
"content": "base64-encoded-file",
"mimeType": "application/pdf"
},
"features": [
{
"type": "DOCUMENT_TEXT_DETECTION"
}
],
"pages": [
1,2,3,4,5
]
}
]
}
For more information on it visit https://cloud.google.com/vision/docs/file-small-batch
How do I call the Vision API and apply more than one feature on an image.
I want to apply both Label Detection and the landmark detection on an image
You can define your request as below to incorporate multiple feature requests per image
"requests":[
{
"image":{
"content":"/9j/7QBEUGhvdG9zaG9...image contents...fXNWzvDEeYxxxzj/Coa6Bax//Z"
},
"features":[
{
"type":"FACE_DETECTION",
"maxResults":10
},
{
"type":"LABEL_DETECTION",
"maxResults":10
}
]
}
]
}
from google.cloud import vision
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/path/client.json"
client = vision.ImageAnnotatorClient()
response = client.annotate_image({
'image': {'source': {'image_uri': 'gs://yourbuket/1.jpg'}},
'features': [{'type': vision.enums.Feature.Type.LABEL_DETECTION},
{'type': vision.enums.Feature.Type.FACE_DETECTION}],
})