Skip to content

Instantly share code, notes, and snippets.

@alfredayibonte
Created February 21, 2019 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alfredayibonte/5d23e13d600ff0c2487f8f0a2129131b to your computer and use it in GitHub Desktop.
Save alfredayibonte/5d23e13d600ff0c2487f8f0a2129131b to your computer and use it in GitHub Desktop.
OCR
const URL = `https://vision.googleapis.com/v1/images:annotate?key=${Config.GOOGLE_VISION_API_KEY}`;
export function ocr(base64) {
const request = {
requests: [
{
image: {
content: base64
},
features: [
{
type: 'TEXT_DETECTION',
maxResults: 200
}
]
}
]
};
return new Promise(function(resolve, reject) {
fetch(URL, {
method: 'POST',
headers: ['Content-Type', 'application/json'],
body: JSON.stringify(request)
})
.then(data => {
resolve(getText(data))
})
.catch(err => {
reject(err)
});
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment