Posts

Showing posts with the label google-vision

Wait for the Google Vision OCR promise in node.js/express and return it

Image
Clash Royale CLAN TAG #URR8PPP Wait for the Google Vision OCR promise in node.js/express and return it I am having problems to return a promise from the Google Vision OCR. Here is the sample code from Google: const vision = require('@google-cloud/vision'); // Creates a client const client = new vision.ImageAnnotatorClient(); /** * TODO(developer): Uncomment the following line before running the sample. */ // const fileName = 'Local image file, e.g. /path/to/image.png'; // Performs text detection on the local file client .textDetection(fileName) .then(results => { const detections = results[0].fullTextAnnotation.text; console.log('Text:'); console.log(detections); }) .catch(err => { console.error('ERROR:', err); }); This will output the full text to the console. If I put the above code into a function and return the variable detections I get only undef...

Google Cloud Functions Text Extraction from image using Vision API

Image
Clash Royale CLAN TAG #URR8PPP Google Cloud Functions Text Extraction from image using Vision API I am following the tutorial to extract text from images at: https://cloud.google.com/functions/docs/tutorials/ocr?authuser=1 But I do not wish to translate the text, I wish to detect and save the text. The tutorial implements 3 functions: gcloud beta functions deploy ocr-extract --trigger-bucket [YOUR_IMAGE_BUCKET_NAME] --entry-point processImage gcloud beta functions deploy ocr-translate --trigger-topic [YOUR_TRANSLATE_TOPIC_NAME] --entry-point translateText gcloud beta functions deploy ocr-save --trigger-topic [YOUR_RESULT_TOPIC_NAME] --entry-point saveResult I just wish to detect text and save the text but I could not remove the translation portion of the code below: /** * Detects the text in an image using the Google Vision API. * * @param {string} bucketName Cloud Storage bucket name. * @param {string} filename Cloud Storage file name. * @returns {Promise} */ function detectText...