Created
August 13, 2016 07:42
-
-
Save atotto/4fe3ec32d30b82d46206c459c1fd0aa8 to your computer and use it in GitHub Desktop.
google cloud vision golang example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gcv_test | |
import ( | |
"encoding/base64" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"google.golang.org/api/googleapi/transport" | |
vision "google.golang.org/api/vision/v1" | |
) | |
// https://github.com/google/google-api-go-client/blob/master/GettingStarted.md | |
const developerKey = `Your ServerKey` | |
func ExampleGoogleCloudVisionAPI() { | |
data, err := ioutil.ReadFile("fiveyears.jpg") | |
enc := base64.StdEncoding.EncodeToString(data) | |
img := &vision.Image{Content: enc} | |
feature := &vision.Feature{ | |
Type: "LABEL_DETECTION", | |
MaxResults: 10, | |
} | |
req := &vision.AnnotateImageRequest{ | |
Image: img, | |
Features: []*vision.Feature{feature}, | |
} | |
batch := &vision.BatchAnnotateImagesRequest{ | |
Requests: []*vision.AnnotateImageRequest{req}, | |
} | |
client := &http.Client{ | |
Transport: &transport.APIKey{Key: developerKey}, | |
} | |
svc, err := vision.New(client) | |
if err != nil { | |
log.Fatal(err) | |
} | |
res, err := svc.Images.Annotate(batch).Do() | |
if err != nil { | |
log.Fatal(err) | |
} | |
body, err := json.Marshal(res.Responses[0].LabelAnnotations) | |
fmt.Println(string(body)) | |
} |
Author
atotto
commented
Aug 13, 2016
Hey, I reused your sample code with Type: "DOCUMENT_TEXT_DETECTION"
.
I get textAnnotations but I'm unable to get fullTextAnnotations. Any idea why that would be?
p.s. this was resolved. No issue with code; it was a GOPATH setting mistake on my side. :-(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment