MGPSTR

class grid.model.perception.str.mgp_str.MGPSTR(*args, **kwargs)

MGPSTR: Scene Text Recognition Model

This class implements a wrapper for the MGPSTR (Multi-Granularity Prediction for Scene Text Recognition) model, which recognizes text in images.

Credits:

https://huggingface.co/alibaba-damo/mgp-str-base

License:

This code is licensed under the Apache 2.0 License.

__init__()

Initializes the MGPSTR model and processor.

Loads the model and processor from the Hugging Face Hub. The model is loaded onto the GPU if available, otherwise it defaults to the CPU.

Return type:

None

run(image)

Given an image, recognize and return the text in the image.

Parameters:

image (np.ndarray) -- The image as a numpy array.

Returns:

Recognized text from the image.

Return type:

str

Example

>>> mgpstr = MGPSTR()
>>> outputs = mgpstr.run(image)
>>> print(outputs)  # Recognized text from the image.