You can use the opencv-python
library:
import cv2
# Reading the file
with open("filename.txt") as iostream:
content = iostream.read()
# Visualizing the data
color = (0, 0, 255) # RED
for line in content.split("\n"):
image_path, xmin, ymin, xmax, ymax = line.split(",")
image = cv2.imread(image_path)
pt1 = (int(xmin), int(ymin))
pt2 = (int(xmax), int(ymax))
cv2.rectangle(image, pt1, pt2, color)
cv2.imshow("Visualization bounding box", image)
cv2.waitKey()
This code will show each image, with a red rectangle to display the bounding box. If you press any key, it will switch to the next one.
If you want to save the cropped images, you can use something like this:
outfile = image_path[:-4] + "_bbox.jpg"
outimage = image[int(ymin):int(ymax), int(xmin):int(xmax)]
cv2.imwrite(outfile, outimage)