剪切文本边界框并将其保存为主图像的子图像

Cut bounding box of text and save it as sub images of main image

我需要提取文本的边界框并将其保存为主图像的子图像。
我有这段代码用于检测图像上的文本并将其用绿色矩形包围(请看下面的图像示例),我已经完成了这一步但是在第二步中我尝试将每个边界框提取到一个单独的图像中,有什么帮助吗? 我的图像是没有嘈杂背景的扫描文档。

    IMAGE_PATH = 'test1.png'
    reader = easyocr.Reader(['en'])
    result = reader.readtext(IMAGE_PATH)
    result

img = cv2.imread(IMAGE_PATH)
spacer = 100
for detection in result: 
    top_left = tuple([int(val) for val in detection[0][0]])
    bottom_right = tuple([int(val) for val in detection[0][2]])
    text = detection[1]
    font= cv2.FONT_HERSHEY_SIMPLEX
    img = cv2.rectangle(img, top_left, bottom_right, (0,255,0), 2)
    #img = cv2.putText(img,text,(20,spacer), font, 1,(0,255,0),2,cv2.LINE_AA)
    spacer+=3
plt.figure(figsize=(30,30))    
plt.imshow(img)
plt.show

OpenCV 图像是可以轻松切片的 numpy 数组:

cropped_img = img[top_left[1]:bottom_right[1], top_left[0]:bottom_right[0], :] 
plt.imsave('cropped.jpg', cropped_img )