Reputation: 1663
I have a tensor
of dimension (224, 224, 3)
representing an image. I would like to firstly "crop" this image using bounding box dimensions in the format bndbox = [x1, y1, x2, y2]
and then resize this cropped image back to a dimension of (224, 224, 3)
.
Is there a simple way of doing this with numpy/cv2(OpenCV)?
Upvotes: 0
Views: 1424
Reputation: 3077
Supposing that your tensor supports slicing, simply select the bounding box, then you can resize with cv2.resize
:
cv2.resize(img[y1:y2,x1:x2], (224, 224))
Just note that img
is probably selected in height then in width, while the shape argument for cv2.resize
takes (width, height).
Upvotes: 2