1793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler/*M/////////////////////////////////////////////////////////////////////////////////////// 2793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 3793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 5793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// By downloading, copying, installing or using the software you agree to this license. 6793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// If you do not agree to this license, do not download, install, 7793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// copy or use the software. 8793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 9793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 10793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// License Agreement 11793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// For Open Source Computer Vision Library 12793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 13793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Third party copyrights are property of their respective owners. 16793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 17793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Redistribution and use in source and binary forms, with or without modification, 18793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// are permitted provided that the following conditions are met: 19793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 20793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Redistribution's of source code must retain the above copyright notice, 21793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// this list of conditions and the following disclaimer. 22793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 23793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * Redistribution's in binary form must reproduce the above copyright notice, 24793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// this list of conditions and the following disclaimer in the documentation 25793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and/or other materials provided with the distribution. 26793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 27793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// * The name of the copyright holders may not be used to endorse or promote products 28793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// derived from this software without specific prior written permission. 29793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 30793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// This software is provided by the copyright holders and contributors "as is" and 31793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// any express or implied warranties, including, but not limited to, the implied 32793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// warranties of merchantability and fitness for a particular purpose are disclaimed. 33793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// In no event shall the Intel Corporation or contributors be liable for any direct, 34793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// indirect, incidental, special, exemplary, or consequential damages 35793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// (including, but not limited to, procurement of substitute goods or services; 36793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// loss of use, data, or profits; or business interruption) however caused 37793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// and on any theory of liability, whether in contract, strict liability, 38793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// or tort (including negligence or otherwise) arising in any way out of 39793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// the use of this software, even if advised of the possibility of such damage. 40793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// 41793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//M*/ 42793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 43793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#include "test_precomp.hpp" 44793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 45793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#ifdef HAVE_CUDA 46793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 47793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslerusing namespace cvtest; 48793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 49793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler//////////////////////////////////////////////////////////////////////////// 50793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler// Blend 51793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 52793ee12c6df9cad3806238d32528c49a3ff9331dNoah Preslernamespace 53793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 54793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler template <typename T> 55793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler void blendLinearGold(const cv::Mat& img1, const cv::Mat& img2, const cv::Mat& weights1, const cv::Mat& weights2, cv::Mat& result_gold) 56793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 57793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler result_gold.create(img1.size(), img1.type()); 58793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 59793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int cn = img1.channels(); 60793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 61793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler for (int y = 0; y < img1.rows; ++y) 62793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 63793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const float* weights1_row = weights1.ptr<float>(y); 64793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const float* weights2_row = weights2.ptr<float>(y); 65793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const T* img1_row = img1.ptr<T>(y); 66793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler const T* img2_row = img2.ptr<T>(y); 67793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler T* result_gold_row = result_gold.ptr<T>(y); 68793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 69793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler for (int x = 0; x < img1.cols * cn; ++x) 70793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 71793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float w1 = weights1_row[x / cn]; 72793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler float w2 = weights2_row[x / cn]; 73793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler result_gold_row[x] = static_cast<T>((img1_row[x] * w1 + img2_row[x] * w2) / (w1 + w2 + 1e-5f)); 74793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 75793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 76793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 77793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 78793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 79793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerPARAM_TEST_CASE(Blend, cv::cuda::DeviceInfo, cv::Size, MatType, UseRoi) 80793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 81793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::cuda::DeviceInfo devInfo; 82793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::Size size; 83793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int type; 84793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler bool useRoi; 85793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 86793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler virtual void SetUp() 87793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler { 88793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler devInfo = GET_PARAM(0); 89793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler size = GET_PARAM(1); 90793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler type = GET_PARAM(2); 91793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler useRoi = GET_PARAM(3); 92793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 93793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::cuda::setDevice(devInfo.deviceID()); 94793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler } 95793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler}; 96793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 97793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerCUDA_TEST_P(Blend, Accuracy) 98793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler{ 99793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler int depth = CV_MAT_DEPTH(type); 100793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 101793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::Mat img1 = randomMat(size, type, 0.0, depth == CV_8U ? 255.0 : 1.0); 102793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::Mat img2 = randomMat(size, type, 0.0, depth == CV_8U ? 255.0 : 1.0); 103793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::Mat weights1 = randomMat(size, CV_32F, 0, 1); 104793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::Mat weights2 = randomMat(size, CV_32F, 0, 1); 105793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 106793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::cuda::GpuMat result; 107793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::cuda::blendLinear(loadMat(img1, useRoi), loadMat(img2, useRoi), loadMat(weights1, useRoi), loadMat(weights2, useRoi), result); 108793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 109793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler cv::Mat result_gold; 110793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler if (depth == CV_8U) 111793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler blendLinearGold<uchar>(img1, img2, weights1, weights2, result_gold); 112793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler else 113793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler blendLinearGold<float>(img1, img2, weights1, weights2, result_gold); 114793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 115793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler EXPECT_MAT_NEAR(result_gold, result, CV_MAT_DEPTH(type) == CV_8U ? 1.0 : 1e-5); 116793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler} 117793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 118793ee12c6df9cad3806238d32528c49a3ff9331dNoah PreslerINSTANTIATE_TEST_CASE_P(CUDA_ImgProc, Blend, testing::Combine( 119793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler ALL_DEVICES, 120793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler DIFFERENT_SIZES, 121793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4)), 122793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler WHOLE_SUBMAT)); 123793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler 124793ee12c6df9cad3806238d32528c49a3ff9331dNoah Presler#endif // HAVE_CUDA 125