Add support for custom padding in DNN preprocessing#24569
Add support for custom padding in DNN preprocessing#24569asmorkalov merged 6 commits intoopencv:4.xfrom
Conversation
fengyuentau
left a comment
There was a problem hiding this comment.
Does YOLO family use different padding values?
It uses 114. We do not have such support out of the box |
It seems like not a padding but mean value. So after subtraction of mean 114 final padding is zero |
Ok. More questions:
IIRC, the letterbox tranformation pads the image to a certain scale, for example, h:w=1:1; then when it is resized, it does not make distortion on the potential objects. |
Agree I think values are necessary like pytorch https://pytorch.org/docs/stable/generated/torch.nn.functional.pad.html#torch.nn.functional.pad or tensorflow https://www.tensorflow.org/api_docs/python/tf/pad |
Answer to the questions
Regardless what yolo family uses, our |
d85f41d to
dd10bcd
Compare
| cv::copyMakeBorder( | ||
| targetImg, targetImg, 0, 0, | ||
| targetSize.width / 2, | ||
| targetSize.width / 2, |
There was a problem hiding this comment.
targetSize vs borderSize - that is a mess.
Test should not depend on exact values of its input parameters.
| int left = (size.width - rw)/2; | ||
| int right = size.width - left - rw; | ||
| copyMakeBorder(images[i], images[i], top, bottom, left, right, BORDER_CONSTANT); | ||
| copyMakeBorder(images[i], images[i], top, bottom, left, right, BORDER_CONSTANT, param.borderValue); |
There was a problem hiding this comment.
images[i], images[i]
Operation is not in-place.
We should not use the same argument for src and dst - this is anti-pattern and bad practice.
Add support for custom padding in DNN preprocessing opencv#24569 This PR add functionality for specifying value in padding. It is required in many preprocessing pipelines in DNNs such as Yolox object detection model ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Add support for custom padding in DNN preprocessing opencv#24569 This PR add functionality for specifying value in padding. It is required in many preprocessing pipelines in DNNs such as Yolox object detection model ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This PR add functionality for specifying value in padding.
It is required in many preprocessing pipelines in DNNs such as Yolox object detection model
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.