2012-10-17 07:18:30 +08:00
|
|
|
#include <stdexcept>
|
2013-04-15 19:27:09 +08:00
|
|
|
#include "opencv2/imgproc.hpp"
|
|
|
|
#include "opencv2/highgui.hpp"
|
|
|
|
#include "opencv2/calib3d.hpp"
|
|
|
|
#include "opencv2/video.hpp"
|
|
|
|
#include "opencv2/gpu.hpp"
|
|
|
|
|
|
|
|
#include "opencv2/legacy.hpp"
|
2012-10-17 07:18:30 +08:00
|
|
|
#include "performance.h"
|
|
|
|
|
2013-03-15 18:09:39 +08:00
|
|
|
#include "opencv2/opencv_modules.hpp"
|
2013-03-18 20:14:37 +08:00
|
|
|
#ifdef HAVE_OPENCV_NONFREE
|
|
|
|
#include "opencv2/nonfree/gpu.hpp"
|
2013-03-15 18:09:39 +08:00
|
|
|
#include "opencv2/nonfree/nonfree.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);
|
2013-04-30 21:27:06 +08:00
|
|
|
|
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);
|
2013-04-15 19:27:09 +08:00
|
|
|
matchTemplate(src, templ, dst, TM_CCORR);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
matchTemplate(src, templ, dst, TM_CCORR);
|
2012-10-17 07:18:30 +08:00
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
d_templ.upload(templ);
|
2013-04-30 21:27:06 +08:00
|
|
|
alg->match(d_src, d_templ, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
GPU_ON;
|
2013-04-30 21:27:06 +08:00
|
|
|
alg->match(d_src, d_templ, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::minMaxLoc(d_src, &min_val, &max_val, &min_loc, &max_loc);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
2013-04-30 19:00:25 +08:00
|
|
|
|
|
|
|
harris->compute(d_src, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
GPU_ON;
|
2013-04-30 19:00:25 +08:00
|
|
|
harris->compute(d_src, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(integral)
|
|
|
|
{
|
|
|
|
Mat src, sum;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::GpuMat d_src, d_sum, d_buf;
|
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);
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::integralBuffered(d_src, d_sum, d_buf);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::integralBuffered(d_src, d_sum, d_buf);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::norm(d_src, NORM_INF, d_buf);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::meanShiftFiltering(d_src, d_dst, sp, sr);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-18 20:14:37 +08:00
|
|
|
#ifdef HAVE_OPENCV_NONFREE
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
TEST(SURF)
|
|
|
|
{
|
2013-04-08 02:45:38 +08:00
|
|
|
Mat src = imread(abspath("aloeL.jpg"), IMREAD_GRAYSCALE);
|
2012-10-17 07:18:30 +08:00
|
|
|
if (src.empty()) throw runtime_error("can't open aloeL.jpg");
|
|
|
|
|
|
|
|
SURF surf;
|
|
|
|
vector<KeyPoint> keypoints;
|
|
|
|
Mat descriptors;
|
|
|
|
|
|
|
|
surf(src, Mat(), keypoints, descriptors);
|
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
surf(src, Mat(), keypoints, descriptors);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::SURF_GPU d_surf;
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
2013-03-15 18:09:39 +08:00
|
|
|
#endif
|
|
|
|
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
TEST(FAST)
|
|
|
|
{
|
2013-04-08 02:45:38 +08:00
|
|
|
Mat src = imread(abspath("aloeL.jpg"), IMREAD_GRAYSCALE);
|
2012-10-17 07:18:30 +08:00
|
|
|
if (src.empty()) throw runtime_error("can't open aloeL.jpg");
|
|
|
|
|
|
|
|
vector<KeyPoint> keypoints;
|
|
|
|
|
|
|
|
FAST(src, keypoints, 20);
|
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
FAST(src, keypoints, 20);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::FAST_GPU d_FAST(20);
|
|
|
|
cuda::GpuMat d_src(src);
|
|
|
|
cuda::GpuMat d_keypoints;
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
d_FAST(d_src, cuda::GpuMat(), d_keypoints);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
d_FAST(d_src, cuda::GpuMat(), d_keypoints);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ORB)
|
|
|
|
{
|
2013-04-08 02:45:38 +08:00
|
|
|
Mat src = imread(abspath("aloeL.jpg"), IMREAD_GRAYSCALE);
|
2012-10-17 07:18:30 +08:00
|
|
|
if (src.empty()) throw runtime_error("can't open aloeL.jpg");
|
|
|
|
|
|
|
|
ORB orb(4000);
|
|
|
|
vector<KeyPoint> keypoints;
|
|
|
|
Mat descriptors;
|
|
|
|
|
|
|
|
orb(src, Mat(), keypoints, descriptors);
|
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
orb(src, Mat(), keypoints, descriptors);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::ORB_GPU d_orb;
|
|
|
|
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_orb(d_src, cuda::GpuMat(), d_keypoints, d_descriptors);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
d_orb(d_src, cuda::GpuMat(), d_keypoints, d_descriptors);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// Init GPU matcher
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::BFMatcher_GPU d_matcher(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);
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::GpuMat d_trainIdx, d_distance, d_allDist, d_nMatches;
|
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.matchSingle(d_query, d_train, d_trainIdx, d_distance);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
SUBTEST << "knnMatch";
|
|
|
|
|
|
|
|
matcher.knnMatch(query, train, matches, 2);
|
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
matcher.knnMatch(query, train, matches, 2);
|
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
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_trainIdx.release();
|
|
|
|
|
|
|
|
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::magnitude(d_x, d_y, d_mag);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::add(d_src1, d_src2, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::log(d_src, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
SUBTEST << "4000x4000, 8UC1, COLOR_GRAY2BGRA";
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
cvtColor(src, dst, COLOR_GRAY2BGRA, 4);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
SUBTEST << "4000x4000, 8UC3 vs 8UC4, COLOR_BGR2YCrCb";
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
cvtColor(src, dst, COLOR_BGR2YCrCb);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
SUBTEST << "4000x4000, 8UC4, COLOR_YCrCb2BGR";
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
cvtColor(src, dst, COLOR_YCrCb2BGR, 4);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
SUBTEST << "4000x4000, 8UC3 vs 8UC4, COLOR_BGR2XYZ";
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
cvtColor(src, dst, COLOR_BGR2XYZ);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
SUBTEST << "4000x4000, 8UC4, COLOR_XYZ2BGR";
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
cvtColor(src, dst, COLOR_XYZ2BGR, 4);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
SUBTEST << "4000x4000, 8UC3 vs 8UC4, COLOR_BGR2HSV";
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
cvtColor(src, dst, COLOR_BGR2HSV);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
SUBTEST << "4000x4000, 8UC4, COLOR_HSV2BGR";
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
cvtColor(src, dst, COLOR_HSV2BGR, 4);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-04-29 20:03:16 +08:00
|
|
|
erode->apply(d_src, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::pow(d_src, -2.0, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
GPU_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);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-04-29 18:47:42 +08:00
|
|
|
gauss->apply(d_src, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-04-29 15:51:47 +08:00
|
|
|
filter2D->apply(d_src, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::pyrDown(d_src, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::pyrUp(d_src, d_dst);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
cuda::GpuMat d_buf;
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::equalizeHist(d_src, d_dst, d_buf);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
GPU_ON;
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::equalizeHist(d_src, d_dst, d_buf);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Canny)
|
|
|
|
{
|
2013-04-08 02:45:38 +08:00
|
|
|
Mat img = imread(abspath("aloeL.jpg"), IMREAD_GRAYSCALE);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
if (img.empty()) throw runtime_error("can't open aloeL.jpg");
|
|
|
|
|
|
|
|
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);
|
2013-04-30 15:47:33 +08:00
|
|
|
|
|
|
|
canny->detect(d_img, d_edges);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
GPU_ON;
|
2013-04-30 15:47:33 +08:00
|
|
|
canny->detect(d_img, d_edges);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
reduce(src, dst0, 0, REDUCE_MIN);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
SUBTEST << size << 'x' << size << ", dim = 1";
|
|
|
|
|
2013-04-15 19:27:09 +08:00
|
|
|
reduce(src, dst1, 1, REDUCE_MIN);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
CPU_ON;
|
2013-04-15 19:27:09 +08:00
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
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
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(GoodFeaturesToTrack)
|
|
|
|
{
|
|
|
|
Mat src = imread(abspath("aloeL.jpg"), IMREAD_GRAYSCALE);
|
|
|
|
if (src.empty()) throw runtime_error("can't open aloeL.jpg");
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
GPU_ON;
|
2013-04-30 20:07:56 +08:00
|
|
|
detector->detect(d_src, d_pts);
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(PyrLKOpticalFlow)
|
|
|
|
{
|
|
|
|
Mat frame0 = imread(abspath("rubberwhale1.png"));
|
|
|
|
if (frame0.empty()) throw runtime_error("can't open rubberwhale1.png");
|
|
|
|
|
|
|
|
Mat frame1 = imread(abspath("rubberwhale2.png"));
|
|
|
|
if (frame1.empty()) throw runtime_error("can't open rubberwhale2.png");
|
|
|
|
|
|
|
|
Mat gray_frame;
|
|
|
|
cvtColor(frame0, gray_frame, COLOR_BGR2GRAY);
|
|
|
|
|
|
|
|
for (int points = 1000; points <= 8000; points *= 2)
|
|
|
|
{
|
|
|
|
SUBTEST << points;
|
|
|
|
|
|
|
|
vector<Point2f> pts;
|
|
|
|
goodFeaturesToTrack(gray_frame, pts, points, 0.01, 0.0);
|
|
|
|
|
|
|
|
vector<Point2f> nextPts;
|
|
|
|
vector<unsigned char> status;
|
|
|
|
|
|
|
|
vector<float> err;
|
|
|
|
|
|
|
|
calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err);
|
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, err);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::PyrLKOpticalFlow d_pyrLK;
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::GpuMat d_frame0(frame0);
|
|
|
|
cuda::GpuMat d_frame1(frame1);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::GpuMat d_pts;
|
2012-10-17 07:18:30 +08:00
|
|
|
Mat pts_mat(1, (int)pts.size(), CV_32FC2, (void*)&pts[0]);
|
|
|
|
d_pts.upload(pts_mat);
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::GpuMat d_nextPts;
|
|
|
|
cuda::GpuMat d_status;
|
|
|
|
cuda::GpuMat d_err;
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status, &d_err);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FarnebackOpticalFlow)
|
|
|
|
{
|
|
|
|
const string datasets[] = {"rubberwhale", "basketball"};
|
|
|
|
for (size_t i = 0; i < sizeof(datasets)/sizeof(*datasets); ++i) {
|
|
|
|
for (int fastPyramids = 0; fastPyramids < 2; ++fastPyramids) {
|
|
|
|
for (int useGaussianBlur = 0; useGaussianBlur < 2; ++useGaussianBlur) {
|
|
|
|
|
|
|
|
SUBTEST << "dataset=" << datasets[i] << ", fastPyramids=" << fastPyramids << ", useGaussianBlur=" << useGaussianBlur;
|
|
|
|
Mat frame0 = imread(abspath(datasets[i] + "1.png"), IMREAD_GRAYSCALE);
|
|
|
|
Mat frame1 = imread(abspath(datasets[i] + "2.png"), IMREAD_GRAYSCALE);
|
|
|
|
if (frame0.empty()) throw runtime_error("can't open " + datasets[i] + "1.png");
|
|
|
|
if (frame1.empty()) throw runtime_error("can't open " + datasets[i] + "2.png");
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::FarnebackOpticalFlow calc;
|
2012-10-17 07:18:30 +08:00
|
|
|
calc.fastPyramids = fastPyramids != 0;
|
|
|
|
calc.flags |= useGaussianBlur ? OPTFLOW_FARNEBACK_GAUSSIAN : 0;
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::GpuMat d_frame0(frame0), d_frame1(frame1), d_flowx, d_flowy;
|
2012-10-17 07:18:30 +08:00
|
|
|
GPU_ON;
|
|
|
|
calc(d_frame0, d_frame1, d_flowx, d_flowy);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
Mat flow;
|
|
|
|
CPU_ON;
|
|
|
|
calcOpticalFlowFarneback(frame0, frame1, flow, calc.pyrScale, calc.numLevels, calc.winSize, calc.numIters, calc.polyN, calc.polySigma, calc.flags);
|
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
}}}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
template<> void Ptr<CvBGStatModel>::delete_obj()
|
|
|
|
{
|
|
|
|
cvReleaseBGStatModel(&obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(FGDStatModel)
|
|
|
|
{
|
|
|
|
const std::string inputFile = abspath("768x576.avi");
|
|
|
|
|
2013-05-07 16:04:21 +08:00
|
|
|
VideoCapture cap(inputFile);
|
2012-10-17 07:18:30 +08:00
|
|
|
if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");
|
|
|
|
|
2013-05-07 16:04:21 +08:00
|
|
|
Mat frame;
|
2012-10-17 07:18:30 +08:00
|
|
|
cap >> frame;
|
|
|
|
|
|
|
|
IplImage ipl_frame = frame;
|
2013-05-07 16:04:21 +08:00
|
|
|
Ptr<CvBGStatModel> model(cvCreateFGDStatModel(&ipl_frame));
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
while (!TestSystem::instance().stop())
|
|
|
|
{
|
|
|
|
cap >> frame;
|
|
|
|
ipl_frame = frame;
|
|
|
|
|
|
|
|
TestSystem::instance().cpuOn();
|
|
|
|
|
|
|
|
cvUpdateBGStatModel(&ipl_frame, model);
|
|
|
|
|
|
|
|
TestSystem::instance().cpuOff();
|
|
|
|
}
|
|
|
|
TestSystem::instance().cpuComplete();
|
|
|
|
|
|
|
|
cap.open(inputFile);
|
|
|
|
|
|
|
|
cap >> frame;
|
|
|
|
|
2013-08-28 19:45:13 +08:00
|
|
|
cuda::GpuMat d_frame(frame), d_fgmask;
|
|
|
|
Ptr<BackgroundSubtractor> d_fgd = cuda::createBackgroundSubtractorFGD();
|
2013-05-07 16:04:21 +08:00
|
|
|
|
|
|
|
d_fgd->apply(d_frame, d_fgmask);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
while (!TestSystem::instance().stop())
|
|
|
|
{
|
|
|
|
cap >> frame;
|
|
|
|
d_frame.upload(frame);
|
|
|
|
|
|
|
|
TestSystem::instance().gpuOn();
|
|
|
|
|
2013-05-07 16:04:21 +08:00
|
|
|
d_fgd->apply(d_frame, d_fgmask);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
TestSystem::instance().gpuOff();
|
|
|
|
}
|
|
|
|
TestSystem::instance().gpuComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MOG)
|
|
|
|
{
|
|
|
|
const std::string inputFile = abspath("768x576.avi");
|
|
|
|
|
|
|
|
cv::VideoCapture cap(inputFile);
|
|
|
|
if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");
|
|
|
|
|
|
|
|
cv::Mat frame;
|
|
|
|
cap >> frame;
|
|
|
|
|
2013-03-20 23:51:49 +08:00
|
|
|
cv::Ptr<cv::BackgroundSubtractor> mog = cv::createBackgroundSubtractorMOG();
|
2012-10-17 07:18:30 +08:00
|
|
|
cv::Mat foreground;
|
|
|
|
|
2013-03-20 23:51:49 +08:00
|
|
|
mog->apply(frame, foreground, 0.01);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
while (!TestSystem::instance().stop())
|
|
|
|
{
|
|
|
|
cap >> frame;
|
|
|
|
|
|
|
|
TestSystem::instance().cpuOn();
|
|
|
|
|
2013-03-20 23:51:49 +08:00
|
|
|
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
|
|
|
|
2013-05-06 20:52:06 +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();
|
|
|
|
|
2013-05-06 20:52:06 +08:00
|
|
|
d_mog->apply(d_frame, d_foreground, 0.01);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
TestSystem::instance().gpuOff();
|
|
|
|
}
|
|
|
|
TestSystem::instance().gpuComplete();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MOG2)
|
|
|
|
{
|
|
|
|
const std::string inputFile = abspath("768x576.avi");
|
|
|
|
|
|
|
|
cv::VideoCapture cap(inputFile);
|
|
|
|
if (!cap.isOpened()) throw runtime_error("can't open 768x576.avi");
|
|
|
|
|
|
|
|
cv::Mat frame;
|
|
|
|
cap >> frame;
|
|
|
|
|
2013-03-20 23:51:49 +08:00
|
|
|
cv::Ptr<cv::BackgroundSubtractor> mog2 = cv::createBackgroundSubtractorMOG2();
|
2012-10-17 07:18:30 +08:00
|
|
|
cv::Mat foreground;
|
|
|
|
cv::Mat background;
|
|
|
|
|
2013-03-20 23:51:49 +08:00
|
|
|
mog2->apply(frame, foreground);
|
|
|
|
mog2->getBackgroundImage(background);
|
2012-10-17 07:18:30 +08:00
|
|
|
|
|
|
|
while (!TestSystem::instance().stop())
|
|
|
|
{
|
|
|
|
cap >> frame;
|
|
|
|
|
|
|
|
TestSystem::instance().cpuOn();
|
|
|
|
|
2013-03-20 23:51:49 +08:00
|
|
|
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();
|
|
|
|
}
|