Skip to content

Instantly share code, notes, and snippets.

@ryqndev
Last active November 17, 2018 22:02
Show Gist options
  • Save ryqndev/df55b8a85b56de2d55d6c6c2d62f4130 to your computer and use it in GitHub Desktop.
Save ryqndev/df55b8a85b56de2d55d6c6c2d62f4130 to your computer and use it in GitHub Desktop.
Google Cloud Platform Text Recognition
// const GCPAPIKEY = 'Enter your key here';
// const IMAGEURL = 'https://images-na.ssl-images-amazon.com/images/I/816C3tZ76IL.jpg'
function getTextFromGCP(GCPAPIKEY, IMAGEURL){
var data = `
{
"requests": [
{
"image": {
"source": {
"imageUri": "${IMAGEURL}"
}
},
"features": [
{
"type": "TEXT_DETECTION"
}
]
}
]
}
`;
var xhr = new XMLHttpRequest();
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", `https://vision.googleapis.com/v1/images:annotate?key=${GCPAPIKEY}`);
xhr.send(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment