OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Read Image from firestore document in google cloud function (python)

  • Thread starter Thread starter mcpj
  • Start date Start date
M

mcpj

Guest
I am creating a Google Cloud Function, using Python, to perform some OCR on an image uploaded by a user into a firestore collection (using flutterflow app). The text detected is then appended to the output_ocr field of the firestore document.

My code is as follow:

Code:
from google.cloud import firestore
from easyocr import Reader
import cv2


def entrypoint(event, context):
    """Triggered by a change to a Firestore document.
    Args:
         event (dict): Event payload.
         context (google.cloud.functions.Context): Metadata for the event.
    """
    db = firestore.Client()
    resource_string = context.resource
    document_path = resource_string.split('/documents/')[1]
    document_reference = db.document(document_path)

    image = str(event['value']['fields']['image']['stringValue'])
    reader = Reader(['en'])  
    img = cv2.imread(image)
    results = reader.readtext(img)
    text = ' '
    for result in results:
         text += ' '+result[1]
    document_reference.update({'output_ocr':text})

But I get the following error:

raise ValueError('Invalid input type. Supporting format = string(file path or url), bytes, numpy array')

Maybe there is a different way to access an image stored in firestore?
<p>I am creating a Google Cloud Function, using Python, to perform some OCR on an image uploaded by a user into a firestore collection (using flutterflow app). The text detected is then appended to the output_ocr field of the firestore document.</p>
<p>My code is as follow:</p>
<pre><code>from google.cloud import firestore
from easyocr import Reader
import cv2


def entrypoint(event, context):
"""Triggered by a change to a Firestore document.
Args:
event (dict): Event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
db = firestore.Client()
resource_string = context.resource
document_path = resource_string.split('/documents/')[1]
document_reference = db.document(document_path)

image = str(event['value']['fields']['image']['stringValue'])
reader = Reader(['en'])
img = cv2.imread(image)
results = reader.readtext(img)
text = ' '
for result in results:
text += ' '+result[1]
document_reference.update({'output_ocr':text})

</code></pre>
<p>But I get the following error:</p>
<blockquote>
<p>raise ValueError('Invalid input type. Supporting format = string(file path or url), bytes, numpy array')</p>
</blockquote>
<p>Maybe there is a different way to access an image stored in firestore?</p>
 

Latest posts

Top