Last active
November 16, 2017 07:55
-
-
Save gguuss/3c69f7fb5457f1824a0fa286e01e4922 to your computer and use it in GitHub Desktop.
Based almost completely off of - https://medium.com/@srobtweets/adding-computer-vision-to-your-ios-app-66d6f540cdd2
This file contains hidden or 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
const Vision = require("@google-cloud/vision"); | |
const functions = require('firebase-functions'); | |
const admin = require('firebase-admin'); | |
const vision = new Vision(); | |
admin.initializeApp(functions.config().firebase); | |
const db = admin.firestore(); | |
exports.callVision = functions.storage.object().onChange(event => { | |
const gcsPath = `gs://${event.data.bucket}/${event.data.name}`; | |
const req = { source: { imageUri: gcsPath } }; | |
return vision.labelDetection(req).then(response => { | |
return {labels: response[0].labelAnnotations}; | |
}).then((visionResp) => { | |
return db.collection('images').doc(filePath.slice(7)).set(visionResp); | |
}).catch(err => { | |
console.log('vision api error', err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment