Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

python - SystemError on cropping image by bounding box

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...