1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-19 11:21:39 +08:00
Files
opencv_contrib/modules/fastcv/test/test_scale.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

104 lines
3.1 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 ResizeBy2Test : public ::testing::TestWithParam<cv::Size> {};
class ResizeBy4Test : public ::testing::TestWithParam<cv::Size> {};
TEST(resizeDownBy2, accuracy)
{
cv::Mat inputImage = cv::imread(cvtest::findDataFile("cv/shared/box_in_scene.png"), cv::IMREAD_GRAYSCALE);
Size dsize;
cv::Mat resized_image;
cv::fastcv::resizeDownBy2(inputImage, resized_image);
EXPECT_FALSE(resized_image.empty());
cv::Mat resizedImageOpenCV;
cv::resize(inputImage, resizedImageOpenCV, cv::Size(inputImage.cols / 2, inputImage.rows / 2), 0, 0, INTER_AREA);
// Calculate the maximum difference
double maxVal = cv::norm(resized_image, resizedImageOpenCV, 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(resizeDownBy4, accuracy)
{
cv::Mat inputImage = cv::imread(cvtest::findDataFile("cv/shared/box_in_scene.png"), cv::IMREAD_GRAYSCALE);
Size dsize;
cv::Mat resized_image;
cv::fastcv::resizeDownBy4(inputImage, resized_image);
EXPECT_FALSE(resized_image.empty());
cv::Mat resizedImageOpenCV;
cv::resize(inputImage, resizedImageOpenCV, cv::Size(inputImage.cols / 4, inputImage.rows / 4), 0, 0, INTER_AREA);
// Calculate the maximum difference
double maxVal = cv::norm(resized_image, resizedImageOpenCV, 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(ResizeBy2Test, ResizeBy2) {
//Size size = get<0>(GetParam());
Size size = GetParam();
cv::Mat inputImage(size, CV_8UC1);
randu(inputImage, Scalar::all(0), Scalar::all(255)); // Fill with random values
Size dsize;
cv::Mat resized_image;
// Resize the image by a factor of 2
cv::fastcv::resizeDownBy2(inputImage, resized_image);
// Check if the output size is correct
EXPECT_EQ(resized_image.size().width, size.width * 0.5);
EXPECT_EQ(resized_image.size().height, size.height * 0.5);
}
TEST_P(ResizeBy4Test, ResizeBy4) {
//Size size = get<0>(GetParam());
Size size = GetParam();
cv::Mat inputImage(size, CV_8UC1);
randu(inputImage, Scalar::all(0), Scalar::all(255)); // Fill with random values
Size dsize;
cv::Mat resized_image;
// Resize the image by a factor of 4
cv::fastcv::resizeDownBy4(inputImage, resized_image);
// Check if the output size is correct
EXPECT_EQ(resized_image.size().width, size.width * 0.25);
EXPECT_EQ(resized_image.size().height, size.height * 0.25);
}
INSTANTIATE_TEST_CASE_P(
ResizeTests,
ResizeBy2Test,
::testing::Values(cv::Size(640, 480), cv::Size(1280, 720), cv::Size(1920, 1080)
));
INSTANTIATE_TEST_CASE_P(
ResizeTests,
ResizeBy4Test,
::testing::Values(cv::Size(640, 480), cv::Size(1280, 720), cv::Size(1920, 1080)
));
}} // namespaces opencv_test, ::