mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #24569 from Abdurrahheem:ash/padding_value_fix
Add support for custom padding in DNN preprocessing #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 commit is contained in:
committed by
GitHub
parent
e9f35610a5
commit
5278560252
@@ -93,6 +93,39 @@ TEST(blobFromImageWithParams_4ch, NHWC_scalar_scale)
|
||||
}
|
||||
}
|
||||
|
||||
TEST(blobFromImageWithParams_CustomPadding, letter_box)
|
||||
{
|
||||
Mat img(40, 20, CV_8UC4, Scalar(0, 1, 2, 3));
|
||||
|
||||
// Custom padding value that you have added
|
||||
Scalar customPaddingValue(5, 6, 7, 8); // Example padding value
|
||||
|
||||
Size targetSize(20, 20);
|
||||
|
||||
Mat targetImg = img.clone();
|
||||
|
||||
cv::copyMakeBorder(
|
||||
targetImg, targetImg, 0, 0,
|
||||
targetSize.width / 2,
|
||||
targetSize.width / 2,
|
||||
BORDER_CONSTANT,
|
||||
customPaddingValue);
|
||||
|
||||
// Set up Image2BlobParams with your new functionality
|
||||
Image2BlobParams param;
|
||||
param.size = targetSize;
|
||||
param.paddingmode = DNN_PMODE_LETTERBOX;
|
||||
param.borderValue = customPaddingValue; // Use your new feature here
|
||||
|
||||
// Create blob with custom padding
|
||||
Mat blob = dnn::blobFromImageWithParams(img, param);
|
||||
|
||||
// Create target blob for comparison
|
||||
Mat targetBlob = dnn::blobFromImage(targetImg, 1.0, targetSize);
|
||||
|
||||
EXPECT_EQ(0, cvtest::norm(targetBlob, blob, NORM_INF));
|
||||
}
|
||||
|
||||
TEST(blobFromImageWithParams_4ch, letter_box)
|
||||
{
|
||||
Mat img(40, 20, CV_8UC4, cv::Scalar(0,1,2,3));
|
||||
|
||||
Reference in New Issue
Block a user