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_warp.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

70 lines
2.3 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 {
typedef testing::TestWithParam<cv::Size> WarpPerspective2Plane;
TEST_P(WarpPerspective2Plane, accuracy)
{
cv::Size dstSize = GetParam();
cv::Mat img = imread(cvtest::findDataFile("cv/shared/baboon.png"));
Mat src(img.rows, img.cols, CV_8UC1);
cvtColor(img,src,cv::COLOR_BGR2GRAY);
cv::Mat dst1, dst2, mat, ref1, ref2;
mat.create(3,3,CV_32FC1);
dst1.create(dstSize,CV_8UC1);
dst2.create(dstSize,CV_8UC1);
RNG rng = RNG((uint64)-1);
Point2f s[4], d[4];
s[0] = Point2f(0,0);
d[0] = Point2f(0,0);
s[1] = Point2f(src.cols-1.f,0);
d[1] = Point2f(dst1.cols-1.f,0);
s[2] = Point2f(src.cols-1.f,src.rows-1.f);
d[2] = Point2f(dst1.cols-1.f,dst1.rows-1.f);
s[3] = Point2f(0,src.rows-1.f);
d[3] = Point2f(0,dst1.rows-1.f);
float buffer[16];
Mat tmp( 1, 16, CV_32FC1, buffer );
rng.fill( tmp, 1, Scalar::all(0.), Scalar::all(0.1) );
for(int i = 0; i < 4; i++ )
{
s[i].x += buffer[i*4]*src.cols/2;
s[i].y += buffer[i*4+1]*src.rows/2;
d[i].x += buffer[i*4+2]*dst1.cols/2;
d[i].y += buffer[i*4+3]*dst1.rows/2;
}
cv::getPerspectiveTransform( s, d ).convertTo( mat, mat.depth() );
// Invert the perspective matrix
invert(mat,mat);
cv::fastcv::warpPerspective2Plane(src, src, dst1, dst2, mat, dstSize);
cv::warpPerspective(src,ref1,mat,dstSize,(cv::INTER_LINEAR | cv::WARP_INVERSE_MAP));
cv::warpPerspective(src,ref2,mat,dstSize,(cv::INTER_LINEAR | cv::WARP_INVERSE_MAP));
cv::Mat difference1, difference2, mask1,mask2;
cv::absdiff(dst1, ref1, difference1);
cv::absdiff(dst2, ref2, difference2);
cv::threshold(difference1, mask1, 5, 255, cv::THRESH_BINARY);
cv::threshold(difference2, mask2, 5, 255, cv::THRESH_BINARY);
int num_diff_pixels_1 = cv::countNonZero(mask1);
int num_diff_pixels_2 = cv::countNonZero(mask2);
EXPECT_LT(num_diff_pixels_1, src.size().area()*0.02);
EXPECT_LT(num_diff_pixels_2, src.size().area()*0.02);
}
INSTANTIATE_TEST_CASE_P(FastCV_Extension, WarpPerspective2Plane, Values(perf::szVGA, perf::sz720p, perf::sz1080p));
}
}