supervision
supervision copied to clipboard
Letterbox of images
Search before asking
- [X] I have searched the Supervision issues and found no similar feature requests.
Description
It would be great to have a feature which resize images as per letterbox concept i.e. resize based on maximum size and adding padding to an image. This is very helpful resize method to increase result quality.
Use case
- Best method for preprocessing image before detector, segmentation models.
Additional
def letterbox(im, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, stride=32) -> np.ndarray:
use case:
import supervision as sv
import cv2
image = cv2.imread(...)
image = sv.letterbox(image)
detection_result = detector(image)
Are you willing to submit a PR?
- [ ] Yes I'd like to help by submitting a PR!
Hi @hardikdava 👋🏻 Yup! That's an excellent idea. But then your detection_result is in the context of letterbox so we would need to have a utility capable of reversing this process.
Hi @SkalskiP 👋 , you are absolutely correct.
@hardikdava, what is the meaning of all of those arguments? Is that function definition copied from YOLOv8?
@hardikdava, what is the meaning of all of those arguments? Is that function definition copied from YOLOv8?
Yeah, for a quick info. But we can modify them and use only needed.
We probably should if we don't want licensing issues.
Hey @SkalskiP how are you doing on this? If I'm not mistaken this is the same as used in DETR transformation and we could copy it from the transformers library. Let me know if you have the bandwidth to take care of this issue otherwise I'd love to help out
This issue was implemented via https://github.com/roboflow/supervision/pull/1028. sv.letterbox_image will be released in supervision-0.20.0.