I have this code below, it works on some images for cropping sub-images for every word in the image contains text. Some images raised an issue while cropping them, I could not find the reason and solution for the error, please help.
the error:
SystemError: tile cannot extend outside image
the code:
IMAGE_PATH = '005002006002-1.tiff'
conv = cv2.imread(IMAGE_PATH)
reader = easyocr.Reader(['ar'],gpu=True)
result = reader.readtext(conv)
img = cv2.imread(IMAGE_PATH)
Image_number = 1000
copy = img.copy()
for i in result:
top_left = tuple([int(val) for val in i[0][0]])
bottom_right = tuple([int(val) for val in i[0][2]])
img = cv2.rectangle(copy, top_left, bottom_right, (36,255,12), 3)
cropped_img = img[top_left[1]:bottom_right[1], top_left[0]:bottom_right[0], :]
plt.imsave('newsub/005002006002-1_{}.tiff'.format(Image_number), cropped_img )
Image_number += 1
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…