opencv/samples/gpu/performance/tests.cpp

1301 lines
28 KiB
C++
Raw Normal View History

2012-10-17 07:18:30 +08:00
#include <stdexcept>
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/calib3d.hpp"
#include "opencv2/video.hpp"
#include "opencv2/cudalegacy.hpp"
2013-07-23 20:59:34 +08:00
#include "opencv2/cudaimgproc.hpp"
2013-07-23 19:24:10 +08:00
#include "opencv2/cudaarithm.hpp"
2013-07-23 19:57:59 +08:00
#include "opencv2/cudawarping.hpp"
#include "opencv2/cudafeatures2d.hpp"
2013-07-23 20:24:55 +08:00
#include "opencv2/cudafilters.hpp"
2013-07-23 21:04:38 +08:00
#include "opencv2/cudaoptflow.hpp"
2013-07-24 14:44:39 +08:00
#include "opencv2/cudabgsegm.hpp"
2012-10-17 07:18:30 +08:00
#include "performance.h"
#include "opencv2/opencv_modules.hpp"
2013-07-23 17:19:54 +08:00
#ifdef HAVE_OPENCV_XFEATURES2D
#include "opencv2/xfeatures2d/cuda.hpp"
#include "opencv2/xfeatures2d/nonfree.hpp"
#endif
#ifdef HAVE_OPENCV_BGSEGM
#include "opencv2/bgsegm.hpp"
#endif
2012-10-17 07:18:30 +08:00
using namespace std;
using namespace cv;
TEST(matchTemplate)
{
Mat src, templ, dst;
gen(src, 3000, 3000, CV_32F, 0, 1);
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src), d_templ, d_dst;
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
Ptr<cuda::TemplateMatching> alg = cuda::createTemplateMatching(src.type(), TM_CCORR);
2012-10-17 07:18:30 +08:00
for (int templ_size = 5; templ_size < 200; templ_size *= 5)
{
SUBTEST << src.cols << 'x' << src.rows << ", 32FC1" << ", templ " << templ_size << 'x' << templ_size << ", CCORR";
gen(templ, templ_size, templ_size, CV_32F, 0, 1);
matchTemplate(src, templ, dst, TM_CCORR);
2012-10-17 07:18:30 +08:00
CPU_ON;
matchTemplate(src, templ, dst, TM_CCORR);
2012-10-17 07:18:30 +08:00
CPU_OFF;
d_templ.upload(templ);
alg->match(d_src, d_templ, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
alg->match(d_src, d_templ, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(minMaxLoc)
{
Mat src;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src;
2012-10-17 07:18:30 +08:00
double min_val, max_val;
Point min_loc, max_loc;
for (int size = 2000; size <= 8000; size *= 2)
{
SUBTEST << size << 'x' << size << ", 32F";
gen(src, size, size, CV_32F, 0, 1);
CPU_ON;
minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc);
CPU_OFF;
d_src.upload(src);
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::minMaxLoc(d_src, &min_val, &max_val, &min_loc, &max_loc);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(remap)
{
Mat src, dst, xmap, ymap;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst, d_xmap, d_ymap;
2012-10-17 07:18:30 +08:00
int interpolation = INTER_LINEAR;
int borderMode = BORDER_REPLICATE;
for (int size = 1000; size <= 4000; size *= 2)
{
SUBTEST << size << 'x' << size << ", 8UC4, INTER_LINEAR, BORDER_REPLICATE";
gen(src, size, size, CV_8UC4, 0, 256);
xmap.create(size, size, CV_32F);
ymap.create(size, size, CV_32F);
for (int i = 0; i < size; ++i)
{
float* xmap_row = xmap.ptr<float>(i);
float* ymap_row = ymap.ptr<float>(i);
for (int j = 0; j < size; ++j)
{
xmap_row[j] = (j - size * 0.5f) * 0.75f + size * 0.5f;
ymap_row[j] = (i - size * 0.5f) * 0.75f + size * 0.5f;
}
}
remap(src, dst, xmap, ymap, interpolation, borderMode);
CPU_ON;
remap(src, dst, xmap, ymap, interpolation, borderMode);
CPU_OFF;
d_src.upload(src);
d_xmap.upload(xmap);
d_ymap.upload(ymap);
2013-08-28 19:45:13 +08:00
cuda::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(dft)
{
Mat src, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 1000; size <= 4000; size *= 2)
{
SUBTEST << size << 'x' << size << ", 32FC2, complex-to-complex";
gen(src, size, size, CV_32FC2, Scalar::all(0), Scalar::all(1));
dft(src, dst);
CPU_ON;
dft(src, dst);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::dft(d_src, d_dst, Size(size, size));
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::dft(d_src, d_dst, Size(size, size));
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(cornerHarris)
{
Mat src, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 1000; size <= 4000; size *= 2)
{
SUBTEST << size << 'x' << size << ", 32FC1, BORDER_REFLECT101";
gen(src, size, size, CV_32F, 0, 1);
cornerHarris(src, dst, 5, 7, 0.1, BORDER_REFLECT101);
CPU_ON;
cornerHarris(src, dst, 5, 7, 0.1, BORDER_REFLECT101);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
Ptr<cuda::CornernessCriteria> harris = cuda::createHarrisCorner(src.type(), 5, 7, 0.1, BORDER_REFLECT101);
harris->compute(d_src, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
harris->compute(d_src, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(integral)
{
Mat src, sum;
cuda::GpuMat d_src, d_sum;
2012-10-17 07:18:30 +08:00
for (int size = 1000; size <= 4000; size *= 2)
{
SUBTEST << size << 'x' << size << ", 8UC1";
gen(src, size, size, CV_8U, 0, 256);
integral(src, sum);
CPU_ON;
integral(src, sum);
CPU_OFF;
d_src.upload(src);
cuda::integral(d_src, d_sum);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
cuda::integral(d_src, d_sum);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(norm)
{
Mat src;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_buf;
2012-10-17 07:18:30 +08:00
for (int size = 2000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 32FC4, NORM_INF";
gen(src, size, size, CV_32FC4, Scalar::all(0), Scalar::all(1));
norm(src, NORM_INF);
CPU_ON;
norm(src, NORM_INF);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::norm(d_src, NORM_INF, d_buf);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::norm(d_src, NORM_INF, d_buf);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(meanShift)
{
int sp = 10, sr = 10;
Mat src, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 400; size <= 800; size *= 2)
{
SUBTEST << size << 'x' << size << ", 8UC3 vs 8UC4";
gen(src, size, size, CV_8UC3, Scalar::all(0), Scalar::all(256));
pyrMeanShiftFiltering(src, dst, sp, sr);
CPU_ON;
pyrMeanShiftFiltering(src, dst, sp, sr);
CPU_OFF;
gen(src, size, size, CV_8UC4, Scalar::all(0), Scalar::all(256));
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::meanShiftFiltering(d_src, d_dst, sp, sr);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::meanShiftFiltering(d_src, d_dst, sp, sr);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
#ifdef HAVE_OPENCV_XFEATURES2D
2012-10-17 07:18:30 +08:00
TEST(SURF)
{
2014-09-13 22:28:41 +08:00
Mat src = imread(abspath("../data/aloeL.jpg"), IMREAD_GRAYSCALE);
if (src.empty()) throw runtime_error("can't open ../data/aloeL.jpg");
2012-10-17 07:18:30 +08:00
Ptr<Feature2D> surf = xfeatures2d::SURF::create();
2012-10-17 07:18:30 +08:00
vector<KeyPoint> keypoints;
Mat descriptors;
surf->detectAndCompute(src, Mat(), keypoints, descriptors);
2012-10-17 07:18:30 +08:00
CPU_ON;
surf->detectAndCompute(src, Mat(), keypoints, descriptors);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-07-24 17:55:18 +08:00
cuda::SURF_CUDA d_surf;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_keypoints;
cuda::GpuMat d_descriptors;
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
d_surf(d_src, cuda::GpuMat(), d_keypoints, d_descriptors);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
d_surf(d_src, cuda::GpuMat(), d_keypoints, d_descriptors);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
#endif
2012-10-17 07:18:30 +08:00
TEST(FAST)
{
2014-09-13 22:28:41 +08:00
Mat src = imread(abspath("../data/aloeL.jpg"), IMREAD_GRAYSCALE);
if (src.empty()) throw runtime_error("can't open ../data/aloeL.jpg");
2012-10-17 07:18:30 +08:00
vector<KeyPoint> keypoints;
FAST(src, keypoints, 20);
CPU_ON;
FAST(src, keypoints, 20);
CPU_OFF;
cv::Ptr<cv::cuda::FastFeatureDetector> d_FAST = cv::cuda::FastFeatureDetector::create(20);
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_keypoints;
2012-10-17 07:18:30 +08:00
d_FAST->detectAsync(d_src, d_keypoints);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
d_FAST->detectAsync(d_src, d_keypoints);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
TEST(ORB)
{
2014-09-13 22:28:41 +08:00
Mat src = imread(abspath("../data/aloeL.jpg"), IMREAD_GRAYSCALE);
if (src.empty()) throw runtime_error("can't open ../data/aloeL.jpg");
2012-10-17 07:18:30 +08:00
2014-11-12 23:06:47 +08:00
Ptr<ORB> orb = ORB::create(4000);
2012-10-17 07:18:30 +08:00
vector<KeyPoint> keypoints;
Mat descriptors;
2014-11-12 23:06:47 +08:00
orb->detectAndCompute(src, Mat(), keypoints, descriptors);
2012-10-17 07:18:30 +08:00
CPU_ON;
2014-11-12 23:06:47 +08:00
orb->detectAndCompute(src, Mat(), keypoints, descriptors);
2012-10-17 07:18:30 +08:00
CPU_OFF;
Ptr<cuda::ORB> d_orb = cuda::ORB::create();
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_keypoints;
cuda::GpuMat d_descriptors;
2012-10-17 07:18:30 +08:00
d_orb->detectAndComputeAsync(d_src, cuda::GpuMat(), d_keypoints, d_descriptors);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
d_orb->detectAndComputeAsync(d_src, cuda::GpuMat(), d_keypoints, d_descriptors);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
TEST(BruteForceMatcher)
{
// Init CPU matcher
int desc_len = 64;
BFMatcher matcher(NORM_L2);
Mat query;
gen(query, 3000, desc_len, CV_32F, 0, 1);
Mat train;
gen(train, 3000, desc_len, CV_32F, 0, 1);
2013-07-24 17:55:18 +08:00
// Init CUDA matcher
2012-10-17 07:18:30 +08:00
Ptr<cuda::DescriptorMatcher> d_matcher = cuda::DescriptorMatcher::createBFMatcher(NORM_L2);
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_query(query);
cuda::GpuMat d_train(train);
2012-10-17 07:18:30 +08:00
// Output
vector< vector<DMatch> > matches(2);
cuda::GpuMat d_matches;
2012-10-17 07:18:30 +08:00
SUBTEST << "match";
matcher.match(query, train, matches[0]);
CPU_ON;
matcher.match(query, train, matches[0]);
CPU_OFF;
d_matcher->matchAsync(d_query, d_train, d_matches);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
d_matcher->matchAsync(d_query, d_train, d_matches);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
SUBTEST << "knnMatch";
matcher.knnMatch(query, train, matches, 2);
CPU_ON;
matcher.knnMatch(query, train, matches, 2);
CPU_OFF;
d_matcher->knnMatchAsync(d_query, d_train, d_matches, 2);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
d_matcher->knnMatchAsync(d_query, d_train, d_matches, 2);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
SUBTEST << "radiusMatch";
float max_distance = 2.0f;
matcher.radiusMatch(query, train, matches, max_distance);
CPU_ON;
matcher.radiusMatch(query, train, matches, max_distance);
CPU_OFF;
d_matcher->radiusMatchAsync(d_query, d_train, d_matches, max_distance);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
d_matcher->radiusMatchAsync(d_query, d_train, d_matches, max_distance);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
TEST(magnitude)
{
Mat x, y, mag;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_x, d_y, d_mag;
2012-10-17 07:18:30 +08:00
for (int size = 2000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 32FC1";
gen(x, size, size, CV_32F, 0, 1);
gen(y, size, size, CV_32F, 0, 1);
magnitude(x, y, mag);
CPU_ON;
magnitude(x, y, mag);
CPU_OFF;
d_x.upload(x);
d_y.upload(y);
2013-08-28 19:45:13 +08:00
cuda::magnitude(d_x, d_y, d_mag);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::magnitude(d_x, d_y, d_mag);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(add)
{
Mat src1, src2, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src1, d_src2, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 2000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 32FC1";
gen(src1, size, size, CV_32F, 0, 1);
gen(src2, size, size, CV_32F, 0, 1);
add(src1, src2, dst);
CPU_ON;
add(src1, src2, dst);
CPU_OFF;
d_src1.upload(src1);
d_src2.upload(src2);
2013-08-28 19:45:13 +08:00
cuda::add(d_src1, d_src2, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::add(d_src1, d_src2, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(log)
{
Mat src, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 2000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 32F";
gen(src, size, size, CV_32F, 1, 10);
log(src, dst);
CPU_ON;
log(src, dst);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::log(d_src, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::log(d_src, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(mulSpectrums)
{
Mat src1, src2, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src1, d_src2, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 2000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size;
gen(src1, size, size, CV_32FC2, Scalar::all(0), Scalar::all(1));
gen(src2, size, size, CV_32FC2, Scalar::all(0), Scalar::all(1));
mulSpectrums(src1, src2, dst, 0, true);
CPU_ON;
mulSpectrums(src1, src2, dst, 0, true);
CPU_OFF;
d_src1.upload(src1);
d_src2.upload(src2);
2013-08-28 19:45:13 +08:00
cuda::mulSpectrums(d_src1, d_src2, d_dst, 0, true);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::mulSpectrums(d_src1, d_src2, d_dst, 0, true);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(resize)
{
Mat src, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 1000; size <= 3000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 8UC4, up";
gen(src, size, size, CV_8UC4, 0, 256);
resize(src, dst, Size(), 2.0, 2.0);
CPU_ON;
resize(src, dst, Size(), 2.0, 2.0);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::resize(d_src, d_dst, Size(), 2.0, 2.0);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::resize(d_src, d_dst, Size(), 2.0, 2.0);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
for (int size = 1000; size <= 3000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 8UC4, down";
gen(src, size, size, CV_8UC4, 0, 256);
resize(src, dst, Size(), 0.5, 0.5);
CPU_ON;
resize(src, dst, Size(), 0.5, 0.5);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::resize(d_src, d_dst, Size(), 0.5, 0.5);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::resize(d_src, d_dst, Size(), 0.5, 0.5);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(cvtColor)
{
Mat src, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
gen(src, 4000, 4000, CV_8UC1, 0, 255);
d_src.upload(src);
SUBTEST << "4000x4000, 8UC1, COLOR_GRAY2BGRA";
2012-10-17 07:18:30 +08:00
cvtColor(src, dst, COLOR_GRAY2BGRA, 4);
2012-10-17 07:18:30 +08:00
CPU_ON;
cvtColor(src, dst, COLOR_GRAY2BGRA, 4);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_GRAY2BGRA, 4);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_GRAY2BGRA, 4);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
cv::swap(src, dst);
d_src.swap(d_dst);
SUBTEST << "4000x4000, 8UC3 vs 8UC4, COLOR_BGR2YCrCb";
2012-10-17 07:18:30 +08:00
cvtColor(src, dst, COLOR_BGR2YCrCb);
2012-10-17 07:18:30 +08:00
CPU_ON;
cvtColor(src, dst, COLOR_BGR2YCrCb);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_BGR2YCrCb, 4);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_BGR2YCrCb, 4);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
cv::swap(src, dst);
d_src.swap(d_dst);
SUBTEST << "4000x4000, 8UC4, COLOR_YCrCb2BGR";
2012-10-17 07:18:30 +08:00
cvtColor(src, dst, COLOR_YCrCb2BGR, 4);
2012-10-17 07:18:30 +08:00
CPU_ON;
cvtColor(src, dst, COLOR_YCrCb2BGR, 4);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_YCrCb2BGR, 4);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_YCrCb2BGR, 4);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
cv::swap(src, dst);
d_src.swap(d_dst);
SUBTEST << "4000x4000, 8UC3 vs 8UC4, COLOR_BGR2XYZ";
2012-10-17 07:18:30 +08:00
cvtColor(src, dst, COLOR_BGR2XYZ);
2012-10-17 07:18:30 +08:00
CPU_ON;
cvtColor(src, dst, COLOR_BGR2XYZ);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_BGR2XYZ, 4);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_BGR2XYZ, 4);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
cv::swap(src, dst);
d_src.swap(d_dst);
SUBTEST << "4000x4000, 8UC4, COLOR_XYZ2BGR";
2012-10-17 07:18:30 +08:00
cvtColor(src, dst, COLOR_XYZ2BGR, 4);
2012-10-17 07:18:30 +08:00
CPU_ON;
cvtColor(src, dst, COLOR_XYZ2BGR, 4);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_XYZ2BGR, 4);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_XYZ2BGR, 4);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
cv::swap(src, dst);
d_src.swap(d_dst);
SUBTEST << "4000x4000, 8UC3 vs 8UC4, COLOR_BGR2HSV";
2012-10-17 07:18:30 +08:00
cvtColor(src, dst, COLOR_BGR2HSV);
2012-10-17 07:18:30 +08:00
CPU_ON;
cvtColor(src, dst, COLOR_BGR2HSV);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_BGR2HSV, 4);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_BGR2HSV, 4);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
cv::swap(src, dst);
d_src.swap(d_dst);
SUBTEST << "4000x4000, 8UC4, COLOR_HSV2BGR";
2012-10-17 07:18:30 +08:00
cvtColor(src, dst, COLOR_HSV2BGR, 4);
2012-10-17 07:18:30 +08:00
CPU_ON;
cvtColor(src, dst, COLOR_HSV2BGR, 4);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_HSV2BGR, 4);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::cvtColor(d_src, d_dst, COLOR_HSV2BGR, 4);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
cv::swap(src, dst);
d_src.swap(d_dst);
}
TEST(erode)
{
Mat src, dst, ker;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_buf, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 2000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size;
gen(src, size, size, CV_8UC4, Scalar::all(0), Scalar::all(256));
ker = getStructuringElement(MORPH_RECT, Size(3, 3));
erode(src, dst, ker);
CPU_ON;
erode(src, dst, ker);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
Ptr<cuda::Filter> erode = cuda::createMorphologyFilter(MORPH_ERODE, d_src.type(), ker);
2013-04-29 20:03:16 +08:00
erode->apply(d_src, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-04-29 20:03:16 +08:00
erode->apply(d_src, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(threshold)
{
Mat src, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 2000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 8UC1, THRESH_BINARY";
gen(src, size, size, CV_8U, 0, 100);
threshold(src, dst, 50.0, 0.0, THRESH_BINARY);
CPU_ON;
threshold(src, dst, 50.0, 0.0, THRESH_BINARY);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::threshold(d_src, d_dst, 50.0, 0.0, THRESH_BINARY);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::threshold(d_src, d_dst, 50.0, 0.0, THRESH_BINARY);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
for (int size = 2000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 32FC1, THRESH_TRUNC [NPP]";
gen(src, size, size, CV_32FC1, 0, 100);
threshold(src, dst, 50.0, 0.0, THRESH_TRUNC);
CPU_ON;
threshold(src, dst, 50.0, 0.0, THRESH_TRUNC);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::threshold(d_src, d_dst, 50.0, 0.0, THRESH_TRUNC);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::threshold(d_src, d_dst, 50.0, 0.0, THRESH_TRUNC);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(pow)
{
Mat src, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 1000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 32F";
gen(src, size, size, CV_32F, 0, 100);
pow(src, -2.0, dst);
CPU_ON;
pow(src, -2.0, dst);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::pow(d_src, -2.0, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::pow(d_src, -2.0, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(projectPoints)
{
Mat src;
vector<Point2f> dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src, d_dst;
2012-10-17 07:18:30 +08:00
Mat rvec; gen(rvec, 1, 3, CV_32F, 0, 1);
Mat tvec; gen(tvec, 1, 3, CV_32F, 0, 1);
Mat camera_mat; gen(camera_mat, 3, 3, CV_32F, 0, 1);
camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(2, 1) = 0.f;
for (int size = (int)1e6, count = 0; size >= 1e5 && count < 5; size = int(size / 1.4), count++)
{
SUBTEST << size;
gen(src, 1, size, CV_32FC3, Scalar::all(0), Scalar::all(10));
projectPoints(src, rvec, tvec, camera_mat, Mat::zeros(1, 8, CV_32F), dst);
CPU_ON;
projectPoints(src, rvec, tvec, camera_mat, Mat::zeros(1, 8, CV_32F), dst);
CPU_OFF;
d_src.upload(src);
2013-08-28 19:45:13 +08:00
cuda::projectPoints(d_src, rvec, tvec, camera_mat, Mat(), d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::projectPoints(d_src, rvec, tvec, camera_mat, Mat(), d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
static void InitSolvePnpRansac()
{
Mat object; gen(object, 1, 4, CV_32FC3, Scalar::all(0), Scalar::all(100));
Mat image; gen(image, 1, 4, CV_32FC2, Scalar::all(0), Scalar::all(100));
Mat rvec, tvec;
2013-08-28 19:45:13 +08:00
cuda::solvePnPRansac(object, image, Mat::eye(3, 3, CV_32F), Mat(), rvec, tvec);
2012-10-17 07:18:30 +08:00
}
TEST(solvePnPRansac)
{
InitSolvePnpRansac();
for (int num_points = 5000; num_points <= 300000; num_points = int(num_points * 3.76))
{
SUBTEST << num_points;
Mat object; gen(object, 1, num_points, CV_32FC3, Scalar::all(10), Scalar::all(100));
Mat image; gen(image, 1, num_points, CV_32FC2, Scalar::all(10), Scalar::all(100));
Mat camera_mat; gen(camera_mat, 3, 3, CV_32F, 0.5, 1);
camera_mat.at<float>(0, 1) = 0.f;
camera_mat.at<float>(1, 0) = 0.f;
camera_mat.at<float>(2, 0) = 0.f;
camera_mat.at<float>(2, 1) = 0.f;
Mat rvec, tvec;
const int num_iters = 200;
const float max_dist = 2.0f;
vector<int> inliers_cpu, inliers_gpu;
CPU_ON;
solvePnPRansac(object, image, camera_mat, Mat::zeros(1, 8, CV_32F), rvec, tvec, false, num_iters,
max_dist, int(num_points * 0.05), inliers_cpu);
CPU_OFF;
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::solvePnPRansac(object, image, camera_mat, Mat::zeros(1, 8, CV_32F), rvec, tvec, false, num_iters,
2012-10-17 07:18:30 +08:00
max_dist, int(num_points * 0.05), &inliers_gpu);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(GaussianBlur)
{
for (int size = 1000; size <= 4000; size += 1000)
{
SUBTEST << size << 'x' << size << ", 8UC4";
Mat src, dst;
gen(src, size, size, CV_8UC4, 0, 256);
GaussianBlur(src, dst, Size(3, 3), 1);
CPU_ON;
GaussianBlur(src, dst, Size(3, 3), 1);
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_dst(src.size(), src.type());
cuda::GpuMat d_buf;
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
cv::Ptr<cv::cuda::Filter> gauss = cv::cuda::createGaussianFilter(d_src.type(), -1, cv::Size(3, 3), 1);
2013-04-29 18:47:42 +08:00
gauss->apply(d_src, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-04-29 18:47:42 +08:00
gauss->apply(d_src, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(filter2D)
{
for (int size = 512; size <= 2048; size *= 2)
{
Mat src;
gen(src, size, size, CV_8UC4, 0, 256);
for (int ksize = 3; ksize <= 16; ksize += 2)
{
SUBTEST << "ksize = " << ksize << ", " << size << 'x' << size << ", 8UC4";
Mat kernel;
gen(kernel, ksize, ksize, CV_32FC1, 0.0, 1.0);
Mat dst;
cv::filter2D(src, dst, -1, kernel);
CPU_ON;
cv::filter2D(src, dst, -1, kernel);
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_dst;
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
Ptr<cuda::Filter> filter2D = cuda::createLinearFilter(d_src.type(), -1, kernel);
2013-04-29 15:51:47 +08:00
filter2D->apply(d_src, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-04-29 15:51:47 +08:00
filter2D->apply(d_src, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
}
TEST(pyrDown)
{
for (int size = 4000; size >= 1000; size -= 1000)
{
SUBTEST << size << 'x' << size << ", 8UC4";
Mat src, dst;
gen(src, size, size, CV_8UC4, 0, 256);
pyrDown(src, dst);
CPU_ON;
pyrDown(src, dst);
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_dst;
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
cuda::pyrDown(d_src, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::pyrDown(d_src, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(pyrUp)
{
for (int size = 2000; size >= 1000; size -= 1000)
{
SUBTEST << size << 'x' << size << ", 8UC4";
Mat src, dst;
gen(src, size, size, CV_8UC4, 0, 256);
pyrUp(src, dst);
CPU_ON;
pyrUp(src, dst);
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_dst;
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
cuda::pyrUp(d_src, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::pyrUp(d_src, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(equalizeHist)
{
for (int size = 1000; size < 4000; size += 1000)
{
SUBTEST << size << 'x' << size;
Mat src, dst;
gen(src, size, size, CV_8UC1, 0, 256);
equalizeHist(src, dst);
CPU_ON;
equalizeHist(src, dst);
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_dst;
2012-10-17 07:18:30 +08:00
cuda::equalizeHist(d_src, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
cuda::equalizeHist(d_src, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(Canny)
{
2014-09-13 22:28:41 +08:00
Mat img = imread(abspath("../data/aloeL.jpg"), IMREAD_GRAYSCALE);
2012-10-17 07:18:30 +08:00
2014-09-13 22:28:41 +08:00
if (img.empty()) throw runtime_error("can't open ../data/aloeL.jpg");
2012-10-17 07:18:30 +08:00
Mat edges(img.size(), CV_8UC1);
CPU_ON;
Canny(img, edges, 50.0, 100.0);
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_img(img);
cuda::GpuMat d_edges;
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
Ptr<cuda::CannyEdgeDetector> canny = cuda::createCannyEdgeDetector(50.0, 100.0);
canny->detect(d_img, d_edges);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
canny->detect(d_img, d_edges);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
TEST(reduce)
{
for (int size = 1000; size < 4000; size += 1000)
{
Mat src;
gen(src, size, size, CV_32F, 0, 255);
Mat dst0;
Mat dst1;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_dst0;
cuda::GpuMat d_dst1;
2012-10-17 07:18:30 +08:00
SUBTEST << size << 'x' << size << ", dim = 0";
reduce(src, dst0, 0, REDUCE_MIN);
2012-10-17 07:18:30 +08:00
CPU_ON;
reduce(src, dst0, 0, REDUCE_MIN);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::reduce(d_src, d_dst0, 0, REDUCE_MIN);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::reduce(d_src, d_dst0, 0, REDUCE_MIN);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
SUBTEST << size << 'x' << size << ", dim = 1";
reduce(src, dst1, 1, REDUCE_MIN);
2012-10-17 07:18:30 +08:00
CPU_ON;
reduce(src, dst1, 1, REDUCE_MIN);
2012-10-17 07:18:30 +08:00
CPU_OFF;
2013-08-28 19:45:13 +08:00
cuda::reduce(d_src, d_dst1, 1, REDUCE_MIN);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::reduce(d_src, d_dst1, 1, REDUCE_MIN);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(gemm)
{
Mat src1, src2, src3, dst;
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src1, d_src2, d_src3, d_dst;
2012-10-17 07:18:30 +08:00
for (int size = 512; size <= 1024; size *= 2)
{
SUBTEST << size << 'x' << size;
gen(src1, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10));
gen(src2, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10));
gen(src3, size, size, CV_32FC1, Scalar::all(-10), Scalar::all(10));
gemm(src1, src2, 1.0, src3, 1.0, dst);
CPU_ON;
gemm(src1, src2, 1.0, src3, 1.0, dst);
CPU_OFF;
d_src1.upload(src1);
d_src2.upload(src2);
d_src3.upload(src3);
2013-08-28 19:45:13 +08:00
cuda::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-08-28 19:45:13 +08:00
cuda::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
}
TEST(GoodFeaturesToTrack)
{
2014-09-13 22:28:41 +08:00
Mat src = imread(abspath("../data/aloeL.jpg"), IMREAD_GRAYSCALE);
if (src.empty()) throw runtime_error("can't open ../data/aloeL.jpg");
2012-10-17 07:18:30 +08:00
vector<Point2f> pts;
goodFeaturesToTrack(src, pts, 8000, 0.01, 0.0);
CPU_ON;
goodFeaturesToTrack(src, pts, 8000, 0.01, 0.0);
CPU_OFF;
2013-08-28 19:45:13 +08:00
Ptr<cuda::CornersDetector> detector = cuda::createGoodFeaturesToTrackDetector(src.type(), 8000, 0.01, 0.0);
2012-10-17 07:18:30 +08:00
2013-08-28 19:45:13 +08:00
cuda::GpuMat d_src(src);
cuda::GpuMat d_pts;
2012-10-17 07:18:30 +08:00
2013-04-30 20:07:56 +08:00
detector->detect(d_src, d_pts);
2012-10-17 07:18:30 +08:00
2013-07-24 17:55:18 +08:00
CUDA_ON;
2013-04-30 20:07:56 +08:00
detector->detect(d_src, d_pts);
2013-07-24 17:55:18 +08:00
CUDA_OFF;
2012-10-17 07:18:30 +08:00
}
#ifdef HAVE_OPENCV_BGSEGM
2012-10-17 07:18:30 +08:00
TEST(MOG)
{
const std::string inputFile = abspath("../data/vtest.avi");
2012-10-17 07:18:30 +08:00
cv::VideoCapture cap(inputFile);
if (!cap.isOpened()) throw runtime_error("can't open ../data/vtest.avi");
2012-10-17 07:18:30 +08:00
cv::Mat frame;
cap >> frame;
cv::Ptr<cv::BackgroundSubtractor> mog = cv::bgsegm::createBackgroundSubtractorMOG();
2012-10-17 07:18:30 +08:00
cv::Mat foreground;
mog->apply(frame, foreground, 0.01);
2012-10-17 07:18:30 +08:00
while (!TestSystem::instance().stop())
{
cap >> frame;
TestSystem::instance().cpuOn();
mog->apply(frame, foreground, 0.01);
2012-10-17 07:18:30 +08:00
TestSystem::instance().cpuOff();
}
TestSystem::instance().cpuComplete();
cap.open(inputFile);
cap >> frame;
2013-08-28 19:45:13 +08:00
cv::cuda::GpuMat d_frame(frame);
cv::Ptr<cv::BackgroundSubtractor> d_mog = cv::cuda::createBackgroundSubtractorMOG();
cv::cuda::GpuMat d_foreground;
2012-10-17 07:18:30 +08:00
d_mog->apply(d_frame, d_foreground, 0.01);
2012-10-17 07:18:30 +08:00
while (!TestSystem::instance().stop())
{
cap >> frame;
d_frame.upload(frame);
TestSystem::instance().gpuOn();
d_mog->apply(d_frame, d_foreground, 0.01);
2012-10-17 07:18:30 +08:00
TestSystem::instance().gpuOff();
}
TestSystem::instance().gpuComplete();
}
#endif
2012-10-17 07:18:30 +08:00
TEST(MOG2)
{
2014-09-13 22:28:41 +08:00
const std::string inputFile = abspath("../data/768x576.avi");
2012-10-17 07:18:30 +08:00
cv::VideoCapture cap(inputFile);
2014-09-13 22:28:41 +08:00
if (!cap.isOpened()) throw runtime_error("can't open ../data/768x576.avi");
2012-10-17 07:18:30 +08:00
cv::Mat frame;
cap >> frame;
cv::Ptr<cv::BackgroundSubtractor> mog2 = cv::createBackgroundSubtractorMOG2();
2012-10-17 07:18:30 +08:00
cv::Mat foreground;
cv::Mat background;
mog2->apply(frame, foreground);
mog2->getBackgroundImage(background);
2012-10-17 07:18:30 +08:00
while (!TestSystem::instance().stop())
{
cap >> frame;
TestSystem::instance().cpuOn();
mog2->apply(frame, foreground);
mog2->getBackgroundImage(background);
2012-10-17 07:18:30 +08:00
TestSystem::instance().cpuOff();
}
TestSystem::instance().cpuComplete();
cap.open(inputFile);
cap >> frame;
2013-08-28 19:45:13 +08:00
cv::Ptr<cv::BackgroundSubtractor> d_mog2 = cv::cuda::createBackgroundSubtractorMOG2();
cv::cuda::GpuMat d_frame(frame);
cv::cuda::GpuMat d_foreground;
cv::cuda::GpuMat d_background;
2012-10-17 07:18:30 +08:00
2013-05-06 21:41:13 +08:00
d_mog2->apply(d_frame, d_foreground);
d_mog2->getBackgroundImage(d_background);
2012-10-17 07:18:30 +08:00
while (!TestSystem::instance().stop())
{
cap >> frame;
d_frame.upload(frame);
TestSystem::instance().gpuOn();
2013-05-06 21:41:13 +08:00
d_mog2->apply(d_frame, d_foreground);
d_mog2->getBackgroundImage(d_background);
2012-10-17 07:18:30 +08:00
TestSystem::instance().gpuOff();
}
TestSystem::instance().gpuComplete();
}