Commit 6e4eb722 authored by Vladislav Vinogradov's avatar Vladislav Vinogradov

updated gpu performance tests

now it executes only on one device
added posibility to specify device on which tests will be executed
parent ddca4704
This diff is collapsed.
This diff is collapsed.
#include "perf_precomp.hpp"
#ifdef HAVE_CUDA
using namespace std;
using namespace testing;
namespace {
//////////////////////////////////////////////////////////////////////
// SURF
GPU_PERF_TEST_1(SURF, cv::gpu::DeviceInfo)
{
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
DEF_PARAM_TEST_1(Image, string);
cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty());
PERF_TEST_P(Image, Features2D_SURF, Values<string>("gpu/perf/aloe.jpg"))
{
declare.time(2.0);
cv::gpu::SURF_GPU surf;
cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
cv::gpu::GpuMat img(img_host);
cv::gpu::GpuMat keypoints, descriptors;
cv::gpu::SURF_GPU d_surf;
surf(img, cv::gpu::GpuMat(), keypoints, descriptors);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints, d_descriptors;
declare.time(2.0);
d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
TEST_CYCLE()
{
surf(img, cv::gpu::GpuMat(), keypoints, descriptors);
d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
}
}
INSTANTIATE_TEST_CASE_P(Features2D, SURF, ALL_DEVICES);
//////////////////////////////////////////////////////////////////////
// FAST
GPU_PERF_TEST_1(FAST, cv::gpu::DeviceInfo)
PERF_TEST_P(Image, Features2D_FAST, Values<string>("gpu/perf/aloe.jpg"))
{
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty());
cv::gpu::FAST_GPU d_fast(20);
cv::gpu::FAST_GPU fast(20);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints;
cv::gpu::GpuMat img(img_host);
cv::gpu::GpuMat keypoints;
fast(img, cv::gpu::GpuMat(), keypoints);
d_fast(d_img, cv::gpu::GpuMat(), d_keypoints);
TEST_CYCLE()
{
fast(img, cv::gpu::GpuMat(), keypoints);
d_fast(d_img, cv::gpu::GpuMat(), d_keypoints);
}
}
INSTANTIATE_TEST_CASE_P(Features2D, FAST, ALL_DEVICES);
//////////////////////////////////////////////////////////////////////
// ORB
GPU_PERF_TEST_1(ORB, cv::gpu::DeviceInfo)
PERF_TEST_P(Image, Features2D_ORB, Values<string>("gpu/perf/aloe.jpg"))
{
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty());
cv::gpu::ORB_GPU d_orb(4000);
cv::gpu::ORB_GPU orb(4000);
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints, d_descriptors;
cv::gpu::GpuMat img(img_host);
cv::gpu::GpuMat keypoints, descriptors;
d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
TEST_CYCLE()
{
orb(img, cv::gpu::GpuMat(), keypoints, descriptors);
d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
}
}
INSTANTIATE_TEST_CASE_P(Features2D, ORB, ALL_DEVICES);
//////////////////////////////////////////////////////////////////////
// BruteForceMatcher_match
// BFMatch
IMPLEMENT_PARAM_CLASS(DescriptorSize, int)
DEF_PARAM_TEST(DescSize_Norm, int, NormType);
GPU_PERF_TEST(BruteForceMatcher_match, cv::gpu::DeviceInfo, DescriptorSize, NormType)
PERF_TEST_P(DescSize_Norm, Features2D_BFMatch, Combine(Values(64, 128, 256), Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING))))
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
declare.time(3.0);
int desc_size = GET_PARAM(1);
int normType = GET_PARAM(2);
int desc_size = GET_PARAM(0);
int normType = GET_PARAM(1);
int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
cv::Mat query_host(3000, desc_size, type);
fill(query_host, 0.0, 10.0);
cv::Mat train_host(3000, desc_size, type);
fill(train_host, 0.0, 10.0);
cv::Mat query(3000, desc_size, type);
fillRandom(query);
cv::gpu::BFMatcher_GPU matcher(normType);
cv::Mat train(3000, desc_size, type);
fillRandom(train);
cv::gpu::GpuMat query(query_host);
cv::gpu::GpuMat train(train_host);
cv::gpu::GpuMat trainIdx, distance;
cv::gpu::BFMatcher_GPU d_matcher(normType);
matcher.matchSingle(query, train, trainIdx, distance);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_distance;
declare.time(3.0);
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
TEST_CYCLE()
{
matcher.matchSingle(query, train, trainIdx, distance);
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
}
}
INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_match, testing::Combine(
ALL_DEVICES,
testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)),
testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING))));
//////////////////////////////////////////////////////////////////////
// BruteForceMatcher_knnMatch
// BFKnnMatch
IMPLEMENT_PARAM_CLASS(K, int)
DEF_PARAM_TEST(DescSize_K_Norm, int, int, NormType);
GPU_PERF_TEST(BruteForceMatcher_knnMatch, cv::gpu::DeviceInfo, DescriptorSize, K, NormType)
PERF_TEST_P(DescSize_K_Norm, Features2D_BFKnnMatch, Combine(
Values(64, 128, 256),
Values(2, 3),
Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING))))
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
declare.time(3.0);
int desc_size = GET_PARAM(1);
int k = GET_PARAM(2);
int normType = GET_PARAM(3);
int desc_size = GET_PARAM(0);
int k = GET_PARAM(1);
int normType = GET_PARAM(2);
int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
cv::Mat query_host(3000, desc_size, type);
fill(query_host, 0.0, 10.0);
cv::Mat train_host(3000, desc_size, type);
fill(train_host, 0.0, 10.0);
cv::Mat query(3000, desc_size, type);
fillRandom(query);
cv::gpu::BFMatcher_GPU matcher(normType);
cv::Mat train(3000, desc_size, type);
fillRandom(train);
cv::gpu::GpuMat query(query_host);
cv::gpu::GpuMat train(train_host);
cv::gpu::GpuMat trainIdx, distance, allDist;
cv::gpu::BFMatcher_GPU d_matcher(normType);
matcher.knnMatchSingle(query, train, trainIdx, distance, allDist, k);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_distance, d_allDist;
declare.time(3.0);
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k);
TEST_CYCLE()
{
matcher.knnMatchSingle(query, train, trainIdx, distance, allDist, k);
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k);
}
}
INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_knnMatch, testing::Combine(
ALL_DEVICES,
testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)),
testing::Values(K(2), K(3)),
testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING))));
//////////////////////////////////////////////////////////////////////
// BruteForceMatcher_radiusMatch
// BFRadiusMatch
GPU_PERF_TEST(BruteForceMatcher_radiusMatch, cv::gpu::DeviceInfo, DescriptorSize, NormType)
PERF_TEST_P(DescSize_Norm, Features2D_BFRadiusMatch, Combine(Values(64, 128, 256), Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING))))
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
declare.time(3.0);
int desc_size = GET_PARAM(1);
int normType = GET_PARAM(2);
int desc_size = GET_PARAM(0);
int normType = GET_PARAM(1);
int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
cv::Mat query_host(3000, desc_size, type);
fill(query_host, 0.0, 1.0);
cv::Mat query(3000, desc_size, type);
fillRandom(query, 0.0, 1.0);
cv::Mat train_host(3000, desc_size, type);
fill(train_host, 0.0, 1.0);
cv::Mat train(3000, desc_size, type);
fillRandom(train, 0.0, 1.0);
cv::gpu::BFMatcher_GPU matcher(normType);
cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat query(query_host);
cv::gpu::GpuMat train(train_host);
cv::gpu::GpuMat trainIdx, nMatches, distance;
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_nMatches, d_distance;
matcher.radiusMatchSingle(query, train, trainIdx, distance, nMatches, 2.0);
declare.time(3.0);
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0);
TEST_CYCLE()
{
matcher.radiusMatchSingle(query, train, trainIdx, distance, nMatches, 2.0);
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0);
}
}
INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_radiusMatch, testing::Combine(
ALL_DEVICES,
testing::Values(DescriptorSize(64), DescriptorSize(128), DescriptorSize(256)),
testing::Values(NormType(cv::NORM_L1), NormType(cv::NORM_L2), NormType(cv::NORM_HAMMING))));
#endif
} // namespace
This diff is collapsed.
This diff is collapsed.
......@@ -41,14 +41,16 @@
#include "perf_precomp.hpp"
#ifdef HAVE_CUDA
using namespace std;
using namespace testing;
GPU_PERF_TEST(ConnectedComponents, cv::gpu::DeviceInfo, cv::Size)
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
namespace {
DEF_PARAM_TEST_1(Image, string);
cv::Mat image = readImage("gpu/labeling/aloe-disp.png", cv::IMREAD_GRAYSCALE);
PERF_TEST_P(Image, Labeling_ConnectedComponents, Values<string>("gpu/labeling/aloe-disp.png"))
{
cv::Mat image = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
// cv::threshold(image, image, 150, 255, CV_THRESH_BINARY);
......@@ -70,6 +72,4 @@ GPU_PERF_TEST(ConnectedComponents, cv::gpu::DeviceInfo, cv::Size)
}
}
INSTANTIATE_TEST_CASE_P(Labeling, ConnectedComponents, testing::Combine(ALL_DEVICES, testing::Values(cv::Size(261, 262))));
#endif
\ No newline at end of file
} // namespace
......@@ -2,11 +2,98 @@
#ifdef HAVE_CUDA
using namespace std;
using namespace cv;
using namespace cv::gpu;
using namespace cvtest;
using namespace testing;
void printInfo()
{
#if defined _WIN32
# if defined _WIN64
puts("OS: Windows x64");
# else
puts("OS: Windows x32");
# endif
#elif defined linux
# if defined _LP64
puts("OS: Linux x64");
# else
puts("OS: Linux x32");
# endif
#elif defined __APPLE__
# if defined _LP64
puts("OS: Apple x64");
# else
puts("OS: Apple x32");
# endif
#endif
int driver;
cudaDriverGetVersion(&driver);
printf("CUDA Driver version: %d\n", driver);
printf("CUDA Runtime version: %d\n", CUDART_VERSION);
puts("GPU module was compiled for the following GPU archs:");
printf(" BIN: %s\n", CUDA_ARCH_BIN);
printf(" PTX: %s\n\n", CUDA_ARCH_PTX);
int deviceCount = getCudaEnabledDeviceCount();
printf("CUDA device count: %d\n\n", deviceCount);
for (int i = 0; i < deviceCount; ++i)
{
DeviceInfo info(i);
printf("Device %d:\n", i);
printf(" Name: %s\n", info.name().c_str());
printf(" Compute capability version: %d.%d\n", info.majorVersion(), info.minorVersion());
printf(" Multi Processor Count: %d\n", info.multiProcessorCount());
printf(" Total memory: %d Mb\n", static_cast<int>(static_cast<int>(info.totalMemory() / 1024.0) / 1024.0));
printf(" Free memory: %d Mb\n", static_cast<int>(static_cast<int>(info.freeMemory() / 1024.0) / 1024.0));
if (!info.isCompatible())
puts(" !!! This device is NOT compatible with current GPU module build\n");
printf("\n");
}
}
int main(int argc, char **argv)
{
CommandLineParser parser(argc, (const char**)argv,
"{ print_info_only | print_info_only | false | Print information about system and exit }"
"{ device | device | 0 | Device on which tests will be executed }");
printInfo();
if (parser.get<bool>("print_info_only"))
return 0;
int device = parser.get<int>("device");
if (device < 0 || device >= getCudaEnabledDeviceCount())
{
cerr << "Incorrect device number - " << device << endl;
return -1;
}
DeviceInfo info(device);
if (!info.isCompatible())
{
cerr << "Device " << device << " [" << info.name() << "] is NOT compatible with current GPU module build" << endl;
return -1;
}
std::cout << "Run tests on device " << device << '\n' << std::endl;
setDevice(device);
testing::InitGoogleTest(&argc, argv);
perf::TestBase::Init(argc, argv);
return RUN_ALL_TESTS();
return 0;
}
#else
......
#include "perf_precomp.hpp"
#ifdef HAVE_CUDA
using namespace std;
using namespace testing;
namespace {
//////////////////////////////////////////////////////////////////////
// SetTo
GPU_PERF_TEST(SetTo, cv::gpu::DeviceInfo, cv::Size, MatType)
PERF_TEST_P(Sz_Depth_Cn, MatOp_SetTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4)))
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
cv::Size size = GET_PARAM(0);
int depth = GET_PARAM(1);
int channels = GET_PARAM(2);
cv::Size size = GET_PARAM(1);
int type = GET_PARAM(2);
int type = CV_MAKE_TYPE(depth, channels);
cv::gpu::GpuMat src(size, type);
cv::Scalar val(1, 2, 3, 4);
src.setTo(val);
cv::gpu::GpuMat d_src(size, type);
d_src.setTo(val);
TEST_CYCLE()
{
src.setTo(val);
d_src.setTo(val);
}
}
INSTANTIATE_TEST_CASE_P(MatOp, SetTo, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4),
MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4),
MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4),
MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4))));
//////////////////////////////////////////////////////////////////////
// SetToMasked
GPU_PERF_TEST(SetToMasked, cv::gpu::DeviceInfo, cv::Size, MatType)
PERF_TEST_P(Sz_Depth_Cn, MatOp_SetToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4)))
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
cv::Size size = GET_PARAM(0);
int depth = GET_PARAM(1);
int channels = GET_PARAM(2);
cv::Size size = GET_PARAM(1);
int type = GET_PARAM(2);
int type = CV_MAKE_TYPE(depth, channels);
cv::Mat src_host(size, type);
fill(src_host, 0, 255);
cv::Mat src(size, type);
fillRandom(src);
cv::Mat mask_host(size, CV_8UC1);
fill(mask_host, 0, 2);
cv::Mat mask(size, CV_8UC1);
fillRandom(mask, 0, 2);
cv::gpu::GpuMat src(src_host);
cv::Scalar val(1, 2, 3, 4);
cv::gpu::GpuMat mask(mask_host);
src.setTo(val, mask);
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_mask(mask);
d_src.setTo(val, d_mask);
TEST_CYCLE()
{
src.setTo(val, mask);
d_src.setTo(val, d_mask);
}
}
INSTANTIATE_TEST_CASE_P(MatOp, SetToMasked, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4),
MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4),
MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4),
MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4))));
//////////////////////////////////////////////////////////////////////
// CopyToMasked
GPU_PERF_TEST(CopyToMasked, cv::gpu::DeviceInfo, cv::Size, MatType)
PERF_TEST_P(Sz_Depth_Cn, MatOp_CopyToMasked, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(1, 3, 4)))
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
cv::Size size = GET_PARAM(0);
int depth = GET_PARAM(1);
int channels = GET_PARAM(2);
cv::Size size = GET_PARAM(1);
int type = GET_PARAM(2);
int type = CV_MAKE_TYPE(depth, channels);
cv::Mat src_host(size, type);
fill(src_host, 0, 255);
cv::Mat src(size, type);
fillRandom(src);
cv::Mat mask_host(size, CV_8UC1);
fill(mask_host, 0, 2);
cv::Mat mask(size, CV_8UC1);
fillRandom(mask, 0, 2);
cv::gpu::GpuMat src(src_host);
cv::gpu::GpuMat mask(mask_host);
cv::gpu::GpuMat dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_mask(mask);
cv::gpu::GpuMat d_dst;
src.copyTo(dst, mask);
d_src.copyTo(d_dst, d_mask);
TEST_CYCLE()
{
src.copyTo(dst, mask);
d_src.copyTo(d_dst, d_mask);
}
}
INSTANTIATE_TEST_CASE_P(MatOp, CopyToMasked, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC3), MatType(CV_8UC4),
MatType(CV_16UC1), MatType(CV_16UC3), MatType(CV_16UC4),
MatType(CV_32FC1), MatType(CV_32FC3), MatType(CV_32FC4),
MatType(CV_64FC1), MatType(CV_64FC3), MatType(CV_64FC4))));
//////////////////////////////////////////////////////////////////////
// ConvertTo
GPU_PERF_TEST(ConvertTo, cv::gpu::DeviceInfo, cv::Size, MatDepth, MatDepth)
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
DEF_PARAM_TEST(Sz_2Depth, cv::Size, MatDepth, MatDepth);
cv::Size size = GET_PARAM(1);
int depth1 = GET_PARAM(2);
int depth2 = GET_PARAM(3);
PERF_TEST_P(Sz_2Depth, MatOp_ConvertTo, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16U, CV_32F, CV_64F), Values(CV_8U, CV_16U, CV_32F, CV_64F)))
{
cv::Size size = GET_PARAM(0);
int depth1 = GET_PARAM(1);
int depth2 = GET_PARAM(2);
cv::Mat src_host(size, depth1);
fill(src_host, 0, 255);
cv::Mat src(size, depth1);
fillRandom(src);
cv::gpu::GpuMat src(src_host);
cv::gpu::GpuMat dst;
cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
src.convertTo(dst, depth2, 0.5, 1.0);
d_src.convertTo(d_dst, depth2, 0.5, 1.0);
TEST_CYCLE()
{
src.convertTo(dst, depth2, 0.5, 1.0);
d_src.convertTo(d_dst, depth2, 0.5, 1.0);
}
}
INSTANTIATE_TEST_CASE_P(MatOp, ConvertTo, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F), MatDepth(CV_64F)),
testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F), MatDepth(CV_64F))));
#endif
} // namespace
#include "perf_precomp.hpp"
#ifdef HAVE_CUDA
using namespace std;
using namespace testing;
namespace {
///////////////////////////////////////////////////////////////
// HOG
GPU_PERF_TEST_1(HOG, cv::gpu::DeviceInfo)
{
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
DEF_PARAM_TEST_1(Image, string);
cv::Mat img_host = readImage("gpu/hog/road.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty());
PERF_TEST_P(Image, ObjDetect_HOG, Values<string>("gpu/hog/road.png"))
{
cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
cv::gpu::GpuMat img(img_host);
std::vector<cv::Rect> found_locations;
cv::gpu::HOGDescriptor hog;
hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
cv::gpu::GpuMat d_img(img);
hog.detectMultiScale(img, found_locations);
cv::gpu::HOGDescriptor d_hog;
d_hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
d_hog.detectMultiScale(d_img, found_locations);
TEST_CYCLE()
{
hog.detectMultiScale(img, found_locations);
d_hog.detectMultiScale(d_img, found_locations);
}
}
INSTANTIATE_TEST_CASE_P(ObjDetect, HOG, ALL_DEVICES);
///////////////////////////////////////////////////////////////
// HaarClassifier
GPU_PERF_TEST_1(HaarClassifier, cv::gpu::DeviceInfo)
{
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
typedef pair<string, string> pair_string;
DEF_PARAM_TEST_1(ImageAndCascade, pair_string);
cv::Mat img_host = readImage("gpu/haarcascade/group_1_640x480_VGA.pgm", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty());
PERF_TEST_P(ImageAndCascade, ObjDetect_HaarClassifier,
Values<pair_string>(make_pair("gpu/haarcascade/group_1_640x480_VGA.pgm", "gpu/perf/haarcascade_frontalface_alt.xml")))
{
cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
cv::gpu::CascadeClassifier_GPU cascade;
cv::gpu::CascadeClassifier_GPU d_cascade;
ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/perf/haarcascade_frontalface_alt.xml")));
ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second)));
cv::gpu::GpuMat img(img_host);
cv::gpu::GpuMat objects_buffer;
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_objects_buffer;
cascade.detectMultiScale(img, objects_buffer);
d_cascade.detectMultiScale(d_img, d_objects_buffer);
TEST_CYCLE()
{
cascade.detectMultiScale(img, objects_buffer);
d_cascade.detectMultiScale(d_img, d_objects_buffer);
}
}
INSTANTIATE_TEST_CASE_P(ObjDetect, HaarClassifier, ALL_DEVICES);
///////////////////////////////////////////////////////////////
// LBP cascade
//===================== LBP cascade ==========================//
GPU_PERF_TEST_1(LBPClassifier, cv::gpu::DeviceInfo)
PERF_TEST_P(ImageAndCascade, ObjDetect_LBPClassifier,
Values<pair_string>(make_pair("gpu/haarcascade/group_1_640x480_VGA.pgm", "gpu/lbpcascade/lbpcascade_frontalface.xml")))
{
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/haarcascade/group_1_640x480_VGA.pgm", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty());
cv::gpu::CascadeClassifier_GPU d_cascade;
ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second)));
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_gpu_rects;
cv::gpu::GpuMat img(img_host);
cv::gpu::GpuMat gpu_rects;
cv::gpu::CascadeClassifier_GPU cascade;
ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/lbpcascade/lbpcascade_frontalface.xml")));
d_cascade.detectMultiScale(d_img, d_gpu_rects);
cascade.detectMultiScale(img, gpu_rects);
TEST_CYCLE()
{
cascade.detectMultiScale(img, gpu_rects);
d_cascade.detectMultiScale(d_img, d_gpu_rects);
}
}
INSTANTIATE_TEST_CASE_P(ObjDetect, LBPClassifier, ALL_DEVICES);
#endif
} // namespace
......@@ -11,6 +11,10 @@
#include "cvconfig.h"
#ifdef HAVE_CUDA
#include <cuda_runtime.h>
#endif
#include "opencv2/ts/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
......@@ -18,6 +22,10 @@
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/legacy/legacy.hpp"
#include "perf_utility.hpp"
......
......@@ -4,12 +4,17 @@ using namespace std;
using namespace cv;
using namespace cv::gpu;
void fill(Mat& m, double a, double b)
void fillRandom(Mat& m, double a, double b)
{
RNG rng(123456789);
rng.fill(m, RNG::UNIFORM, Scalar::all(a), Scalar::all(b));
}
Mat readImage(const string& fileName, int flags)
{
return imread(perf::TestBase::getDataPath(fileName), flags);
}
void PrintTo(const CvtColorInfo& info, ostream* os)
{
static const char* str[] =
......@@ -184,37 +189,3 @@ void PrintTo(const CvtColorInfo& info, ostream* os)
*os << str[info.code];
}
void cv::gpu::PrintTo(const DeviceInfo& info, ostream* os)
{
*os << info.name();
}
Mat readImage(const string& fileName, int flags)
{
return imread(perf::TestBase::getDataPath(fileName), flags);
}
const vector<DeviceInfo>& devices()
{
static vector<DeviceInfo> devs;
static bool first = true;
if (first)
{
int deviceCount = getCudaEnabledDeviceCount();
devs.reserve(deviceCount);
for (int i = 0; i < deviceCount; ++i)
{
DeviceInfo info(i);
if (info.isCompatible())
devs.push_back(info);
}
first = false;
}
return devs;
}
#ifndef __OPENCV_PERF_GPU_UTILITY_HPP__
#define __OPENCV_PERF_GPU_UTILITY_HPP__
void fill(cv::Mat& m, double a, double b);
#include "opencv2/core/core.hpp"
#include "opencv2/core/gpumat.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/ts/ts_perf.hpp"
void fillRandom(cv::Mat& m, double a = 0.0, double b = 255.0);
cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR);
using perf::MatType;
using perf::MatDepth;
CV_ENUM(BorderMode, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP)
CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::INTER_AREA)
#define ALL_BORDER_MODES testing::ValuesIn(BorderMode::all())
CV_ENUM(Interpolation, cv::INTER_NEAREST, cv::INTER_LINEAR, cv::INTER_CUBIC, cv::INTER_AREA)
#define ALL_INTERPOLATIONS testing::ValuesIn(Interpolation::all())
CV_ENUM(NormType, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_HAMMING)
struct CvtColorInfo
......@@ -18,60 +26,18 @@ struct CvtColorInfo
explicit CvtColorInfo(int scn_=0, int dcn_=0, int code_=0) : scn(scn_), dcn(dcn_), code(code_) {}
};
void PrintTo(const CvtColorInfo& info, std::ostream* os);
#define IMPLEMENT_PARAM_CLASS(name, type) \
class name \
{ \
public: \
name ( type arg = type ()) : val_(arg) {} \
operator type () const {return val_;} \
private: \
type val_; \
}; \
inline void PrintTo( name param, std::ostream* os) \
{ \
*os << #name << " = " << testing::PrintToString(static_cast< type >(param)); \
}
IMPLEMENT_PARAM_CLASS(Channels, int)
namespace cv { namespace gpu
{
void PrintTo(const cv::gpu::DeviceInfo& info, std::ostream* os);
}}
#define GPU_PERF_TEST(name, ...) \
struct name : perf::TestBaseWithParam< std::tr1::tuple< __VA_ARGS__ > > \
{ \
public: \
name() {} \
protected: \
void PerfTestBody(); \
}; \
TEST_P(name, perf){ RunPerfTestBody(); } \
void name :: PerfTestBody()
#define GPU_PERF_TEST_1(name, param_type) \
struct name : perf::TestBaseWithParam< param_type > \
{ \
public: \
name() {} \
protected: \
void PerfTestBody(); \
}; \
TEST_P(name, perf){ RunPerfTestBody(); } \
void name :: PerfTestBody()
#define GPU_TYPICAL_MAT_SIZES testing::Values(perf::szSXGA, perf::sz1080p, cv::Size(1800, 1500))
cv::Mat readImage(const std::string& fileName, int flags = cv::IMREAD_COLOR);
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
const std::vector<cv::gpu::DeviceInfo>& devices();
#define DEF_PARAM_TEST(name, ...) typedef ::perf::TestBaseWithParam< std::tr1::tuple< __VA_ARGS__ > > name
#define DEF_PARAM_TEST_1(name, param_type) typedef ::perf::TestBaseWithParam< param_type > name
#define ALL_DEVICES testing::ValuesIn(devices())
DEF_PARAM_TEST_1(Sz, cv::Size);
typedef perf::Size_MatType Sz_Type;
DEF_PARAM_TEST(Sz_Depth, cv::Size, MatDepth);
DEF_PARAM_TEST(Sz_Depth_Cn, cv::Size, MatDepth, int);
#define GET_PARAM(k) std::tr1::get< k >(GetParam())
#define GPU_TYPICAL_MAT_SIZES testing::Values(perf::szSXGA, perf::sz720p, perf::sz1080p)
#endif // __OPENCV_PERF_GPU_UTILITY_HPP__
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment