updated gpu performance tests

now it executes only on one device
added posibility to specify device on which tests will be executed
This commit is contained in:
Vladislav Vinogradov 2012-08-17 15:14:14 +04:00
parent ddca47040b
commit 6e4eb722a6
13 changed files with 2079 additions and 2853 deletions

View File

@ -1,207 +1,180 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
#ifdef HAVE_CUDA using namespace std;
using namespace testing;
namespace {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// StereoBM // StereoBM
GPU_PERF_TEST_1(StereoBM, cv::gpu::DeviceInfo) typedef pair<string, string> pair_string;
DEF_PARAM_TEST_1(ImagePair, pair_string);
PERF_TEST_P(ImagePair, Calib3D_StereoBM, Values(make_pair<string, string>("gpu/perf/aloe.jpg", "gpu/perf/aloeR.jpg")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img_l_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_l_host.empty());
cv::Mat img_r_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_r_host.empty());
cv::gpu::StereoBM_GPU bm(0, 256);
cv::gpu::GpuMat img_l(img_l_host);
cv::gpu::GpuMat img_r(img_r_host);
cv::gpu::GpuMat dst;
bm(img_l, img_r, dst);
declare.time(5.0); declare.time(5.0);
cv::Mat imgLeft = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(imgLeft.empty());
cv::Mat imgRight = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(imgRight.empty());
cv::gpu::StereoBM_GPU d_bm(0, 256);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_bm(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE() TEST_CYCLE()
{ {
bm(img_l, img_r, dst); d_bm(d_imgLeft, d_imgRight, d_dst);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, StereoBM, ALL_DEVICES);
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// StereoBeliefPropagation // StereoBeliefPropagation
GPU_PERF_TEST_1(StereoBeliefPropagation, cv::gpu::DeviceInfo) PERF_TEST_P(ImagePair, Calib3D_StereoBeliefPropagation, Values(make_pair<string, string>("gpu/stereobp/aloe-L.png", "gpu/stereobp/aloe-R.png")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img_l_host = readImage("gpu/stereobp/aloe-L.png");
ASSERT_FALSE(img_l_host.empty());
cv::Mat img_r_host = readImage("gpu/stereobp/aloe-R.png");
ASSERT_FALSE(img_r_host.empty());
cv::gpu::StereoBeliefPropagation bp(64);
cv::gpu::GpuMat img_l(img_l_host);
cv::gpu::GpuMat img_r(img_r_host);
cv::gpu::GpuMat dst;
bp(img_l, img_r, dst);
declare.time(10.0); declare.time(10.0);
cv::Mat imgLeft = readImage(GetParam().first);
ASSERT_FALSE(imgLeft.empty());
cv::Mat imgRight = readImage(GetParam().second);
ASSERT_FALSE(imgRight.empty());
cv::gpu::StereoBeliefPropagation d_bp(64);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_bp(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE() TEST_CYCLE()
{ {
bp(img_l, img_r, dst); d_bp(d_imgLeft, d_imgRight, d_dst);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, StereoBeliefPropagation, ALL_DEVICES);
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// StereoConstantSpaceBP // StereoConstantSpaceBP
GPU_PERF_TEST_1(StereoConstantSpaceBP, cv::gpu::DeviceInfo) PERF_TEST_P(ImagePair, Calib3D_StereoConstantSpaceBP, Values(make_pair<string, string>("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-R.png")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img_l_host = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_l_host.empty());
cv::Mat img_r_host = readImage("gpu/stereobm/aloe-R.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_r_host.empty());
cv::gpu::StereoConstantSpaceBP csbp(128);
cv::gpu::GpuMat img_l(img_l_host);
cv::gpu::GpuMat img_r(img_r_host);
cv::gpu::GpuMat dst;
csbp(img_l, img_r, dst);
declare.time(10.0); declare.time(10.0);
cv::Mat imgLeft = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(imgLeft.empty());
cv::Mat imgRight = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(imgRight.empty());
cv::gpu::StereoConstantSpaceBP d_csbp(128);
cv::gpu::GpuMat d_imgLeft(imgLeft);
cv::gpu::GpuMat d_imgRight(imgRight);
cv::gpu::GpuMat d_dst;
d_csbp(d_imgLeft, d_imgRight, d_dst);
TEST_CYCLE() TEST_CYCLE()
{ {
csbp(img_l, img_r, dst); d_csbp(d_imgLeft, d_imgRight, d_dst);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, StereoConstantSpaceBP, ALL_DEVICES);
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// DisparityBilateralFilter // DisparityBilateralFilter
GPU_PERF_TEST_1(DisparityBilateralFilter, cv::gpu::DeviceInfo) PERF_TEST_P(ImagePair, Calib3D_DisparityBilateralFilter, Values(make_pair<string, string>("gpu/stereobm/aloe-L.png", "gpu/stereobm/aloe-disp.png")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam(); cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID()); ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/stereobm/aloe-L.png", cv::IMREAD_GRAYSCALE); cv::Mat disp = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty()); ASSERT_FALSE(disp.empty());
cv::Mat disp_host = readImage("gpu/stereobm/aloe-disp.png", cv::IMREAD_GRAYSCALE); cv::gpu::DisparityBilateralFilter d_filter(128);
ASSERT_FALSE(disp_host.empty()); cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_disp(disp);
cv::gpu::GpuMat d_dst;
cv::gpu::DisparityBilateralFilter f(128); d_filter(d_disp, d_img, d_dst);
cv::gpu::GpuMat img(img_host);
cv::gpu::GpuMat disp(disp_host);
cv::gpu::GpuMat dst;
f(disp, img, dst);
TEST_CYCLE() TEST_CYCLE()
{ {
f(disp, img, dst); d_filter(d_disp, d_img, d_dst);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, DisparityBilateralFilter, ALL_DEVICES);
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// TransformPoints // TransformPoints
IMPLEMENT_PARAM_CLASS(Count, int) DEF_PARAM_TEST_1(Count, int);
GPU_PERF_TEST(TransformPoints, cv::gpu::DeviceInfo, Count) PERF_TEST_P(Count, Calib3D_TransformPoints, Values(5000, 10000, 20000))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); int count = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
int count = GET_PARAM(1); cv::Mat src(1, count, CV_32FC3);
fillRandom(src, -100, 100);
cv::Mat src_host(1, count, CV_32FC3);
fill(src_host, -100, 100);
cv::gpu::GpuMat src(src_host);
cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1);
cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1);
cv::gpu::GpuMat dst;
cv::gpu::transformPoints(src, rvec, tvec, dst); cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::transformPoints(d_src, rvec, tvec, d_dst);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::transformPoints(src, rvec, tvec, dst); cv::gpu::transformPoints(d_src, rvec, tvec, d_dst);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, TransformPoints, testing::Combine(
ALL_DEVICES,
testing::Values<Count>(5000, 10000, 20000)));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// ProjectPoints // ProjectPoints
GPU_PERF_TEST(ProjectPoints, cv::gpu::DeviceInfo, Count) PERF_TEST_P(Count, Calib3D_ProjectPoints, Values(5000, 10000, 20000))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); int count = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
int count = GET_PARAM(1); cv::Mat src(1, count, CV_32FC3);
fillRandom(src, -100, 100);
cv::Mat src_host(1, count, CV_32FC3);
fill(src_host, -100, 100);
cv::gpu::GpuMat src(src_host);
cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1); cv::Mat rvec = cv::Mat::ones(1, 3, CV_32FC1);
cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1); cv::Mat tvec = cv::Mat::ones(1, 3, CV_32FC1);
cv::Mat camera_mat = cv::Mat::ones(3, 3, CV_32FC1); cv::Mat camera_mat = cv::Mat::ones(3, 3, CV_32FC1);
cv::gpu::GpuMat dst;
cv::gpu::projectPoints(src, rvec, tvec, camera_mat, cv::Mat(), dst); cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat d_dst;
cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::projectPoints(src, rvec, tvec, camera_mat, cv::Mat(), dst); cv::gpu::projectPoints(d_src, rvec, tvec, camera_mat, cv::Mat(), d_dst);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, ProjectPoints, testing::Combine(
ALL_DEVICES,
testing::Values<Count>(5000, 10000, 20000)));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// SolvePnPRansac // SolvePnPRansac
GPU_PERF_TEST(SolvePnPRansac, cv::gpu::DeviceInfo, Count) PERF_TEST_P(Count, Calib3D_SolvePnPRansac, Values(5000, 10000, 20000))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); declare.time(3.0);
cv::gpu::setDevice(devInfo.deviceID());
int count = GET_PARAM(1); int count = GetParam();
cv::Mat object(1, count, CV_32FC3); cv::Mat object(1, count, CV_32FC3);
fill(object, -100, 100); fillRandom(object, -100, 100);
cv::Mat camera_mat(3, 3, CV_32FC1); cv::Mat camera_mat(3, 3, CV_32FC1);
fill(camera_mat, 0.5, 1); fillRandom(camera_mat, 0.5, 1);
camera_mat.at<float>(0, 1) = 0.f; camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(1, 0) = 0.f; camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f; camera_mat.at<float>(2, 0) = 0.f;
@ -211,9 +184,9 @@ GPU_PERF_TEST(SolvePnPRansac, cv::gpu::DeviceInfo, Count)
std::vector<cv::Point2f> image_vec; std::vector<cv::Point2f> image_vec;
cv::Mat rvec_gold(1, 3, CV_32FC1); cv::Mat rvec_gold(1, 3, CV_32FC1);
fill(rvec_gold, 0, 1); fillRandom(rvec_gold, 0, 1);
cv::Mat tvec_gold(1, 3, CV_32FC1); cv::Mat tvec_gold(1, 3, CV_32FC1);
fill(tvec_gold, 0, 1); fillRandom(tvec_gold, 0, 1);
cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, dist_coef, image_vec); cv::projectPoints(object, rvec_gold, tvec_gold, camera_mat, dist_coef, image_vec);
cv::Mat image(1, count, CV_32FC2, &image_vec[0]); cv::Mat image(1, count, CV_32FC2, &image_vec[0]);
@ -223,80 +196,57 @@ GPU_PERF_TEST(SolvePnPRansac, cv::gpu::DeviceInfo, Count)
cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
declare.time(3.0);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec); cv::gpu::solvePnPRansac(object, image, camera_mat, dist_coef, rvec, tvec);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, SolvePnPRansac, testing::Combine(
ALL_DEVICES,
testing::Values<Count>(5000, 10000, 20000)));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// ReprojectImageTo3D // ReprojectImageTo3D
GPU_PERF_TEST(ReprojectImageTo3D, cv::gpu::DeviceInfo, cv::Size, MatDepth) PERF_TEST_P(Sz_Depth, Calib3D_ReprojectImageTo3D, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int depth = GET_PARAM(1);
cv::Size size = GET_PARAM(1); cv::Mat src(size, depth);
int depth = GET_PARAM(2); fillRandom(src, 5.0, 30.0);
cv::Mat src_host(size, depth);
fill(src_host, 5.0, 30.0);
cv::Mat Q(4, 4, CV_32FC1); cv::Mat Q(4, 4, CV_32FC1);
fill(Q, 0.1, 1.0); fillRandom(Q, 0.1, 1.0);
cv::gpu::GpuMat src(src_host); cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat dst; cv::gpu::GpuMat d_dst;
cv::gpu::reprojectImageTo3D(src, dst, Q); cv::gpu::reprojectImageTo3D(d_src, d_dst, Q);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::reprojectImageTo3D(src, dst, Q); cv::gpu::reprojectImageTo3D(d_src, d_dst, Q);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, ReprojectImageTo3D, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values<MatDepth>(CV_8U, CV_16S)));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// DrawColorDisp // DrawColorDisp
GPU_PERF_TEST(DrawColorDisp, cv::gpu::DeviceInfo, cv::Size, MatDepth) PERF_TEST_P(Sz_Depth, Calib3D_DrawColorDisp, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8U, CV_16S)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src, 0, 255);
cv::Mat src_host(size, type); cv::gpu::GpuMat d_src(src);
fill(src_host, 0, 255); cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat src(src_host); cv::gpu::drawColorDisp(d_src, d_dst, 255);
cv::gpu::GpuMat dst;
cv::gpu::drawColorDisp(src, dst, 255);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::drawColorDisp(src, dst, 255); cv::gpu::drawColorDisp(d_src, d_dst, 255);
} }
} }
INSTANTIATE_TEST_CASE_P(Calib3D, DrawColorDisp, testing::Combine( } // namespace
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatDepth(CV_8U), MatDepth(CV_16S))));
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,209 +1,179 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
#ifdef HAVE_CUDA using namespace std;
using namespace testing;
namespace {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// SURF // SURF
GPU_PERF_TEST_1(SURF, cv::gpu::DeviceInfo) DEF_PARAM_TEST_1(Image, string);
PERF_TEST_P(Image, Features2D_SURF, Values<string>("gpu/perf/aloe.jpg"))
{ {
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty());
cv::gpu::SURF_GPU surf;
cv::gpu::GpuMat img(img_host);
cv::gpu::GpuMat keypoints, descriptors;
surf(img, cv::gpu::GpuMat(), keypoints, descriptors);
declare.time(2.0); declare.time(2.0);
cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img.empty());
cv::gpu::SURF_GPU d_surf;
cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints, d_descriptors;
d_surf(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
TEST_CYCLE() 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 // 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::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID()); ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); cv::gpu::FAST_GPU d_fast(20);
ASSERT_FALSE(img_host.empty());
cv::gpu::FAST_GPU fast(20); cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_keypoints;
cv::gpu::GpuMat img(img_host); d_fast(d_img, cv::gpu::GpuMat(), d_keypoints);
cv::gpu::GpuMat keypoints;
fast(img, cv::gpu::GpuMat(), keypoints);
TEST_CYCLE() 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 // 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::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID()); ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); cv::gpu::ORB_GPU d_orb(4000);
ASSERT_FALSE(img_host.empty());
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); d_orb(d_img, cv::gpu::GpuMat(), d_keypoints, d_descriptors);
cv::gpu::GpuMat keypoints, descriptors;
TEST_CYCLE() 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); //////////////////////////////////////////////////////////////////////
// BFMatch
DEF_PARAM_TEST(DescSize_Norm, int, 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))))
{
declare.time(3.0);
int desc_size = GET_PARAM(0);
int normType = GET_PARAM(1);
int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
cv::Mat query(3000, desc_size, type);
fillRandom(query);
cv::Mat train(3000, desc_size, type);
fillRandom(train);
cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat d_trainIdx, d_distance;
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
TEST_CYCLE()
{
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
}
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// BruteForceMatcher_match // BFKnnMatch
IMPLEMENT_PARAM_CLASS(DescriptorSize, int) DEF_PARAM_TEST(DescSize_K_Norm, int, int, NormType);
GPU_PERF_TEST(BruteForceMatcher_match, cv::gpu::DeviceInfo, DescriptorSize, 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); declare.time(3.0);
cv::gpu::setDevice(devInfo.deviceID());
int desc_size = GET_PARAM(1); int desc_size = GET_PARAM(0);
int k = GET_PARAM(1);
int normType = GET_PARAM(2); int normType = GET_PARAM(2);
int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
cv::Mat query_host(3000, desc_size, type); cv::Mat query(3000, desc_size, type);
fill(query_host, 0.0, 10.0); fillRandom(query);
cv::Mat train_host(3000, desc_size, type); cv::Mat train(3000, desc_size, type);
fill(train_host, 0.0, 10.0); fillRandom(train);
cv::gpu::BFMatcher_GPU matcher(normType); cv::gpu::BFMatcher_GPU d_matcher(normType);
cv::gpu::GpuMat query(query_host); cv::gpu::GpuMat d_query(query);
cv::gpu::GpuMat train(train_host); cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat trainIdx, distance; cv::gpu::GpuMat d_trainIdx, d_distance, d_allDist;
matcher.matchSingle(query, train, trainIdx, distance); d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k);
declare.time(3.0);
TEST_CYCLE() TEST_CYCLE()
{ {
matcher.matchSingle(query, train, trainIdx, distance); d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, k);
} }
} }
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 // BFRadiusMatch
IMPLEMENT_PARAM_CLASS(K, int) 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))))
GPU_PERF_TEST(BruteForceMatcher_knnMatch, cv::gpu::DeviceInfo, DescriptorSize, K, NormType)
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); declare.time(3.0);
cv::gpu::setDevice(devInfo.deviceID());
int desc_size = GET_PARAM(1); int desc_size = GET_PARAM(0);
int k = GET_PARAM(2); int normType = GET_PARAM(1);
int normType = GET_PARAM(3);
int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F; int type = normType == cv::NORM_HAMMING ? CV_8U : CV_32F;
cv::Mat query_host(3000, desc_size, type); cv::Mat query(3000, desc_size, type);
fill(query_host, 0.0, 10.0); fillRandom(query, 0.0, 1.0);
cv::Mat train_host(3000, desc_size, type); cv::Mat train(3000, desc_size, type);
fill(train_host, 0.0, 10.0); 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 d_query(query);
cv::gpu::GpuMat train(train_host); cv::gpu::GpuMat d_train(train);
cv::gpu::GpuMat trainIdx, distance, allDist; cv::gpu::GpuMat d_trainIdx, d_nMatches, d_distance;
matcher.knnMatchSingle(query, train, trainIdx, distance, allDist, k); d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0);
declare.time(3.0);
TEST_CYCLE() TEST_CYCLE()
{ {
matcher.knnMatchSingle(query, train, trainIdx, distance, allDist, k); d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, 2.0);
} }
} }
INSTANTIATE_TEST_CASE_P(Features2D, BruteForceMatcher_knnMatch, testing::Combine( } // namespace
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
GPU_PERF_TEST(BruteForceMatcher_radiusMatch, cv::gpu::DeviceInfo, DescriptorSize, NormType)
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
int desc_size = 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, 1.0);
cv::Mat train_host(3000, desc_size, type);
fill(train_host, 0.0, 1.0);
cv::gpu::BFMatcher_GPU matcher(normType);
cv::gpu::GpuMat query(query_host);
cv::gpu::GpuMat train(train_host);
cv::gpu::GpuMat trainIdx, nMatches, distance;
matcher.radiusMatchSingle(query, train, trainIdx, distance, nMatches, 2.0);
declare.time(3.0);
TEST_CYCLE()
{
matcher.radiusMatchSingle(query, train, trainIdx, distance, 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

View File

@ -1,308 +1,235 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
#ifdef HAVE_CUDA using namespace std;
using namespace testing;
namespace {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Blur // Blur
IMPLEMENT_PARAM_CLASS(KernelSize, int) DEF_PARAM_TEST(Sz_Type_KernelSz, cv::Size, MatType, int);
GPU_PERF_TEST(Blur, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) PERF_TEST_P(Sz_Type_KernelSz, Filters_Blur, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4), Values(3, 5, 7)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
int ksize = GET_PARAM(2);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
int ksize = GET_PARAM(3);
cv::Mat src_host(size, type); cv::gpu::GpuMat d_src(src);
fill(src_host, 0.0, 255.0); cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat src(src_host); cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize));
cv::gpu::GpuMat dst;
cv::gpu::blur(src, dst, cv::Size(ksize, ksize));
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::blur(src, dst, cv::Size(ksize, ksize)); cv::gpu::blur(d_src, d_dst, cv::Size(ksize, ksize));
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, Blur, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
testing::Values(KernelSize(3), KernelSize(5), KernelSize(7))));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Sobel // Sobel
GPU_PERF_TEST(Sobel, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) PERF_TEST_P(Sz_Type_KernelSz, Filters_Sobel, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1), Values(3, 5, 7, 9, 11, 13, 15)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
int ksize = GET_PARAM(2);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
int ksize = GET_PARAM(3);
cv::Mat src_host(size, type); cv::gpu::GpuMat d_src(src);
fill(src_host, 0.0, 255.0); cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_buf;
cv::gpu::GpuMat src(src_host); cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize);
cv::gpu::GpuMat dst;
cv::gpu::GpuMat buf;
cv::gpu::Sobel(src, dst, -1, 1, 1, buf, ksize);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::Sobel(src, dst, -1, 1, 1, buf, ksize); cv::gpu::Sobel(d_src, d_dst, -1, 1, 1, d_buf, ksize);
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, Sobel, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)),
testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15))));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Scharr // Scharr
GPU_PERF_TEST(Scharr, cv::gpu::DeviceInfo, cv::Size, MatType) PERF_TEST_P(Sz_Type, Filters_Scharr, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
cv::Mat src_host(size, type); cv::gpu::GpuMat d_src(src);
fill(src_host, 0.0, 255.0); cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_buf;
cv::gpu::GpuMat src(src_host); cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf);
cv::gpu::GpuMat dst;
cv::gpu::GpuMat buf;
cv::gpu::Scharr(src, dst, -1, 1, 0, buf);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::Scharr(src, dst, -1, 1, 0, buf); cv::gpu::Scharr(d_src, d_dst, -1, 1, 0, d_buf);
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, Scharr, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1))));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// GaussianBlur // GaussianBlur
GPU_PERF_TEST(GaussianBlur, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) PERF_TEST_P(Sz_Type_KernelSz, Filters_GaussianBlur, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1), Values(3, 5, 7, 9, 11, 13, 15)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
int ksize = GET_PARAM(2);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
int ksize = GET_PARAM(3);
cv::Mat src_host(size, type); cv::gpu::GpuMat d_src(src);
fill(src_host, 0.0, 255.0); cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat d_buf;
cv::gpu::GpuMat src(src_host); cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5);
cv::gpu::GpuMat dst;
cv::gpu::GpuMat buf;
cv::gpu::GaussianBlur(src, dst, cv::Size(ksize, ksize), buf, 0.5);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::GaussianBlur(src, dst, cv::Size(ksize, ksize), buf, 0.5); cv::gpu::GaussianBlur(d_src, d_dst, cv::Size(ksize, ksize), d_buf, 0.5);
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, GaussianBlur, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1)),
testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15))));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Laplacian // Laplacian
GPU_PERF_TEST(Laplacian, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) PERF_TEST_P(Sz_Type_KernelSz, Filters_Laplacian, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(1, 3)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
int ksize = GET_PARAM(2);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
int ksize = GET_PARAM(3);
cv::Mat src_host(size, type); cv::gpu::GpuMat d_src(src);
fill(src_host, 0.0, 255.0); cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat src(src_host); cv::gpu::Laplacian(d_src, d_dst, -1, ksize);
cv::gpu::GpuMat dst;
cv::gpu::Laplacian(src, dst, -1, ksize);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::Laplacian(src, dst, -1, ksize); cv::gpu::Laplacian(d_src, d_dst, -1, ksize);
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, Laplacian, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC4)),
testing::Values(KernelSize(1), KernelSize(3))));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Erode // Erode
GPU_PERF_TEST(Erode, cv::gpu::DeviceInfo, cv::Size, MatType) PERF_TEST_P(Sz_Type, Filters_Erode, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
cv::Mat src_host(size, type);
fill(src_host, 0.0, 255.0);
cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
cv::gpu::GpuMat src(src_host); cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat dst; cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat buf; cv::gpu::GpuMat d_buf;
cv::gpu::erode(src, dst, ker, buf); cv::gpu::erode(d_src, d_dst, ker, d_buf);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::erode(src, dst, ker, buf); cv::gpu::erode(d_src, d_dst, ker, d_buf);
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, Erode, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4))));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Dilate // Dilate
GPU_PERF_TEST(Dilate, cv::gpu::DeviceInfo, cv::Size, MatType) PERF_TEST_P(Sz_Type, Filters_Dilate, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
cv::Mat src_host(size, type);
fill(src_host, 0.0, 255.0);
cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
cv::gpu::GpuMat src(src_host); cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat dst; cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat buf; cv::gpu::GpuMat d_buf;
cv::gpu::dilate(src, dst, ker, buf); cv::gpu::dilate(d_src, d_dst, ker, d_buf);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::dilate(src, dst, ker, buf); cv::gpu::dilate(d_src, d_dst, ker, d_buf);
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, Dilate, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4))));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// MorphologyEx // MorphologyEx
CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT) CV_ENUM(MorphOp, cv::MORPH_OPEN, cv::MORPH_CLOSE, cv::MORPH_GRADIENT, cv::MORPH_TOPHAT, cv::MORPH_BLACKHAT)
#define ALL_MORPH_OPS testing::Values(MorphOp(cv::MORPH_OPEN), MorphOp(cv::MORPH_CLOSE), MorphOp(cv::MORPH_GRADIENT), MorphOp(cv::MORPH_TOPHAT), MorphOp(cv::MORPH_BLACKHAT)) #define ALL_MORPH_OPS ValuesIn(MorphOp::all())
GPU_PERF_TEST(MorphologyEx, cv::gpu::DeviceInfo, cv::Size, MatType, MorphOp) DEF_PARAM_TEST(Sz_Type_Op, cv::Size, MatType, MorphOp);
PERF_TEST_P(Sz_Type_Op, Filters_MorphologyEx, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4), ALL_MORPH_OPS))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
int morphOp = GET_PARAM(2);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
int morphOp = GET_PARAM(3);
cv::Mat src_host(size, type);
fill(src_host, 0.0, 255.0);
cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)); cv::Mat ker = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
cv::gpu::GpuMat src(src_host); cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat dst; cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat buf1; cv::gpu::GpuMat d_buf1;
cv::gpu::GpuMat buf2; cv::gpu::GpuMat d_buf2;
cv::gpu::morphologyEx(src, dst, morphOp, ker, buf1, buf2); cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::morphologyEx(src, dst, morphOp, ker, buf1, buf2); cv::gpu::morphologyEx(d_src, d_dst, morphOp, ker, d_buf1, d_buf2);
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, MorphologyEx, testing::Combine(
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4)),
ALL_MORPH_OPS));
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// Filter2D // Filter2D
GPU_PERF_TEST(Filter2D, cv::gpu::DeviceInfo, cv::Size, MatType, KernelSize) PERF_TEST_P(Sz_Type_KernelSz, Filters_Filter2D, Combine(GPU_TYPICAL_MAT_SIZES, Values(CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4), Values(3, 5, 7, 9, 11, 13, 15)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int type = GET_PARAM(1);
int ksize = GET_PARAM(2);
cv::Size size = GET_PARAM(1); cv::Mat src(size, type);
int type = GET_PARAM(2); fillRandom(src);
int ksize = GET_PARAM(3);
cv::Mat src_host(size, type);
fill(src_host, 0.0, 255.0);
cv::Mat kernel(ksize, ksize, CV_32FC1); cv::Mat kernel(ksize, ksize, CV_32FC1);
fill(kernel, 0.0, 1.0); fillRandom(kernel, 0.0, 1.0);
cv::gpu::GpuMat src(src_host); cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat dst; cv::gpu::GpuMat d_dst;
cv::gpu::filter2D(src, dst, -1, kernel); cv::gpu::filter2D(d_src, d_dst, -1, kernel);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::filter2D(src, dst, -1, kernel); cv::gpu::filter2D(d_src, d_dst, -1, kernel);
} }
} }
INSTANTIATE_TEST_CASE_P(Filters, Filter2D, testing::Combine( } // namespace
ALL_DEVICES,
GPU_TYPICAL_MAT_SIZES,
testing::Values(MatType(CV_8UC1), MatType(CV_8UC4), MatType(CV_32FC1), MatType(CV_32FC4)),
testing::Values(KernelSize(3), KernelSize(5), KernelSize(7), KernelSize(9), KernelSize(11), KernelSize(13), KernelSize(15))));
#endif

File diff suppressed because it is too large Load Diff

View File

@ -41,14 +41,16 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
#ifdef HAVE_CUDA using namespace std;
using namespace testing;
GPU_PERF_TEST(ConnectedComponents, cv::gpu::DeviceInfo, cv::Size) namespace {
DEF_PARAM_TEST_1(Image, string);
PERF_TEST_P(Image, Labeling_ConnectedComponents, Values<string>("gpu/labeling/aloe-disp.png"))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Mat image = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat image = readImage("gpu/labeling/aloe-disp.png", cv::IMREAD_GRAYSCALE);
// cv::threshold(image, image, 150, 255, CV_THRESH_BINARY); // 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)))); } // namespace
#endif

View File

@ -2,11 +2,98 @@
#ifdef HAVE_CUDA #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) 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); testing::InitGoogleTest(&argc, argv);
perf::TestBase::Init(argc, argv); perf::TestBase::Init(argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
return 0;
} }
#else #else

View File

@ -1,141 +1,115 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
#ifdef HAVE_CUDA using namespace std;
using namespace testing;
namespace {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// SetTo // 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::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int depth = GET_PARAM(1);
int channels = GET_PARAM(2);
cv::Size size = GET_PARAM(1); int type = CV_MAKE_TYPE(depth, channels);
int type = GET_PARAM(2);
cv::gpu::GpuMat src(size, type);
cv::Scalar val(1, 2, 3, 4); cv::Scalar val(1, 2, 3, 4);
src.setTo(val); cv::gpu::GpuMat d_src(size, type);
d_src.setTo(val);
TEST_CYCLE() 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 // 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::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int depth = GET_PARAM(1);
int channels = GET_PARAM(2);
cv::Size size = GET_PARAM(1); int type = CV_MAKE_TYPE(depth, channels);
int type = GET_PARAM(2);
cv::Mat src_host(size, type); cv::Mat src(size, type);
fill(src_host, 0, 255); fillRandom(src);
cv::Mat mask_host(size, CV_8UC1); cv::Mat mask(size, CV_8UC1);
fill(mask_host, 0, 2); fillRandom(mask, 0, 2);
cv::gpu::GpuMat src(src_host);
cv::Scalar val(1, 2, 3, 4); 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() 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 // 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::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int depth = GET_PARAM(1);
int channels = GET_PARAM(2);
cv::Size size = GET_PARAM(1); int type = CV_MAKE_TYPE(depth, channels);
int type = GET_PARAM(2);
cv::Mat src_host(size, type); cv::Mat src(size, type);
fill(src_host, 0, 255); fillRandom(src);
cv::Mat mask_host(size, CV_8UC1); cv::Mat mask(size, CV_8UC1);
fill(mask_host, 0, 2); fillRandom(mask, 0, 2);
cv::gpu::GpuMat src(src_host); cv::gpu::GpuMat d_src(src);
cv::gpu::GpuMat mask(mask_host); cv::gpu::GpuMat d_mask(mask);
cv::gpu::GpuMat dst; cv::gpu::GpuMat d_dst;
src.copyTo(dst, mask); d_src.copyTo(d_dst, d_mask);
TEST_CYCLE() 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 // ConvertTo
GPU_PERF_TEST(ConvertTo, cv::gpu::DeviceInfo, cv::Size, MatDepth, MatDepth) DEF_PARAM_TEST(Sz_2Depth, cv::Size, MatDepth, MatDepth);
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::gpu::DeviceInfo devInfo = GET_PARAM(0); cv::Size size = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID()); int depth1 = GET_PARAM(1);
int depth2 = GET_PARAM(2);
cv::Size size = GET_PARAM(1); cv::Mat src(size, depth1);
int depth1 = GET_PARAM(2); fillRandom(src);
int depth2 = GET_PARAM(3);
cv::Mat src_host(size, depth1); cv::gpu::GpuMat d_src(src);
fill(src_host, 0, 255); cv::gpu::GpuMat d_dst;
cv::gpu::GpuMat src(src_host); d_src.convertTo(d_dst, depth2, 0.5, 1.0);
cv::gpu::GpuMat dst;
src.convertTo(dst, depth2, 0.5, 1.0);
TEST_CYCLE() 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( } // namespace
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

View File

@ -1,85 +1,84 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
#ifdef HAVE_CUDA using namespace std;
using namespace testing;
namespace {
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// HOG // HOG
GPU_PERF_TEST_1(HOG, cv::gpu::DeviceInfo) DEF_PARAM_TEST_1(Image, string);
PERF_TEST_P(Image, ObjDetect_HOG, Values<string>("gpu/hog/road.png"))
{ {
cv::gpu::DeviceInfo devInfo = GetParam(); cv::Mat img = readImage(GetParam(), cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID()); ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/hog/road.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(img_host.empty());
cv::gpu::GpuMat img(img_host);
std::vector<cv::Rect> found_locations; std::vector<cv::Rect> found_locations;
cv::gpu::HOGDescriptor hog; cv::gpu::GpuMat d_img(img);
hog.setSVMDetector(cv::gpu::HOGDescriptor::getDefaultPeopleDetector());
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() TEST_CYCLE()
{ {
hog.detectMultiScale(img, found_locations); d_hog.detectMultiScale(d_img, found_locations);
} }
} }
INSTANTIATE_TEST_CASE_P(ObjDetect, HOG, ALL_DEVICES);
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// HaarClassifier // HaarClassifier
GPU_PERF_TEST_1(HaarClassifier, cv::gpu::DeviceInfo) typedef pair<string, string> pair_string;
DEF_PARAM_TEST_1(ImageAndCascade, pair_string);
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::gpu::DeviceInfo devInfo = GetParam(); cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID()); ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/haarcascade/group_1_640x480_VGA.pgm", cv::IMREAD_GRAYSCALE); cv::gpu::CascadeClassifier_GPU d_cascade;
ASSERT_FALSE(img_host.empty());
cv::gpu::CascadeClassifier_GPU cascade; ASSERT_TRUE(d_cascade.load(perf::TestBase::getDataPath(GetParam().second)));
ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/perf/haarcascade_frontalface_alt.xml"))); cv::gpu::GpuMat d_img(img);
cv::gpu::GpuMat d_objects_buffer;
cv::gpu::GpuMat img(img_host); d_cascade.detectMultiScale(d_img, d_objects_buffer);
cv::gpu::GpuMat objects_buffer;
cascade.detectMultiScale(img, objects_buffer);
TEST_CYCLE() 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 ==========================// PERF_TEST_P(ImageAndCascade, ObjDetect_LBPClassifier,
GPU_PERF_TEST_1(LBPClassifier, cv::gpu::DeviceInfo) Values<pair_string>(make_pair("gpu/haarcascade/group_1_640x480_VGA.pgm", "gpu/lbpcascade/lbpcascade_frontalface.xml")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam(); cv::Mat img = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID()); ASSERT_FALSE(img.empty());
cv::Mat img_host = readImage("gpu/haarcascade/group_1_640x480_VGA.pgm", cv::IMREAD_GRAYSCALE); cv::gpu::CascadeClassifier_GPU d_cascade;
ASSERT_FALSE(img_host.empty());
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); d_cascade.detectMultiScale(d_img, d_gpu_rects);
cv::gpu::GpuMat gpu_rects;
cv::gpu::CascadeClassifier_GPU cascade;
ASSERT_TRUE(cascade.load(perf::TestBase::getDataPath("gpu/lbpcascade/lbpcascade_frontalface.xml")));
cascade.detectMultiScale(img, gpu_rects);
TEST_CYCLE() TEST_CYCLE()
{ {
cascade.detectMultiScale(img, gpu_rects); d_cascade.detectMultiScale(d_img, d_gpu_rects);
} }
} }
INSTANTIATE_TEST_CASE_P(ObjDetect, LBPClassifier, ALL_DEVICES); } // namespace
#endif

View File

@ -11,6 +11,10 @@
#include "cvconfig.h" #include "cvconfig.h"
#ifdef HAVE_CUDA
#include <cuda_runtime.h>
#endif
#include "opencv2/ts/ts.hpp" #include "opencv2/ts/ts.hpp"
#include "opencv2/ts/ts_perf.hpp" #include "opencv2/ts/ts_perf.hpp"
@ -18,6 +22,10 @@
#include "opencv2/highgui/highgui.hpp" #include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp" #include "opencv2/gpu/gpu.hpp"
#include "opencv2/calib3d/calib3d.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" #include "perf_utility.hpp"

View File

@ -4,12 +4,17 @@ using namespace std;
using namespace cv; using namespace cv;
using namespace cv::gpu; using namespace cv::gpu;
void fill(Mat& m, double a, double b) void fillRandom(Mat& m, double a, double b)
{ {
RNG rng(123456789); RNG rng(123456789);
rng.fill(m, RNG::UNIFORM, Scalar::all(a), Scalar::all(b)); 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) void PrintTo(const CvtColorInfo& info, ostream* os)
{ {
static const char* str[] = static const char* str[] =
@ -184,37 +189,3 @@ void PrintTo(const CvtColorInfo& info, ostream* os)
*os << str[info.code]; *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;
}

View File

@ -1,13 +1,21 @@
#ifndef __OPENCV_PERF_GPU_UTILITY_HPP__ #ifndef __OPENCV_PERF_GPU_UTILITY_HPP__
#define __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::MatType;
using perf::MatDepth; using perf::MatDepth;
CV_ENUM(BorderMode, cv::BORDER_REFLECT101, cv::BORDER_REPLICATE, cv::BORDER_CONSTANT, cv::BORDER_REFLECT, cv::BORDER_WRAP) 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) CV_ENUM(NormType, cv::NORM_INF, cv::NORM_L1, cv::NORM_L2, cv::NORM_HAMMING)
struct CvtColorInfo 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_) {} 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); 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);
const std::vector<cv::gpu::DeviceInfo>& devices();
#define ALL_DEVICES testing::ValuesIn(devices())
#define GET_PARAM(k) std::tr1::get< k >(GetParam()) #define GET_PARAM(k) std::tr1::get< k >(GetParam())
#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
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 GPU_TYPICAL_MAT_SIZES testing::Values(perf::szSXGA, perf::sz720p, perf::sz1080p)
#endif // __OPENCV_PERF_GPU_UTILITY_HPP__ #endif // __OPENCV_PERF_GPU_UTILITY_HPP__

View File

@ -1,305 +1,277 @@
#include "perf_precomp.hpp" #include "perf_precomp.hpp"
#ifdef HAVE_CUDA using namespace std;
using namespace testing;
namespace {
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// BroxOpticalFlow // BroxOpticalFlow
GPU_PERF_TEST_1(BroxOpticalFlow, cv::gpu::DeviceInfo) typedef pair<string, string> pair_string;
DEF_PARAM_TEST_1(ImagePair, pair_string);
PERF_TEST_P(ImagePair, Video_BroxOpticalFlow, Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam(); declare.time(10);
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame0_host.empty()); ASSERT_FALSE(frame0.empty());
cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE); cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame1_host.empty()); ASSERT_FALSE(frame1.empty());
frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0); frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0);
frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0); frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0);
cv::gpu::GpuMat frame0(frame0_host); cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat frame1(frame1_host); cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat u; cv::gpu::GpuMat d_u;
cv::gpu::GpuMat v; cv::gpu::GpuMat d_v;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/); 10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(frame0, frame1, u, v); d_flow(d_frame0, d_frame1, d_u, d_v);
declare.time(10);
TEST_CYCLE() TEST_CYCLE()
{ {
d_flow(frame0, frame1, u, v); d_flow(d_frame0, d_frame1, d_u, d_v);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, BroxOpticalFlow, ALL_DEVICES);
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// InterpolateFrames // InterpolateFrames
GPU_PERF_TEST_1(InterpolateFrames, cv::gpu::DeviceInfo) PERF_TEST_P(ImagePair, Video_InterpolateFrames, Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam(); cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID()); ASSERT_FALSE(frame0.empty());
cv::Mat frame0_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame0_host.empty()); ASSERT_FALSE(frame1.empty());
cv::Mat frame1_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE); frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0);
ASSERT_FALSE(frame1_host.empty()); frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0);
frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0); cv::gpu::GpuMat d_frame0(frame0);
frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0); cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_fu, d_fv;
cv::gpu::GpuMat frame0(frame0_host); cv::gpu::GpuMat d_bu, d_bv;
cv::gpu::GpuMat frame1(frame1_host);
cv::gpu::GpuMat fu, fv;
cv::gpu::GpuMat bu, bv;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/); 10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(frame0, frame1, fu, fv); d_flow(d_frame0, d_frame1, d_fu, d_fv);
d_flow(frame1, frame0, bu, bv); d_flow(d_frame1, d_frame0, d_bu, d_bv);
cv::gpu::GpuMat newFrame; cv::gpu::GpuMat d_newFrame;
cv::gpu::GpuMat buf; cv::gpu::GpuMat d_buf;
cv::gpu::interpolateFrames(frame0, frame1, fu, fv, bu, bv, 0.5f, newFrame, buf); cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::interpolateFrames(frame0, frame1, fu, fv, bu, bv, 0.5f, newFrame, buf); cv::gpu::interpolateFrames(d_frame0, d_frame1, d_fu, d_fv, d_bu, d_bv, 0.5f, d_newFrame, d_buf);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, InterpolateFrames, ALL_DEVICES);
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// CreateOpticalFlowNeedleMap // CreateOpticalFlowNeedleMap
GPU_PERF_TEST_1(CreateOpticalFlowNeedleMap, cv::gpu::DeviceInfo) PERF_TEST_P(ImagePair, Video_CreateOpticalFlowNeedleMap, Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam(); cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
cv::gpu::setDevice(devInfo.deviceID()); ASSERT_FALSE(frame0.empty());
cv::Mat frame0_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame0_host.empty()); ASSERT_FALSE(frame1.empty());
cv::Mat frame1_host = readImage("gpu/perf/aloeR.jpg", cv::IMREAD_GRAYSCALE); frame0.convertTo(frame0, CV_32FC1, 1.0 / 255.0);
ASSERT_FALSE(frame1_host.empty()); frame1.convertTo(frame1, CV_32FC1, 1.0 / 255.0);
frame0_host.convertTo(frame0_host, CV_32FC1, 1.0 / 255.0); cv::gpu::GpuMat d_frame0(frame0);
frame1_host.convertTo(frame1_host, CV_32FC1, 1.0 / 255.0); cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat frame0(frame0_host); cv::gpu::GpuMat d_v;
cv::gpu::GpuMat frame1(frame1_host);
cv::gpu::GpuMat u, v;
cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/, cv::gpu::BroxOpticalFlow d_flow(0.197f /*alpha*/, 50.0f /*gamma*/, 0.8f /*scale_factor*/,
10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/); 10 /*inner_iterations*/, 77 /*outer_iterations*/, 10 /*solver_iterations*/);
d_flow(frame0, frame1, u, v); d_flow(d_frame0, d_frame1, d_u, d_v);
cv::gpu::GpuMat vertex, colors; cv::gpu::GpuMat d_vertex, d_colors;
cv::gpu::createOpticalFlowNeedleMap(u, v, vertex, colors); cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors);
TEST_CYCLE() TEST_CYCLE()
{ {
cv::gpu::createOpticalFlowNeedleMap(u, v, vertex, colors); cv::gpu::createOpticalFlowNeedleMap(d_u, d_v, d_vertex, d_colors);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, CreateOpticalFlowNeedleMap, ALL_DEVICES);
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// GoodFeaturesToTrack // GoodFeaturesToTrack
IMPLEMENT_PARAM_CLASS(MinDistance, double) DEF_PARAM_TEST(Image_MinDistance, string, double);
GPU_PERF_TEST(GoodFeaturesToTrack, cv::gpu::DeviceInfo, MinDistance) PERF_TEST_P(Image_MinDistance, Video_GoodFeaturesToTrack, Combine(Values<string>("gpu/perf/aloe.jpg"), Values(0.0, 3.0)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); string fileName = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
double minDistance = GET_PARAM(1); double minDistance = GET_PARAM(1);
cv::Mat image_host = readImage("gpu/perf/aloe.jpg", cv::IMREAD_GRAYSCALE); cv::Mat image = readImage(fileName, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(image_host.empty()); ASSERT_FALSE(image.empty());
cv::gpu::GoodFeaturesToTrackDetector_GPU detector(8000, 0.01, minDistance); cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(8000, 0.01, minDistance);
cv::gpu::GpuMat image(image_host); cv::gpu::GpuMat d_image(image);
cv::gpu::GpuMat pts; cv::gpu::GpuMat d_pts;
detector(image, pts); d_detector(d_image, d_pts);
TEST_CYCLE() TEST_CYCLE()
{ {
detector(image, pts); d_detector(d_image, d_pts);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, GoodFeaturesToTrack, testing::Combine(
ALL_DEVICES,
testing::Values(MinDistance(0.0), MinDistance(3.0))));
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// PyrLKOpticalFlowSparse // PyrLKOpticalFlowSparse
IMPLEMENT_PARAM_CLASS(GraySource, bool) DEF_PARAM_TEST(ImagePair_Gray_NPts_WinSz_Levels_Iters, pair_string, bool, int, int, int, int);
IMPLEMENT_PARAM_CLASS(Points, int)
IMPLEMENT_PARAM_CLASS(WinSize, int)
IMPLEMENT_PARAM_CLASS(Levels, int)
IMPLEMENT_PARAM_CLASS(Iters, int)
GPU_PERF_TEST(PyrLKOpticalFlowSparse, cv::gpu::DeviceInfo, GraySource, Points, WinSize, Levels, Iters) PERF_TEST_P(ImagePair_Gray_NPts_WinSz_Levels_Iters, Video_PyrLKOpticalFlowSparse, Combine(
Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")),
Bool(),
Values(1000, 2000, 4000, 8000),
Values(9, 13, 17, 21),
Values(1, 2, 3),
Values(1, 10, 30)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); pair_string imagePair = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
bool useGray = GET_PARAM(1); bool useGray = GET_PARAM(1);
int points = GET_PARAM(2); int points = GET_PARAM(2);
int winSize = GET_PARAM(3); int winSize = GET_PARAM(3);
int levels = GET_PARAM(4); int levels = GET_PARAM(4);
int iters = GET_PARAM(5); int iters = GET_PARAM(5);
cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); cv::Mat frame0 = readImage(imagePair.first, useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
ASSERT_FALSE(frame0_host.empty()); ASSERT_FALSE(frame0.empty());
cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR); cv::Mat frame1 = readImage(imagePair.second, useGray ? cv::IMREAD_GRAYSCALE : cv::IMREAD_COLOR);
ASSERT_FALSE(frame1_host.empty()); ASSERT_FALSE(frame1.empty());
cv::Mat gray_frame; cv::Mat gray_frame;
if (useGray) if (useGray)
gray_frame = frame0_host; gray_frame = frame0;
else else
cv::cvtColor(frame0_host, gray_frame, cv::COLOR_BGR2GRAY); cv::cvtColor(frame0, gray_frame, cv::COLOR_BGR2GRAY);
cv::gpu::GpuMat pts; cv::gpu::GpuMat d_pts;
cv::gpu::GoodFeaturesToTrackDetector_GPU detector(points, 0.01, 0.0); cv::gpu::GoodFeaturesToTrackDetector_GPU d_detector(points, 0.01, 0.0);
detector(cv::gpu::GpuMat(gray_frame), pts); d_detector(cv::gpu::GpuMat(gray_frame), d_pts);
cv::gpu::PyrLKOpticalFlow pyrLK; cv::gpu::PyrLKOpticalFlow d_pyrLK;
pyrLK.winSize = cv::Size(winSize, winSize); d_pyrLK.winSize = cv::Size(winSize, winSize);
pyrLK.maxLevel = levels - 1; d_pyrLK.maxLevel = levels - 1;
pyrLK.iters = iters; d_pyrLK.iters = iters;
cv::gpu::GpuMat frame0(frame0_host); cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat frame1(frame1_host); cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat nextPts; cv::gpu::GpuMat d_nextPts;
cv::gpu::GpuMat status; cv::gpu::GpuMat d_status;
pyrLK.sparse(frame0, frame1, pts, nextPts, status); d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status);
TEST_CYCLE() TEST_CYCLE()
{ {
pyrLK.sparse(frame0, frame1, pts, nextPts, status); d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlowSparse, testing::Combine(
ALL_DEVICES,
testing::Values(GraySource(true), GraySource(false)),
testing::Values(Points(1000), Points(2000), Points(4000), Points(8000)),
testing::Values(WinSize(9), WinSize(13), WinSize(17), WinSize(21)),
testing::Values(Levels(1), Levels(2), Levels(3)),
testing::Values(Iters(1), Iters(10), Iters(30))));
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// PyrLKOpticalFlowDense // PyrLKOpticalFlowDense
GPU_PERF_TEST(PyrLKOpticalFlowDense, cv::gpu::DeviceInfo, WinSize, Levels, Iters) DEF_PARAM_TEST(ImagePair_WinSz_Levels_Iters, pair_string, int, int, int);
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
PERF_TEST_P(ImagePair_WinSz_Levels_Iters, Video_PyrLKOpticalFlowDense, Combine(
Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")),
Values(3, 5, 7, 9, 13, 17, 21),
Values(1, 2, 3),
Values(1, 10)))
{
declare.time(30);
pair_string imagePair = GET_PARAM(0);
int winSize = GET_PARAM(1); int winSize = GET_PARAM(1);
int levels = GET_PARAM(2); int levels = GET_PARAM(2);
int iters = GET_PARAM(3); int iters = GET_PARAM(3);
cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE); cv::Mat frame0 = readImage(imagePair.first, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame0_host.empty()); ASSERT_FALSE(frame0.empty());
cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE); cv::Mat frame1 = readImage(imagePair.second, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame1_host.empty()); ASSERT_FALSE(frame1.empty());
cv::gpu::GpuMat frame0(frame0_host); cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat frame1(frame1_host); cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat u; cv::gpu::GpuMat d_u;
cv::gpu::GpuMat v; cv::gpu::GpuMat d_v;
cv::gpu::PyrLKOpticalFlow pyrLK; cv::gpu::PyrLKOpticalFlow d_pyrLK;
d_pyrLK.winSize = cv::Size(winSize, winSize);
d_pyrLK.maxLevel = levels - 1;
d_pyrLK.iters = iters;
pyrLK.winSize = cv::Size(winSize, winSize); d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v);
pyrLK.maxLevel = levels - 1;
pyrLK.iters = iters;
pyrLK.dense(frame0, frame1, u, v);
declare.time(30);
TEST_CYCLE() TEST_CYCLE()
{ {
pyrLK.dense(frame0, frame1, u, v); d_pyrLK.dense(d_frame0, d_frame1, d_u, d_v);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, PyrLKOpticalFlowDense, testing::Combine(
ALL_DEVICES,
testing::Values(WinSize(3), WinSize(5), WinSize(7), WinSize(9), WinSize(13), WinSize(17), WinSize(21)),
testing::Values(Levels(1), Levels(2), Levels(3)),
testing::Values(Iters(1), Iters(10))));
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// FarnebackOpticalFlowTest // FarnebackOpticalFlow
GPU_PERF_TEST_1(FarnebackOpticalFlowTest, cv::gpu::DeviceInfo) PERF_TEST_P(ImagePair, Video_FarnebackOpticalFlow, Values<pair_string>(make_pair("gpu/opticalflow/frame0.png", "gpu/opticalflow/frame1.png")))
{ {
cv::gpu::DeviceInfo devInfo = GetParam();
cv::gpu::setDevice(devInfo.deviceID());
cv::Mat frame0_host = readImage("gpu/opticalflow/frame0.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame0_host.empty());
cv::Mat frame1_host = readImage("gpu/opticalflow/frame1.png", cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame1_host.empty());
cv::gpu::GpuMat frame0(frame0_host);
cv::gpu::GpuMat frame1(frame1_host);
cv::gpu::GpuMat u;
cv::gpu::GpuMat v;
cv::gpu::FarnebackOpticalFlow farneback;
farneback(frame0, frame1, u, v);
declare.time(10); declare.time(10);
cv::Mat frame0 = readImage(GetParam().first, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame0.empty());
cv::Mat frame1 = readImage(GetParam().second, cv::IMREAD_GRAYSCALE);
ASSERT_FALSE(frame1.empty());
cv::gpu::GpuMat d_frame0(frame0);
cv::gpu::GpuMat d_frame1(frame1);
cv::gpu::GpuMat d_u;
cv::gpu::GpuMat d_v;
cv::gpu::FarnebackOpticalFlow d_farneback;
d_farneback(d_frame0, d_frame1, d_u, d_v);
TEST_CYCLE() TEST_CYCLE()
{ {
farneback(frame0, frame1, u, v); d_farneback(d_frame0, d_frame1, d_u, d_v);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, FarnebackOpticalFlowTest, ALL_DEVICES);
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// FGDStatModel // FGDStatModel
GPU_PERF_TEST(FGDStatModel, cv::gpu::DeviceInfo, std::string) DEF_PARAM_TEST_1(Video, string);
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); PERF_TEST_P(Video, Video_FGDStatModel, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"))
{
declare.time(10);
string inputFile = perf::TestBase::getDataPath(GetParam());
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
@ -312,8 +284,6 @@ GPU_PERF_TEST(FGDStatModel, cv::gpu::DeviceInfo, std::string)
cv::gpu::FGDStatModel d_model(4); cv::gpu::FGDStatModel d_model(4);
d_model.create(d_frame); d_model.create(d_frame);
declare.time(10);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
cap >> frame; cap >> frame;
@ -327,23 +297,16 @@ GPU_PERF_TEST(FGDStatModel, cv::gpu::DeviceInfo, std::string)
} }
} }
INSTANTIATE_TEST_CASE_P(Video, FGDStatModel, testing::Combine(
ALL_DEVICES,
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// MOG // MOG
IMPLEMENT_PARAM_CLASS(LearningRate, double) DEF_PARAM_TEST(Video_Cn_LearningRate, string, int, double);
GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate) PERF_TEST_P(Video_Cn_LearningRate, Video_MOG, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4), Values(0.0, 0.01)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
cv::gpu::setDevice(devInfo.deviceID()); int cn = GET_PARAM(1);
double learningRate = GET_PARAM(2);
std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));
int cn = GET_PARAM(2);
double learningRate = GET_PARAM(3);
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
@ -351,8 +314,8 @@ GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate)
cv::Mat frame; cv::Mat frame;
cv::gpu::GpuMat d_frame; cv::gpu::GpuMat d_frame;
cv::gpu::MOG_GPU mog; cv::gpu::MOG_GPU d_mog;
cv::gpu::GpuMat foreground; cv::gpu::GpuMat d_foreground;
cap >> frame; cap >> frame;
ASSERT_FALSE(frame.empty()); ASSERT_FALSE(frame.empty());
@ -369,7 +332,7 @@ GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate)
d_frame.upload(frame); d_frame.upload(frame);
mog(d_frame, foreground, learningRate); d_mog(d_frame, d_foreground, learningRate);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
@ -389,27 +352,20 @@ GPU_PERF_TEST(MOG, cv::gpu::DeviceInfo, std::string, Channels, LearningRate)
d_frame.upload(frame); d_frame.upload(frame);
startTimer(); next(); startTimer(); next();
mog(d_frame, foreground, learningRate); d_mog(d_frame, d_foreground, learningRate);
stopTimer(); stopTimer();
} }
} }
INSTANTIATE_TEST_CASE_P(Video, MOG, testing::Combine(
ALL_DEVICES,
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),
testing::Values(Channels(1), Channels(3), Channels(4)),
testing::Values(LearningRate(0.0), LearningRate(0.01))));
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// MOG2 // MOG2
GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels) DEF_PARAM_TEST(Video_Cn, string, int);
{
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); PERF_TEST_P(Video_Cn, Video_MOG2, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4)))
int cn = GET_PARAM(2); {
string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
int cn = GET_PARAM(1);
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
@ -417,8 +373,8 @@ GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels)
cv::Mat frame; cv::Mat frame;
cv::gpu::GpuMat d_frame; cv::gpu::GpuMat d_frame;
cv::gpu::MOG2_GPU mog2; cv::gpu::MOG2_GPU d_mog2;
cv::gpu::GpuMat foreground; cv::gpu::GpuMat d_foreground;
cap >> frame; cap >> frame;
ASSERT_FALSE(frame.empty()); ASSERT_FALSE(frame.empty());
@ -435,7 +391,7 @@ GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels)
d_frame.upload(frame); d_frame.upload(frame);
mog2(d_frame, foreground); d_mog2(d_frame, d_foreground);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
@ -455,23 +411,18 @@ GPU_PERF_TEST(MOG2_update, cv::gpu::DeviceInfo, std::string, Channels)
d_frame.upload(frame); d_frame.upload(frame);
startTimer(); next(); startTimer(); next();
mog2(d_frame, foreground); d_mog2(d_frame, d_foreground);
stopTimer(); stopTimer();
} }
} }
INSTANTIATE_TEST_CASE_P(Video, MOG2_update, testing::Combine( //////////////////////////////////////////////////////
ALL_DEVICES, // MOG2GetBackgroundImage
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),
testing::Values(Channels(1), Channels(3), Channels(4))));
GPU_PERF_TEST(MOG2_getBackgroundImage, cv::gpu::DeviceInfo, std::string, Channels) PERF_TEST_P(Video_Cn, Video_MOG2GetBackgroundImage, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
cv::gpu::setDevice(devInfo.deviceID()); int cn = GET_PARAM(1);
std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));
int cn = GET_PARAM(2);
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
@ -479,8 +430,8 @@ GPU_PERF_TEST(MOG2_getBackgroundImage, cv::gpu::DeviceInfo, std::string, Channel
cv::Mat frame; cv::Mat frame;
cv::gpu::GpuMat d_frame; cv::gpu::GpuMat d_frame;
cv::gpu::MOG2_GPU mog2; cv::gpu::MOG2_GPU d_mog2;
cv::gpu::GpuMat foreground; cv::gpu::GpuMat d_foreground;
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
@ -499,33 +450,25 @@ GPU_PERF_TEST(MOG2_getBackgroundImage, cv::gpu::DeviceInfo, std::string, Channel
d_frame.upload(frame); d_frame.upload(frame);
mog2(d_frame, foreground); d_mog2(d_frame, d_foreground);
} }
cv::gpu::GpuMat background; cv::gpu::GpuMat d_background;
mog2.getBackgroundImage(background); d_mog2.getBackgroundImage(d_background);
TEST_CYCLE() TEST_CYCLE()
{ {
mog2.getBackgroundImage(background); d_mog2.getBackgroundImage(d_background);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, MOG2_getBackgroundImage, testing::Combine(
ALL_DEVICES,
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),
testing::Values(Channels(1), Channels(3), Channels(4))));
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// VIBE // VIBE
GPU_PERF_TEST(VIBE, cv::gpu::DeviceInfo, std::string, Channels) PERF_TEST_P(Video_Cn, Video_VIBE, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
cv::gpu::setDevice(devInfo.deviceID()); int cn = GET_PARAM(1);
std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));
int cn = GET_PARAM(2);
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
@ -545,10 +488,10 @@ GPU_PERF_TEST(VIBE, cv::gpu::DeviceInfo, std::string, Channels)
} }
cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_frame(frame);
cv::gpu::VIBE_GPU vibe; cv::gpu::VIBE_GPU d_vibe;
cv::gpu::GpuMat foreground; cv::gpu::GpuMat d_foreground;
vibe(d_frame, foreground); d_vibe(d_frame, d_foreground);
for (int i = 0; i < 10; ++i) for (int i = 0; i < 10; ++i)
{ {
@ -568,28 +511,21 @@ GPU_PERF_TEST(VIBE, cv::gpu::DeviceInfo, std::string, Channels)
d_frame.upload(frame); d_frame.upload(frame);
startTimer(); next(); startTimer(); next();
vibe(d_frame, foreground); d_vibe(d_frame, d_foreground);
stopTimer(); stopTimer();
} }
} }
INSTANTIATE_TEST_CASE_P(Video, VIBE, testing::Combine(
ALL_DEVICES,
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),
testing::Values(Channels(1), Channels(3), Channels(4))));
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// GMG // GMG
IMPLEMENT_PARAM_CLASS(MaxFeatures, int) DEF_PARAM_TEST(Video_Cn_MaxFeatures, string, int, int);
GPU_PERF_TEST(GMG, cv::gpu::DeviceInfo, std::string, Channels, MaxFeatures) PERF_TEST_P(Video_Cn_MaxFeatures, Video_GMG, Combine(Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"), Values(1, 3, 4), Values(20, 40, 60)))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0); std::string inputFile = perf::TestBase::getDataPath(GET_PARAM(0));
cv::gpu::setDevice(devInfo.deviceID()); int cn = GET_PARAM(1);
std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1)); int maxFeatures = GET_PARAM(2);
int cn = GET_PARAM(2);
int maxFeatures = GET_PARAM(3);
cv::VideoCapture cap(inputFile); cv::VideoCapture cap(inputFile);
ASSERT_TRUE(cap.isOpened()); ASSERT_TRUE(cap.isOpened());
@ -611,10 +547,10 @@ GPU_PERF_TEST(GMG, cv::gpu::DeviceInfo, std::string, Channels, MaxFeatures)
cv::gpu::GpuMat d_frame(frame); cv::gpu::GpuMat d_frame(frame);
cv::gpu::GpuMat d_fgmask; cv::gpu::GpuMat d_fgmask;
cv::gpu::GMG_GPU gmg; cv::gpu::GMG_GPU d_gmg;
gmg.maxFeatures = maxFeatures; d_gmg.maxFeatures = maxFeatures;
gmg(d_frame, d_fgmask); d_gmg(d_frame, d_fgmask);
for (int i = 0; i < 150; ++i) for (int i = 0; i < 150; ++i)
{ {
@ -638,32 +574,21 @@ GPU_PERF_TEST(GMG, cv::gpu::DeviceInfo, std::string, Channels, MaxFeatures)
d_frame.upload(frame); d_frame.upload(frame);
startTimer(); next(); startTimer(); next();
gmg(d_frame, d_fgmask); d_gmg(d_frame, d_fgmask);
stopTimer(); stopTimer();
} }
} }
INSTANTIATE_TEST_CASE_P(Video, GMG, testing::Combine(
ALL_DEVICES,
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi")),
testing::Values(Channels(1), Channels(3), Channels(4)),
testing::Values(MaxFeatures(20), MaxFeatures(40), MaxFeatures(60))));
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// VideoWriter // VideoWriter
#ifdef WIN32 PERF_TEST_P(Video, Video_VideoWriter, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"))
GPU_PERF_TEST(VideoWriter, cv::gpu::DeviceInfo, std::string)
{ {
string inputFile = perf::TestBase::getDataPath(GetParam());
string outputFile = cv::tempfile(".avi");
const double FPS = 25.0; const double FPS = 25.0;
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));
std::string outputFile = cv::tempfile(".avi");
cv::VideoCapture reader(inputFile); cv::VideoCapture reader(inputFile);
ASSERT_TRUE( reader.isOpened() ); ASSERT_TRUE( reader.isOpened() );
@ -690,39 +615,26 @@ GPU_PERF_TEST(VideoWriter, cv::gpu::DeviceInfo, std::string)
} }
} }
INSTANTIATE_TEST_CASE_P(Video, VideoWriter, testing::Combine(
ALL_DEVICES,
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));
#endif // WIN32
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// VideoReader // VideoReader
GPU_PERF_TEST(VideoReader, cv::gpu::DeviceInfo, std::string) PERF_TEST_P(Video, Video_VideoReader, Values("gpu/video/768x576.avi", "gpu/video/1920x1080.avi"))
{ {
cv::gpu::DeviceInfo devInfo = GET_PARAM(0);
cv::gpu::setDevice(devInfo.deviceID());
std::string inputFile = perf::TestBase::getDataPath(std::string("gpu/video/") + GET_PARAM(1));
cv::gpu::VideoReader_GPU reader(inputFile);
ASSERT_TRUE( reader.isOpened() );
cv::gpu::GpuMat frame;
reader.read(frame);
declare.time(20); declare.time(20);
string inputFile = perf::TestBase::getDataPath(GetParam());
cv::gpu::VideoReader_GPU d_reader(inputFile);
ASSERT_TRUE( d_reader.isOpened() );
cv::gpu::GpuMat d_frame;
d_reader.read(d_frame);
TEST_CYCLE_N(10) TEST_CYCLE_N(10)
{ {
reader.read(frame); d_reader.read(d_frame);
} }
} }
INSTANTIATE_TEST_CASE_P(Video, VideoReader, testing::Combine( } // namespace
ALL_DEVICES,
testing::Values(std::string("768x576.avi"), std::string("1920x1080.avi"))));
#endif