JaidedAI / EasyOCR

Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.
https://www.jaided.ai
Apache License 2.0
24.17k stars 3.14k forks source link

Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU. Illegal instruction #1323

Open luisjose1996 opened 3 days ago

luisjose1996 commented 3 days ago

import easyocr import cv2 import matplotlib.pyplot as plt

Create an EasyOCR reader instance

reader = easyocr.Reader(['en'], gpu=False) # Specify the languages you want to use

Function to extract text from an image

def extract_text_from_image(image_path):

Read the image using OpenCV

image = cv2.imread(image_path)

# Use EasyOCR to extract text
results = reader.readtext(image)

# Extract text and bounding boxes
extracted_text = ""
for (bbox, text, prob) in results:
    extracted_text += f"{text} "
    # Optionally, you can draw bounding boxes on the image
    (top_left, top_right, bottom_right, bottom_left) = bbox
    top_left = tuple(map(int, top_left))
    bottom_right = tuple(map(int, bottom_right))
    cv2.rectangle(image, top_left, bottom_right, (0, 255, 0), 2)

return extracted_text.strip(), image

Example usage

if name == "main": image_path = "1.png" # Replace with your image path text, annotated_image = extract_text_from_image(image_path) print("Extracted Text:", text)

# Display the image with bounding boxes
plt.imshow(cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB))
plt.axis('off')  # Hide axes
plt.show()

In this code, I got an issue like "Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU. Illegal instruction". How should I solve this issue?

romanvelichkin commented 2 days ago

It's not clear what is a problem. Easyocr doesn't scan image, so you don't have image + bbox output? Or image is showed, but you're bothered with a message?

It's a default message if you don't use gpu. You can change gpu=False -> gpu=True to fix it, but you will need GPU for that.