1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 15:23:05 +04:00

Merge pull request #23894 from kallaballa:blobFromImagesWithParams

Pertaining Issue: https://github.com/opencv/opencv/issues/5697

### 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
- [x] 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:
Amir Hassan
2023-10-20 13:27:40 +02:00
committed by GitHub
parent d142a796d8
commit c2f909fc86
2 changed files with 155 additions and 36 deletions
+15 -8
View File
@@ -102,12 +102,21 @@ public:
return 0;
}
CV_CheckEQ(input_image.size(), Size(inputW, inputH), "Size does not match. Call setInputSize(size) if input size does not match the preset size");
// Pad input_image with divisor 32
Mat pad_image = padWithDivisor(input_image);
// Build blob from input image
Mat input_blob = dnn::blobFromImage(pad_image);
Mat input_blob;
if(input_image.kind() == _InputArray::UMAT) {
// Pad input_image with divisor 32
UMat pad_image;
padWithDivisor(input_image, pad_image);
// Build blob from input image
input_blob = dnn::blobFromImage(pad_image);
} else {
// Pad input_image with divisor 32
Mat pad_image;
padWithDivisor(input_image, pad_image);
// Build blob from input image
input_blob = dnn::blobFromImage(pad_image);
}
// Forward
std::vector<String> output_names = { "cls_8", "cls_16", "cls_32", "obj_8", "obj_16", "obj_32", "bbox_8", "bbox_16", "bbox_32", "kps_8", "kps_16", "kps_32" };
std::vector<Mat> output_blobs;
@@ -217,13 +226,11 @@ private:
}
}
Mat padWithDivisor(InputArray& input_image)
void padWithDivisor(InputArray input_image, OutputArray pad_image)
{
int bottom = padH - inputH;
int right = padW - inputW;
Mat pad_image;
copyMakeBorder(input_image, pad_image, 0, bottom, 0, right, BORDER_CONSTANT, 0);
return pad_image;
}
private:
dnn::Net net;