2011-06-29 12:14:16 +02:00
|
|
|
/*M///////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
|
|
|
//
|
|
|
|
// By downloading, copying, installing or using the software you agree to this license.
|
|
|
|
// If you do not agree to this license, do not download, install,
|
|
|
|
// copy or use the software.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Intel License Agreement
|
|
|
|
// For Open Source Computer Vision Library
|
|
|
|
//
|
|
|
|
// Copyright (C) 2000, Intel Corporation, all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
// are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistribution's of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// * Redistribution's in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// * The name of Intel Corporation may not be used to endorse or promote products
|
|
|
|
// derived from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// This software is provided by the copyright holders and contributors "as is" and
|
|
|
|
// any express or implied warranties, including, but not limited to, the implied
|
|
|
|
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
|
|
|
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
|
|
|
// indirect, incidental, special, exemplary, or consequential damages
|
|
|
|
// (including, but not limited to, procurement of substitute goods or services;
|
|
|
|
// loss of use, data, or profits; or business interruption) however caused
|
|
|
|
// and on any theory of liability, whether in contract, strict liability,
|
|
|
|
// or tort (including negligence or otherwise) arising in any way out of
|
|
|
|
// the use of this software, even if advised of the possibility of such damage.
|
|
|
|
//
|
|
|
|
//M*/
|
|
|
|
|
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
|
|
|
using namespace cv::gpu;
|
|
|
|
using namespace cvtest;
|
|
|
|
|
|
|
|
GpuMat loadMat(const Mat& m, bool useRoi)
|
|
|
|
{
|
|
|
|
Size size = m.size();
|
|
|
|
Size size0 = size;
|
|
|
|
|
|
|
|
if (useRoi)
|
|
|
|
{
|
|
|
|
RNG& rng = TS::ptr()->get_rng();
|
|
|
|
|
|
|
|
size0.width += rng.uniform(5, 15);
|
|
|
|
size0.height += rng.uniform(5, 15);
|
|
|
|
}
|
|
|
|
|
|
|
|
GpuMat d_m(size0, m.type());
|
|
|
|
|
|
|
|
if (size0 != size)
|
|
|
|
d_m = d_m(Rect((size0.width - size.width) / 2, (size0.height - size.height) / 2, size.width, size.height));
|
|
|
|
|
|
|
|
d_m.upload(m);
|
|
|
|
|
|
|
|
return d_m;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool supportFeature(const DeviceInfo& info, FeatureSet feature)
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
return TargetArchs::builtWith(feature) && info.supports(feature);
|
2011-06-29 12:14:16 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
const vector<DeviceInfo>& devices()
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
static vector<DeviceInfo> devs;
|
2011-06-29 12:14:16 +02:00
|
|
|
static bool first = true;
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
int deviceCount = getCudaEnabledDeviceCount();
|
2011-06-29 12:14:16 +02:00
|
|
|
|
|
|
|
devs.reserve(deviceCount);
|
|
|
|
|
|
|
|
for (int i = 0; i < deviceCount; ++i)
|
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
DeviceInfo info(i);
|
2011-06-29 12:14:16 +02:00
|
|
|
if (info.isCompatible())
|
|
|
|
devs.push_back(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return devs;
|
|
|
|
}
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
vector<DeviceInfo> devices(FeatureSet feature)
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
const vector<DeviceInfo>& d = devices();
|
2011-06-29 12:14:16 +02:00
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
vector<DeviceInfo> devs_filtered;
|
2011-06-29 12:14:16 +02:00
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
if (TargetArchs::builtWith(feature))
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
|
|
|
devs_filtered.reserve(d.size());
|
|
|
|
|
|
|
|
for (size_t i = 0, size = d.size(); i < size; ++i)
|
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
const DeviceInfo& info = d[i];
|
2011-06-29 12:14:16 +02:00
|
|
|
|
|
|
|
if (info.supports(feature))
|
|
|
|
devs_filtered.push_back(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return devs_filtered;
|
|
|
|
}
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
vector<MatType> types(int depth_start, int depth_end, int cn_start, int cn_end)
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
vector<MatType> v;
|
2011-06-29 12:14:16 +02:00
|
|
|
|
|
|
|
v.reserve((depth_end - depth_start + 1) * (cn_end - cn_start + 1));
|
|
|
|
|
|
|
|
for (int depth = depth_start; depth <= depth_end; ++depth)
|
|
|
|
{
|
|
|
|
for (int cn = cn_start; cn <= cn_end; ++cn)
|
|
|
|
{
|
|
|
|
v.push_back(CV_MAKETYPE(depth, cn));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
const vector<MatType>& all_types()
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
static vector<MatType> v = types(CV_8U, CV_64F, 1, 4);
|
|
|
|
|
2011-06-29 12:14:16 +02:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
Mat readImage(const string& fileName, int flags)
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
return imread(string(cvtest::TS::ptr()->get_data_path()) + fileName, flags);
|
2011-06-29 12:14:16 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
double checkNorm(const Mat& m1, const Mat& m2)
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
return norm(m1, m2, NORM_INF);
|
2011-06-29 12:14:16 +02:00
|
|
|
}
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
double checkSimilarity(const Mat& m1, const Mat& m2)
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
Mat diff;
|
|
|
|
matchTemplate(m1, m2, diff, CV_TM_CCORR_NORMED);
|
2011-06-29 12:14:16 +02:00
|
|
|
return std::abs(diff.at<float>(0, 0) - 1.f);
|
|
|
|
}
|
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os)
|
2011-06-29 12:14:16 +02:00
|
|
|
{
|
2012-01-10 12:11:58 +01:00
|
|
|
(*os) << info.name();
|
|
|
|
}
|
2011-06-29 12:14:16 +02:00
|
|
|
|
2012-01-10 12:11:58 +01:00
|
|
|
void PrintTo(const UseRoi& useRoi, std::ostream* os)
|
|
|
|
{
|
|
|
|
if (useRoi)
|
|
|
|
(*os) << "sub matrix";
|
|
|
|
else
|
|
|
|
(*os) << "whole matrix";
|
2011-06-29 12:14:16 +02:00
|
|
|
}
|