Here's a receipt image that I've got and I've plotted it using matplotlib,
# x1, y1, x2, y2, x3, y3, x4, y4
bbox_coords = [[650, 850], [1040, 850], [1040, 930], [650, 930]]
image = cv2.imread(IMG_FILE)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
fig, ax = plt.subplots(figsize=(20, 20))
ax.imshow(gray, cmap='Greys_r');
rect = Polygon(bbox_coords, fill=False, linewidth=1, edgecolor='r')
ax.add_patch(rect)
plt.show()
print(gray.shape)
(4376, 2885)
Then, I've cropped the original gray image and plotted it again with same bounding box coordinates and here's the result,
# cropped the original image
gray_new = gray[25:4314, 147:2880]
fig, ax = plt.subplots(figsize=(20, 20))
ax.imshow(gray_new, cmap='Greys_r');
rect = Polygon(bbox_coords, fill=False, linewidth=1, edgecolor='r')
ax.add_patch(rect)
plt.show()
print(gray_new.shape)
(4289, 2733)
So, I'm looking for a way to make bounding box to fit the cropped image. I couldn't figure out how I can achieve it.
Edit:
Here's an another image if you want to replicate the question, receipt-2
and these are the b-box coordinates for the image [1638,1462,2974,1462,2974,1549,1638,1549]
.
X
values. Similar for top crop andY
values. – Meteor25:4314
so what about 4314 on the right side? – Occupation