1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-20 04:25:42 +08:00
Files
opencv_contrib/modules/fastcv/test/test_scale.cpp
sssanjee-quic 2c7591c57f Merge pull request #3824 from CodeLinaro:FastcvHAL_1stPost
Depends on https://github.com/opencv/opencv/pull/26316

### 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-02 10:53:50 +03:00

113 lines
3.3 KiB
C++

/*
* Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "opencv2/ts.hpp"
#include "opencv2/fastcv/scale.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);
cv::Mat diffImage;
cv::absdiff(resized_image, resizedImageOpenCV, diffImage);
// Calculate the maximum difference
double maxVal=0.0;
cv::minMaxLoc(diffImage, nullptr, &maxVal);
// 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);
cv::Mat diffImage;
cv::absdiff(resized_image, resizedImageOpenCV, diffImage);
// Calculate the maximum difference
double maxVal=0.0;
cv::minMaxLoc(diffImage, nullptr, &maxVal);
// 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, 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::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, ::