1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-18 08:44:11 +08:00
Files
opencv_contrib/modules/fastcv/test/test_remap.cpp
quic-xuezha 67815e94c8 Merge pull request #3844 from CodeLinaro:xuezha_2ndPost
FastCV Extension code for OpenCV 2ndpost-1 #3844

Depends on: [opencv/opencv#26617](https://github.com/opencv/opencv/pull/26617)
Requires binary from [opencv/opencv_3rdparty#90](https://github.com/opencv/opencv_3rdparty/pull/90)

### 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
- [ ] There is a reference to the original bug report and related work
- [ ] 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
2024-12-20 18:13:09 +03:00

131 lines
4.0 KiB
C++

/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "test_precomp.hpp"
namespace opencv_test { namespace {
class RemapTest : public ::testing::TestWithParam<tuple<int, int, Size>> {
protected:
void SetUp() override {
// Generate random source data
Size size = get<2>(GetParam());
src = Mat(size, get<0>(GetParam()));
randu(src, Scalar::all(0), Scalar::all(255)); // Fill with random values
ASSERT_FALSE(src.empty()) << "Unable to generate the image!";
// Create map matrices
map_x.create(src.size(), CV_32FC1);
map_y.create(src.size(), CV_32FC1);
// Initialize the map matrices
for (int i = 0; i < src.rows; i++) {
for (int j = 0; j < src.cols; j++) {
map_x.at<float>(i, j) = static_cast<float>(src.cols - j); //Flips the image horizonally
map_y.at<float>(i, j) = static_cast<float>(i); //Keep y coordinate unchanged
}
}
}
Mat src, map_x, map_y, dst;
};
class RemapTestRGBA : public ::testing::TestWithParam<tuple<int, int, Size>> {
protected:
void SetUp() override {
// Generate random source data
Size size = get<2>(GetParam());
src = Mat(size, get<0>(GetParam()));
randu(src, Scalar::all(0), Scalar::all(255)); // Fill with random values
ASSERT_FALSE(src.empty()) << "Unable to generate the image!";
// Create map matrices
map_x.create(src.size(), CV_32FC1);
map_y.create(src.size(), CV_32FC1);
// Initialize the map matrices
for (int i = 0; i < src.rows; i++) {
for (int j = 0; j < src.cols; j++) {
map_x.at<float>(i, j) = static_cast<float>(src.cols - j); //Flips the image horizonally
map_y.at<float>(i, j) = static_cast<float>(i); //Keep y coordinate unchanged
}
}
}
Mat src, map_x, map_y, dst;
};
TEST_P(RemapTest, accuracy)
{
int type = get<0>(GetParam());
int interpolation = get<1>(GetParam());
// Convert source image to the specified type
Mat src_converted;
src.convertTo(src_converted, type);
cv::fastcv::remap(src_converted, dst, map_x, map_y, interpolation);
// Check if the remapped image is not empty
ASSERT_FALSE(dst.empty()) << "Remapped image is empty!";
cv::Mat remapOpenCV;
cv::remap(src_converted, remapOpenCV, map_x, map_y, interpolation);
// Calculate the maximum difference
double maxVal = cv::norm(dst, remapOpenCV, cv::NORM_INF);
// Assert if the difference is acceptable (max difference should be less than 10)
CV_Assert(maxVal < 10 && "Difference between images is too high!");
}
TEST_P(RemapTestRGBA, accuracy)
{
int type = get<0>(GetParam());
int interpolation = get<1>(GetParam());
// Convert source image to the specified type
Mat src_converted;
src.convertTo(src_converted, type);
cv::fastcv::remapRGBA(src_converted, dst, map_x, map_y, interpolation);
// Check if the remapped image is not empty
ASSERT_FALSE(dst.empty()) << "Remapped image is empty!";
cv::Mat remapOpenCV;
cv::remap(src_converted, remapOpenCV, map_x, map_y, interpolation);
// Calculate the maximum difference
double maxVal = cv::norm(dst, remapOpenCV, cv::NORM_INF);
// Assert if the difference is acceptable (max difference should be less than 10)
CV_Assert(maxVal < 10 && "Difference between images is too high!");
}
INSTANTIATE_TEST_CASE_P(
RemapTests,
RemapTest,
::testing::Combine(
::testing::Values(CV_8UC1),
::testing::Values(INTER_LINEAR, INTER_NEAREST),
::testing::Values(Size(640, 480), Size(1280, 720), Size(1920, 1080))
)
);
INSTANTIATE_TEST_CASE_P(
RemapTests,
RemapTestRGBA,
::testing::Combine(
::testing::Values(CV_8UC4),
::testing::Values(INTER_LINEAR, INTER_NEAREST),
::testing::Values(Size(640, 480), Size(1280, 720), Size(1920, 1080))
)
);
}} // namespaces opencv_test, ::