mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-19 02:16:34 +08:00

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
81 lines
2.1 KiB
C++
81 lines
2.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 DCTExtTest : public ::testing::TestWithParam<cv::Size> {};
|
|
|
|
TEST_P(DCTExtTest, forward)
|
|
{
|
|
Size size = GetParam();
|
|
|
|
RNG& rng = cv::theRNG();
|
|
Mat src(size, CV_8UC1);
|
|
cvtest::randUni(rng, src, Scalar::all(0), Scalar::all(255));
|
|
Mat srcFloat;
|
|
src.convertTo(srcFloat, CV_32F);
|
|
|
|
Mat dst, ref;
|
|
cv::fastcv::DCT(src, dst);
|
|
|
|
cv::dct(srcFloat, ref);
|
|
|
|
Mat dstFloat;
|
|
ref.convertTo(dstFloat, CV_32F);
|
|
|
|
double normInf = cvtest::norm(dstFloat, ref, cv::NORM_INF);
|
|
double normL2 = cvtest::norm(dstFloat, ref, cv::NORM_L2) / dst.size().area();
|
|
|
|
if (cvtest::debugLevel > 0)
|
|
{
|
|
std::cout << "dst:" << std::endl << dst << std::endl;
|
|
std::cout << "ref:" << std::endl << ref << std::endl;
|
|
}
|
|
|
|
EXPECT_EQ(normInf, 0);
|
|
EXPECT_EQ(normL2, 0);
|
|
}
|
|
|
|
TEST_P(DCTExtTest, inverse)
|
|
{
|
|
Size size = GetParam();
|
|
|
|
RNG& rng = cv::theRNG();
|
|
Mat src(size, CV_8UC1);
|
|
cvtest::randUni(rng, src, Scalar::all(0), Scalar::all(256));
|
|
|
|
Mat srcFloat;
|
|
src.convertTo(srcFloat, CV_32F);
|
|
|
|
Mat fwd, back;
|
|
cv::fastcv::DCT(src, fwd);
|
|
cv::fastcv::IDCT(fwd, back);
|
|
Mat backFloat;
|
|
back.convertTo(backFloat, CV_32F);
|
|
|
|
Mat fwdRef, backRef;
|
|
cv::dct(srcFloat, fwdRef);
|
|
cv::idct(fwdRef, backRef);
|
|
|
|
double normInf = cvtest::norm(backFloat, backRef, cv::NORM_INF);
|
|
double normL2 = cvtest::norm(backFloat, backRef, cv::NORM_L2) / src.size().area();
|
|
|
|
if (cvtest::debugLevel > 0)
|
|
{
|
|
std::cout << "src:" << std::endl << src << std::endl;
|
|
std::cout << "back:" << std::endl << back << std::endl;
|
|
std::cout << "backRef:" << std::endl << backRef << std::endl;
|
|
}
|
|
|
|
EXPECT_LE(normInf, 7.00005);
|
|
EXPECT_LT(normL2, 0.13);
|
|
}
|
|
|
|
INSTANTIATE_TEST_CASE_P(FastCV_Extension, DCTExtTest, ::testing::Values(Size(8, 8), Size(128, 128), Size(32, 256), Size(512, 512)));
|
|
|
|
}} // namespaces opencv_test, ::
|