0

I tried to use PaddleOCR for rading arabic texts. I followed the instructions given here: https://learnopencv.com/optical-character-recognition-using-paddleocr/

When I switch the language to engl. i get also an error.

here is the code for reading the arabic text:

# Importing required functions for inference and visualization.
from paddleocr import PaddleOCR,draw_ocr
import os
import cv2
import matplotlib.pyplot as plt
%matplotlib inline
import paddle

paddle.utils.run_check()

ocr = PaddleOCR(use_angle_cls=True, lang ='ar')
img_path = r'C:\Users\user\Desktop\Input\example.jpg'
font = './fonts/simfang.ttf'
result = ocr.ocr(img_path)
out_path = r'C:\Users\user\Desktop'

def save_ocr(img_path, out_path, result, font):
    save_path = os.path.join(out_path, img_path.split('/')[-1] + 'output')

    image = cv2.imread(img_path)

    boxes = [line[0] for line in result]
    txts = [line[1][0] for line in result]
    scores = [line[1][1] for line in result]

    im_show = draw_ocr(image, boxes, txts, scores, font_path=font)

    cv2.imwrite(save_path, im_show)

    img = cv2.cvtColor(im_show, cv2.COLOR_BGR2RGB)
    plt.imshow(img)

save_ocr(img_path, out_path, result, font)

But I always get the following error:

IndexError                                Traceback (most recent call last)
Cell In[9], line 1
----> 1 save_ocr(img_path, out_path, result, font)

Cell In[8], line 7, in save_ocr(img_path, out_path, result, font)
      4 image = cv2.imread(img_path)
      6 boxes = [line[0] for line in result]
----> 7 txts = [line[1][0] for line in result]
      8 scores = [line[1][1] for line in result]
     10 im_show = draw_ocr(image, boxes, txts, scores, font_path=font)

Cell In[8], line 7, in <listcomp>(.0)
      4 image = cv2.imread(img_path)
      6 boxes = [line[0] for line in result]
----> 7 txts = [line[1][0] for line in result]
      8 scores = [line[1][1] for line in result]
     10 im_show = draw_ocr(image, boxes, txts, scores, font_path=font)

IndexError: list index out of range

I tried different languages English, Chinese and Arabic but nothing worked here ...

Kassy
  • 1
  • 1

0 Answers0