Path: blob/master/modules/stitching/test/ocl/test_warpers.cpp
16348 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.13// Third party copyrights are property of their respective owners.14//15// Redistribution and use in source and binary forms, with or without modification,16// are permitted provided that the following conditions are met:17//18// * Redistribution's of source code must retain the above copyright notice,19// this list of conditions and the following disclaimer.20//21// * Redistribution's in binary form must reproduce the above copyright notice,22// this list of conditions and the following disclaimer in the documentation23// and/or other materials provided with the distribution.24//25// * The name of the copyright holders may not be used to endorse or promote products26// derived from this software without specific prior written permission.27//28// This software is provided by the copyright holders and contributors "as is" and29// any express or implied warranties, including, but not limited to, the implied30// warranties of merchantability and fitness for a particular purpose are disclaimed.31// In no event shall the OpenCV Foundation or contributors be liable for any direct,32// indirect, incidental, special, exemplary, or consequential damages33// (including, but not limited to, procurement of substitute goods or services;34// loss of use, data, or profits; or business interruption) however caused35// and on any theory of liability, whether in contract, strict liability,36// or tort (including negligence or otherwise) arising in any way out of37// the use of this software, even if advised of the possibility of such damage.38//39//M*/4041#include "../test_precomp.hpp"42#include "opencv2/ts/ocl_test.hpp"43#include "opencv2/stitching/warpers.hpp"4445#ifdef HAVE_OPENCL4647namespace opencv_test {48namespace ocl {4950struct WarperTestBase :51public Test, public TestUtils52{53Mat src, dst, xmap, ymap;54UMat usrc, udst, uxmap, uymap;55Mat K, R;5657void generateTestData()58{59Size size = randomSize(1, MAX_VALUE);6061src = randomMat(size, CV_32FC1, -500, 500);62src.copyTo(usrc);6364K = Mat::eye(3, 3, CV_32FC1);65float angle = (float)(30.0 * CV_PI / 180.0);66float rotationMatrix[9] = {67(float)cos(angle), (float)sin(angle), 0,68(float)-sin(angle), (float)cos(angle), 0,690, 0, 170};71Mat(3, 3, CV_32FC1, rotationMatrix).copyTo(R);72}7374void Near(double threshold = 0.)75{76EXPECT_MAT_NEAR(xmap, uxmap, threshold);77EXPECT_MAT_NEAR(ymap, uymap, threshold);78EXPECT_MAT_NEAR(dst, udst, threshold);79}80};8182typedef WarperTestBase SphericalWarperTest;8384OCL_TEST_F(SphericalWarperTest, Mat)85{86for (int j = 0; j < test_loop_times; j++)87{88generateTestData();8990Ptr<WarperCreator> creator = makePtr<SphericalWarper>();91Ptr<detail::RotationWarper> warper = creator->create(2.0);9293OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));94OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));9596OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));97OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));9899Near(1e-4);100}101}102103typedef WarperTestBase CylindricalWarperTest;104105OCL_TEST_F(CylindricalWarperTest, Mat)106{107for (int j = 0; j < test_loop_times; j++)108{109generateTestData();110111Ptr<WarperCreator> creator = makePtr<CylindricalWarper>();112Ptr<detail::RotationWarper> warper = creator->create(2.0);113114OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));115OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));116117OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));118OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));119120Near(1e-4);121}122}123124typedef WarperTestBase PlaneWarperTest;125126OCL_TEST_F(PlaneWarperTest, Mat)127{128for (int j = 0; j < test_loop_times; j++)129{130generateTestData();131132Ptr<WarperCreator> creator = makePtr<PlaneWarper>();133Ptr<detail::RotationWarper> warper = creator->create(2.0);134135OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));136OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));137138OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));139OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));140141Near(1.5e-4);142}143}144145typedef WarperTestBase AffineWarperTest;146147OCL_TEST_F(AffineWarperTest, Mat)148{149for (int j = 0; j < test_loop_times; j++)150{151generateTestData();152153Ptr<WarperCreator> creator = makePtr<AffineWarper>();154Ptr<detail::RotationWarper> warper = creator->create(1.0);155156OCL_OFF(warper->buildMaps(src.size(), K, R, xmap, ymap));157OCL_ON(warper->buildMaps(usrc.size(), K, R, uxmap, uymap));158159OCL_OFF(warper->warp(src, K, R, INTER_LINEAR, BORDER_REPLICATE, dst));160OCL_ON(warper->warp(usrc, K, R, INTER_LINEAR, BORDER_REPLICATE, udst));161162Near(1.5e-4);163}164}165166} } // namespace opencv_test::ocl167168#endif // HAVE_OPENCL169170171