Files
Andrei Fedorov 96ec0c97df Merge pull request #29922 from andreyfe1:extend_perf_core
Extend core performance tests - #29922

Added more cases for performance tests. It's a part of a bigger PR https://github.com/opencv/opencv/pull/29631
execution time increased by <18% per my measurements.
Duplication of https://github.com/opencv/opencv/pull/29900, but from a different fork.
`opencv_extra` PR is https://github.com/opencv/opencv_extra/pull/1410

Following was added:

| File | Test | Added |
|------|------|-------|
| `perf_arithm.cpp` | `BinaryOpTest.*` (add/subtract/multiply/absdiff/min/max/transpose2d) | types `CV_16UC1`, `CV_64FC1` |
| `perf_compare.cpp` | `compareScalar` | types `CV_16UC1`, `CV_16SC1` |
| `perf_dot.cpp` | `dot` | type `CV_64FC1` |
| `perf_flip.cpp` | `flip` (`FLIP_TYPES`) | types `CV_32FC3`, `CV_32FC4` |
| `perf_mat.cpp` | `Mat_CopyToWithMask` | types `CV_32FC3` |
| `perf_mat.cpp` | `Mat_SetToWithMask` | types `CV_8UC3, CV_8UC4, CV_16UC3, CV_16UC4, CV_32FC3, CV_32FC4` |
| `perf_norm.cpp` | `norm` | norm type `NORM_L2SQR` |
| `perf_norm.cpp` | `norm_mask` | types `CV_8UC3`, `CV_16UC3`, `CV_32FC3`; norm type `NORM_L2SQR` |
| `perf_norm.cpp` | `norm2` | norm types `NORM_L2SQR`, `NORM_RELATIVE+NORM_L2SQR` |
| `perf_norm.cpp` | `norm2_mask` | types `CV_8UC3`, `CV_16UC3`, `CV_32FC3`; norm types `NORM_L2SQR`, `NORM_RELATIVE\|NORM_L2SQR` |
| `perf_sort.cpp` | `sort`, `sorIdx` (`TYPICAL_MAT_TYPES_SORT`) | types `CV_16SC1`, `CV_32SC1`, `CV_64FC1` |
| `perf_stat.cpp` | `sum`, `mean` | types widened `{8UC1,8UC4,32FC1}` → `8U/16U/16S/32F × C1/C3/C4` |
| `perf_stat.cpp` | `mean_mask`, `meanStdDev`, `meanStdDev_mask` | types widened `{8UC1,8UC4,32FC1}` → `8U/16U/32F × C1/C3/C4` |

### 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
- [ ] 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-09-15 08:47:00 +03:00

131 lines
3.4 KiB
C++

#include "perf_precomp.hpp"
namespace opencv_test
{
using namespace perf;
// Masked variants: 8U/16U/32F x C1/C3/C4.
#define TYPICAL_MAT_TYPES_STAT_MASK CV_8UC1, CV_8UC3, CV_8UC4, CV_16UC1, CV_16UC3, CV_16UC4, CV_32FC1, CV_32FC3, CV_32FC4
// sum/mean/meanStdDev additionally cover 16S.
#define TYPICAL_MAT_TYPES_STAT TYPICAL_MAT_TYPES_STAT_MASK, CV_16SC1, CV_16SC3, CV_16SC4
PERF_TEST_P(Size_MatType, sum, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ),
testing::Values( TYPICAL_MAT_TYPES_STAT ) ))
{
Size sz = get<0>(GetParam());
int type = get<1>(GetParam());
Mat arr(sz, type);
Scalar s;
declare.in(arr, WARMUP_RNG).out(s);
TEST_CYCLE() s = sum(arr);
SANITY_CHECK(s, 1e-6, ERROR_RELATIVE);
}
PERF_TEST_P(Size_MatType, mean, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ),
testing::Values( TYPICAL_MAT_TYPES_STAT ) ))
{
Size sz = get<0>(GetParam());
int type = get<1>(GetParam());
Mat src(sz, type);
Scalar s;
declare.in(src, WARMUP_RNG).out(s);
TEST_CYCLE() s = cv::mean(src);
SANITY_CHECK(s, 1e-5);
}
PERF_TEST_P(Size_MatType, mean_mask, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ),
testing::Values( TYPICAL_MAT_TYPES_STAT_MASK ) ))
{
Size sz = get<0>(GetParam());
int type = get<1>(GetParam());
Mat src(sz, type);
Mat mask = Mat::ones(src.size(), CV_8U);
Scalar s;
declare.in(src, WARMUP_RNG).in(mask).out(s);
TEST_CYCLE() s = cv::mean(src, mask);
SANITY_CHECK(s, 5e-5);
}
PERF_TEST_P(Size_MatType, meanStdDev, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ),
testing::Values( TYPICAL_MAT_TYPES_STAT_MASK ) ))
{
Size sz = get<0>(GetParam());
int matType = get<1>(GetParam());
Mat src(sz, matType);
Scalar mean;
Scalar dev;
declare.in(src, WARMUP_RNG).out(mean, dev);
TEST_CYCLE() meanStdDev(src, mean, dev);
SANITY_CHECK(mean, 1e-5, ERROR_RELATIVE);
SANITY_CHECK(dev, 1e-5, ERROR_RELATIVE);
}
PERF_TEST_P(Size_MatType, meanStdDev_mask, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ),
testing::Values( TYPICAL_MAT_TYPES_STAT_MASK ) ))
{
Size sz = get<0>(GetParam());
int matType = get<1>(GetParam());
Mat src(sz, matType);
Mat mask = Mat::ones(sz, CV_8U);
Scalar mean;
Scalar dev;
declare.in(src, WARMUP_RNG).in(mask).out(mean, dev);
TEST_CYCLE() meanStdDev(src, mean, dev, mask);
SANITY_CHECK(mean, 1e-5);
SANITY_CHECK(dev, 1e-5);
}
PERF_TEST_P(Size_MatType, countNonZero, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ), testing::Values( CV_8UC1, CV_8SC1, CV_16UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_64FC1 ) ))
{
Size sz = get<0>(GetParam());
int matType = get<1>(GetParam());
Mat src(sz, matType);
int cnt = 0;
declare.in(src, WARMUP_RNG);
int runs = (sz.width <= 640) ? 8 : 1;
TEST_CYCLE_MULTIRUN(runs) cnt = countNonZero(src);
SANITY_CHECK(cnt);
}
PERF_TEST_P(Size_MatType, hasNonZero, testing::Combine( testing::Values( TYPICAL_MAT_SIZES ), testing::Values( CV_8UC1, CV_8SC1, CV_16UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_64FC1 ) ))
{
Size sz = get<0>(GetParam());
int matType = get<1>(GetParam());
Mat src(sz, matType);
/*bool hnz = false;*/
declare.in(src, WARMUP_RNG);
int runs = (sz.width <= 640) ? 8 : 1;
TEST_CYCLE_MULTIRUN(runs) /*hnz =*/ hasNonZero(src);
SANITY_CHECK_NOTHING();
}
} // namespace