Code Monkey home page Code Monkey logo

cloudvisionlib's Introduction

#Cloud Vision Lib

This is a simple wrapper for Google's new Cloud Vision API.

It uses the latest version of Retrofit2 and the example app was built using the latest preview of Android Studio (2.1 preview 4 at time of writing, with alpha gradle pluging) so please be aware of that if you run into compiling issues.

##Usage First and foremost, to get access to the API, you need to follow the directions written here:

http://cloud.google.com/vision/docs/getting-started

Make sure you do everything in 'Setup up your project' in order to get an api key. You shouldn't need to setup a Cloud Storage bucket for use with an Android app.

For using the library on its own, you can clone this repo and include the module, or, via jcenter() you can add it to your build.gradle dependencies {}:

compile 'net.trippedout:cloudvisionlib:0.1.0'

Once imported, you can start sending ImageRequests to the service.

Setup your CloudVisionService:

mCloudVisionService = CloudVisionApi.getCloudVisionService();

Then, since there's only one API call (for now), get an image and determine what features you want in your response, and call the API:

String encodedData = ImageUtil.getEncodedImageData(path/to/file or Bitmap you want to use);

Call<VisionResponse> call = mCloudVisionService.getAnnotations(
    "yourApiKey", // you get this key from the getting-started steps above        
    CloudVisionApi.getTestRequestAllFeatures(encodedData) // uses all possible features with default result number
)

If you are familiar with Retrofit this should look familiar: .enqueue() the response, and use the built in helper class or handle it like any other Retrofit call.

Check out ImageActivity#getFaces() for implementation specifics.

The VisionResponse object will contain a map of all the features you requested. In our example, we pass all the face detect annotations to our custom FaceFeaturesView, an extension of ImageView that draws the annotations on top of its image, in the correct scale.

CloudVisionApi.FaceDetectResponse faceDetectResponse 
    = (CloudVisionApi.FaceDetectResponse) response.getResponseByType(CloudVisionApi.FEATURE_TYPE_FACE_DETECTION);
mFaceFeaturesView.setFaceAnnotations(faceDetectResponse.faceAnnotations);

cloudvisionlib's People

Contributors

sriharrsha avatar trippedout avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.