'Cropping an ROI in image

I am trying to crop ROI in an image. I have the bounding box coordinates, but I don't understand how to use it to extract sub-array from the original image Here's a snippet of my code:

    `for j, box in enumerate(draw_boxes):

        cv2.rectangle(orig_image,
                      (int(box[0]), int(box[1])),
                      (int(box[2]), int(box[3])),
                      (0, 0, 255), 2)
        cv2.putText(orig_image, pred_classes[j],
                    (int(box[0]), int(box[1]-5)),
                     cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 0),
                     2, lineType=cv2.LINE_AA)
        print(box[0], box[1], box[2], box[3])
        cropped = orig_image[int(box[0]): int(box[1]), int(box[2]): int(box[3])]
        cv2.imwrite(f"../test_predictions/{image_name}.jpg", orig_image)
        cv2.imshow('Cropped', cropped)
        cv2.imshow('Prediction', orig_image)
        cv2.waitKey()` 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source