mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge pull request #25984 from fengyuentau:imgproc/warpaffine_opt
imgproc: add optimized warpAffine kernels for 8U/16U/32F + C1/C3/C4 inputs #25984 Merge wtih https://github.com/opencv/opencv_extra/pull/1198. Merge with https://github.com/opencv/opencv_contrib/pull/3787. ### 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:
@@ -748,8 +748,76 @@ struct DefaultRngAuto
|
||||
|
||||
|
||||
// test images generation functions
|
||||
void fillGradient(Mat& img, int delta = 5);
|
||||
void smoothBorder(Mat& img, const Scalar& color, int delta = 3);
|
||||
template<typename T>
|
||||
void fillGradient(Mat& img, int delta = 5)
|
||||
{
|
||||
CV_UNUSED(delta);
|
||||
const int ch = img.channels();
|
||||
|
||||
int r, c, i;
|
||||
for(r=0; r<img.rows; r++)
|
||||
{
|
||||
for(c=0; c<img.cols; c++)
|
||||
{
|
||||
T vals[] = {(T)r, (T)c, (T)(r*c), (T)(r*c/(r+c+1))};
|
||||
T *p = (T*)img.ptr(r, c);
|
||||
for(i=0; i<ch; i++) p[i] = (T)vals[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
template<>
|
||||
void fillGradient<uint8_t>(Mat& img, int delta);
|
||||
|
||||
template<typename T>
|
||||
void smoothBorder(Mat& img, const Scalar& color, int delta = 3)
|
||||
{
|
||||
const int ch = img.channels();
|
||||
CV_Assert(!img.empty() && ch <= 4);
|
||||
|
||||
Scalar s;
|
||||
int n = 100/delta;
|
||||
int nR = std::min(n, (img.rows+1)/2), nC = std::min(n, (img.cols+1)/2);
|
||||
|
||||
int r, c, i;
|
||||
for(r=0; r<nR; r++)
|
||||
{
|
||||
double k1 = r*delta/100., k2 = 1-k1;
|
||||
for(c=0; c<img.cols; c++)
|
||||
{
|
||||
auto *p = img.ptr<T>(r, c);
|
||||
for(i=0; i<ch; i++) s[i] = p[i];
|
||||
s = s * k1 + color * k2;
|
||||
for(i=0; i<ch; i++) p[i] = static_cast<T>((s[i]));
|
||||
}
|
||||
for(c=0; c<img.cols; c++)
|
||||
{
|
||||
auto *p = img.ptr<T>(img.rows-r-1, c);
|
||||
for(i=0; i<ch; i++) s[i] = p[i];
|
||||
s = s * k1 + color * k2;
|
||||
for(i=0; i<ch; i++) p[i] = static_cast<T>((s[i]));
|
||||
}
|
||||
}
|
||||
|
||||
for(r=0; r<img.rows; r++)
|
||||
{
|
||||
for(c=0; c<nC; c++)
|
||||
{
|
||||
double k1 = c*delta/100., k2 = 1-k1;
|
||||
auto *p = img.ptr<T>(r, c);
|
||||
for(i=0; i<ch; i++) s[i] = p[i];
|
||||
s = s * k1 + color * k2;
|
||||
for(i=0; i<ch; i++) p[i] = static_cast<T>((s[i]));
|
||||
}
|
||||
for(c=0; c<n; c++)
|
||||
{
|
||||
double k1 = c*delta/100., k2 = 1-k1;
|
||||
auto *p = img.ptr<T>(r, img.cols-c-1);
|
||||
for(i=0; i<ch; i++) s[i] = p[i];
|
||||
s = s * k1 + color * k2;
|
||||
for(i=0; i<ch; i++) p[i] = static_cast<T>((s[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user