2011-01-26 12:37:54 +01:00
|
|
|
#include <stdexcept>
|
2011-05-21 20:32:34 +02:00
|
|
|
#include "opencv2/imgproc/imgproc.hpp"
|
|
|
|
#include "opencv2/highgui/highgui.hpp"
|
|
|
|
#include "opencv2/calib3d/calib3d.hpp"
|
2012-02-13 13:57:27 +01:00
|
|
|
#include "opencv2/video/video.hpp"
|
2011-05-21 20:32:34 +02:00
|
|
|
#include "opencv2/gpu/gpu.hpp"
|
2011-01-24 11:33:01 +01:00
|
|
|
#include "performance.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace cv;
|
|
|
|
|
2011-03-01 10:17:22 +01:00
|
|
|
void InitMatchTemplate()
|
2011-01-25 15:43:54 +01:00
|
|
|
{
|
2011-01-26 08:49:56 +01:00
|
|
|
Mat src; gen(src, 500, 500, CV_32F, 0, 1);
|
|
|
|
Mat templ; gen(templ, 500, 500, CV_32F, 0, 1);
|
|
|
|
gpu::GpuMat d_src(src), d_templ(templ), d_dst;
|
|
|
|
gpu::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
|
2011-01-25 15:43:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-24 11:33:01 +01:00
|
|
|
TEST(matchTemplate)
|
|
|
|
{
|
2011-03-01 10:17:22 +01:00
|
|
|
InitMatchTemplate();
|
|
|
|
|
2011-01-26 08:49:56 +01:00
|
|
|
Mat src, templ, dst;
|
2011-01-25 15:43:54 +01:00
|
|
|
gen(src, 3000, 3000, CV_32F, 0, 1);
|
2011-01-25 09:32:45 +01:00
|
|
|
|
2011-01-26 08:49:56 +01:00
|
|
|
gpu::GpuMat d_src(src), d_templ, d_dst;
|
2011-01-25 09:32:45 +01:00
|
|
|
|
2011-01-26 08:49:56 +01:00
|
|
|
for (int templ_size = 5; templ_size < 200; templ_size *= 5)
|
2011-01-24 11:33:01 +01:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << src.cols << 'x' << src.rows << ", 32FC1" << ", templ " << templ_size << 'x' << templ_size << ", CCORR";
|
2011-01-24 11:33:01 +01:00
|
|
|
|
2011-01-25 12:45:29 +01:00
|
|
|
gen(templ, templ_size, templ_size, CV_32F, 0, 1);
|
2012-01-11 09:58:39 +01:00
|
|
|
matchTemplate(src, templ, dst, CV_TM_CCORR);
|
2011-01-24 11:33:01 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
2011-01-26 08:49:56 +01:00
|
|
|
matchTemplate(src, templ, dst, CV_TM_CCORR);
|
2011-01-24 11:33:01 +01:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_templ.upload(templ);
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
|
2011-01-24 11:33:01 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
2011-01-26 08:49:56 +01:00
|
|
|
gpu::matchTemplate(d_src, d_templ, d_dst, CV_TM_CCORR);
|
2011-01-24 11:33:01 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
2011-01-25 09:32:45 +01:00
|
|
|
|
|
|
|
|
2011-01-25 10:54:17 +01:00
|
|
|
TEST(minMaxLoc)
|
2011-01-25 09:32:45 +01:00
|
|
|
{
|
|
|
|
Mat src;
|
|
|
|
gpu::GpuMat d_src;
|
|
|
|
|
|
|
|
double min_val, max_val;
|
|
|
|
Point min_loc, max_loc;
|
|
|
|
|
|
|
|
for (int size = 2000; size <= 8000; size *= 2)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 32F";
|
2011-01-25 09:32:45 +01:00
|
|
|
|
2011-01-25 12:45:29 +01:00
|
|
|
gen(src, size, size, CV_32F, 0, 1);
|
2011-01-25 09:32:45 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
minMaxLoc(src, &min_val, &max_val, &min_loc, &max_loc);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2011-01-25 09:32:45 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::minMaxLoc(d_src, &min_val, &max_val, &min_loc, &max_loc);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-01-25 10:54:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(remap)
|
|
|
|
{
|
|
|
|
Mat src, dst, xmap, ymap;
|
|
|
|
gpu::GpuMat d_src, d_dst, d_xmap, d_ymap;
|
2011-09-06 09:01:23 +02:00
|
|
|
|
|
|
|
int interpolation = INTER_LINEAR;
|
2011-09-06 15:42:50 +02:00
|
|
|
int borderMode = BORDER_REPLICATE;
|
2011-01-25 10:54:17 +01:00
|
|
|
|
2011-08-31 13:42:54 +02:00
|
|
|
for (int size = 1000; size <= 4000; size *= 2)
|
2011-01-25 10:54:17 +01:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 8UC4, INTER_LINEAR, BORDER_REPLICATE";
|
2011-08-31 13:42:54 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
remap(src, dst, xmap, ymap, interpolation, borderMode);
|
2011-08-31 13:42:54 +02:00
|
|
|
|
|
|
|
CPU_ON;
|
2011-09-06 09:01:23 +02:00
|
|
|
remap(src, dst, xmap, ymap, interpolation, borderMode);
|
2011-08-31 13:42:54 +02:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
|
|
|
d_xmap.upload(xmap);
|
|
|
|
d_ymap.upload(ymap);
|
2011-08-31 13:42:54 +02:00
|
|
|
|
2011-09-06 09:01:23 +02:00
|
|
|
gpu::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode);
|
2011-01-25 10:54:17 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
2011-09-06 09:01:23 +02:00
|
|
|
gpu::remap(d_src, d_dst, d_xmap, d_ymap, interpolation, borderMode);
|
2011-01-25 10:54:17 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(dft)
|
|
|
|
{
|
|
|
|
Mat src, dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
2011-01-26 08:49:56 +01:00
|
|
|
for (int size = 1000; size <= 4000; size *= 2)
|
2011-01-25 10:54:17 +01:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 32FC2, complex-to-complex";
|
2011-01-25 10:54:17 +01:00
|
|
|
|
2011-01-25 12:45:29 +01:00
|
|
|
gen(src, size, size, CV_32FC2, Scalar::all(0), Scalar::all(1));
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
dft(src, dst);
|
2011-01-25 10:54:17 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
dft(src, dst);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::dft(d_src, d_dst, Size(size, size));
|
2011-01-25 10:54:17 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::dft(d_src, d_dst, Size(size, size));
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(cornerHarris)
|
|
|
|
{
|
|
|
|
Mat src, dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
for (int size = 1000; size <= 4000; size *= 2)
|
2011-01-25 10:54:17 +01:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 32FC1, BORDER_REFLECT101";
|
2011-01-25 10:54:17 +01:00
|
|
|
|
2011-01-25 12:45:29 +01:00
|
|
|
gen(src, size, size, CV_32F, 0, 1);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
cornerHarris(src, dst, 5, 7, 0.1, BORDER_REFLECT101);
|
2011-01-25 10:54:17 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
cornerHarris(src, dst, 5, 7, 0.1, BORDER_REFLECT101);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::cornerHarris(d_src, d_dst, 5, 7, 0.1, BORDER_REFLECT101);
|
2011-01-25 10:54:17 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
2011-01-26 09:12:06 +01:00
|
|
|
gpu::cornerHarris(d_src, d_dst, 5, 7, 0.1, BORDER_REFLECT101);
|
2011-01-25 10:54:17 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-01-25 11:37:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-04 09:16:09 +01:00
|
|
|
TEST(integral)
|
|
|
|
{
|
|
|
|
Mat src, sum;
|
|
|
|
gpu::GpuMat d_src, d_sum, d_buf;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
for (int size = 1000; size <= 4000; size *= 2)
|
|
|
|
{
|
|
|
|
SUBTEST << size << 'x' << size << ", 8UC1";
|
2011-02-04 09:16:09 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gen(src, size, size, CV_8U, 0, 256);
|
2011-02-04 09:16:09 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
integral(src, sum);
|
2011-02-04 09:16:09 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
integral(src, sum);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
d_src.upload(src);
|
|
|
|
|
|
|
|
gpu::integralBuffered(d_src, d_sum, d_buf);
|
|
|
|
|
2011-02-04 09:16:09 +01:00
|
|
|
GPU_ON;
|
|
|
|
gpu::integralBuffered(d_src, d_sum, d_buf);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
2011-01-26 08:49:56 +01:00
|
|
|
|
|
|
|
|
|
|
|
TEST(norm)
|
|
|
|
{
|
|
|
|
Mat src;
|
2011-02-01 11:46:19 +01:00
|
|
|
gpu::GpuMat d_src, d_buf;
|
2011-01-26 08:49:56 +01:00
|
|
|
|
2011-02-01 11:51:50 +01:00
|
|
|
for (int size = 2000; size <= 4000; size += 1000)
|
2011-01-26 08:49:56 +01:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 32FC4, NORM_INF";
|
2011-01-26 08:49:56 +01:00
|
|
|
|
2011-02-01 11:51:50 +01:00
|
|
|
gen(src, size, size, CV_32FC4, Scalar::all(0), Scalar::all(1));
|
2011-01-26 08:49:56 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
norm(src, NORM_INF);
|
|
|
|
|
2011-01-26 08:49:56 +01:00
|
|
|
CPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
norm(src, NORM_INF);
|
2011-01-26 08:49:56 +01:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2011-01-26 08:49:56 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::norm(d_src, NORM_INF, d_buf);
|
|
|
|
|
2011-01-26 08:49:56 +01:00
|
|
|
GPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::norm(d_src, NORM_INF, d_buf);
|
2011-01-26 08:49:56 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-01-25 11:37:48 +01:00
|
|
|
}
|
2011-01-26 12:37:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
TEST(meanShift)
|
|
|
|
{
|
|
|
|
int sp = 10, sr = 10;
|
|
|
|
|
|
|
|
Mat src, dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
|
|
|
for (int size = 400; size <= 800; size *= 2)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 8UC3 vs 8UC4";
|
2011-01-26 12:37:54 +01:00
|
|
|
|
|
|
|
gen(src, size, size, CV_8UC3, Scalar::all(0), Scalar::all(256));
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
pyrMeanShiftFiltering(src, dst, sp, sr);
|
2011-01-26 12:37:54 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
pyrMeanShiftFiltering(src, dst, sp, sr);
|
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
gen(src, size, size, CV_8UC4, Scalar::all(0), Scalar::all(256));
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::meanShiftFiltering(d_src, d_dst, sp, sr);
|
2011-01-26 12:37:54 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::meanShiftFiltering(d_src, d_dst, sp, sr);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(SURF)
|
|
|
|
{
|
2011-12-27 10:33:20 +01:00
|
|
|
Mat src = imread(abspath("aloeL.jpg"), CV_LOAD_IMAGE_GRAYSCALE);
|
|
|
|
if (src.empty()) throw runtime_error("can't open aloeL.jpg");
|
2011-01-26 12:37:54 +01:00
|
|
|
|
|
|
|
SURF surf;
|
2011-12-27 10:33:20 +01:00
|
|
|
vector<KeyPoint> keypoints;
|
|
|
|
vector<float> descriptors;
|
|
|
|
|
|
|
|
surf(src, Mat(), keypoints, descriptors);
|
2011-01-26 12:37:54 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
2011-12-27 10:33:20 +01:00
|
|
|
surf(src, Mat(), keypoints, descriptors);
|
2011-01-26 12:37:54 +01:00
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
gpu::SURF_GPU d_surf;
|
2011-12-27 10:33:20 +01:00
|
|
|
gpu::GpuMat d_src(src);
|
|
|
|
gpu::GpuMat d_keypoints;
|
|
|
|
gpu::GpuMat d_descriptors;
|
|
|
|
|
|
|
|
d_surf(d_src, gpu::GpuMat(), d_keypoints, d_descriptors);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
d_surf(d_src, gpu::GpuMat(), d_keypoints, d_descriptors);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FAST)
|
|
|
|
{
|
|
|
|
Mat src = imread(abspath("aloeL.jpg"), CV_LOAD_IMAGE_GRAYSCALE);
|
|
|
|
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;
|
|
|
|
|
|
|
|
gpu::FAST_GPU d_FAST(20);
|
|
|
|
gpu::GpuMat d_src(src);
|
|
|
|
gpu::GpuMat d_keypoints;
|
|
|
|
|
|
|
|
d_FAST(d_src, gpu::GpuMat(), d_keypoints);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
d_FAST(d_src, gpu::GpuMat(), d_keypoints);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ORB)
|
|
|
|
{
|
|
|
|
Mat src = imread(abspath("aloeL.jpg"), CV_LOAD_IMAGE_GRAYSCALE);
|
|
|
|
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;
|
|
|
|
|
|
|
|
gpu::ORB_GPU d_orb;
|
|
|
|
gpu::GpuMat d_src(src);
|
|
|
|
gpu::GpuMat d_keypoints;
|
|
|
|
gpu::GpuMat d_descriptors;
|
|
|
|
|
|
|
|
d_orb(d_src, gpu::GpuMat(), d_keypoints, d_descriptors);
|
2011-01-26 12:37:54 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
2011-12-27 10:33:20 +01:00
|
|
|
d_orb(d_src, gpu::GpuMat(), d_keypoints, d_descriptors);
|
2011-01-26 12:37:54 +01:00
|
|
|
GPU_OFF;
|
2011-01-26 16:28:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(BruteForceMatcher)
|
|
|
|
{
|
|
|
|
// Init CPU matcher
|
|
|
|
|
2011-08-29 13:31:52 +02:00
|
|
|
int desc_len = 64;
|
2011-01-26 16:28:42 +01:00
|
|
|
|
|
|
|
BruteForceMatcher< L2<float> > matcher;
|
|
|
|
|
|
|
|
Mat query;
|
2011-02-02 08:34:18 +01:00
|
|
|
gen(query, 3000, desc_len, CV_32F, 0, 1);
|
2011-01-26 16:35:41 +01:00
|
|
|
|
|
|
|
Mat train;
|
2011-02-02 08:34:18 +01:00
|
|
|
gen(train, 3000, desc_len, CV_32F, 0, 1);
|
2011-01-26 16:28:42 +01:00
|
|
|
|
|
|
|
// Init GPU matcher
|
|
|
|
|
|
|
|
gpu::BruteForceMatcher_GPU< L2<float> > d_matcher;
|
|
|
|
|
|
|
|
gpu::GpuMat d_query(query);
|
2011-01-26 16:35:41 +01:00
|
|
|
gpu::GpuMat d_train(train);
|
2011-01-26 16:28:42 +01:00
|
|
|
|
|
|
|
// Output
|
2011-08-24 13:16:42 +02:00
|
|
|
vector< vector<DMatch> > matches(2);
|
2011-10-12 12:23:03 +02:00
|
|
|
gpu::GpuMat d_trainIdx, d_distance, d_allDist, d_nMatches;
|
2011-01-26 16:28:42 +01:00
|
|
|
|
|
|
|
SUBTEST << "match";
|
|
|
|
|
2011-10-12 12:23:03 +02:00
|
|
|
matcher.match(query, train, matches[0]);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
2011-01-26 16:28:42 +01:00
|
|
|
CPU_ON;
|
2011-01-26 16:35:41 +01:00
|
|
|
matcher.match(query, train, matches[0]);
|
2011-01-26 16:28:42 +01:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-12 12:23:03 +02:00
|
|
|
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
2011-01-26 16:28:42 +01:00
|
|
|
GPU_ON;
|
2011-10-12 12:23:03 +02:00
|
|
|
d_matcher.matchSingle(d_query, d_train, d_trainIdx, d_distance);
|
2011-01-26 16:28:42 +01:00
|
|
|
GPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << "knnMatch";
|
2011-01-26 16:28:42 +01:00
|
|
|
|
2011-10-12 12:23:03 +02:00
|
|
|
matcher.knnMatch(query, train, matches, 2);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
2011-01-26 16:28:42 +01:00
|
|
|
CPU_ON;
|
2011-10-12 12:23:03 +02:00
|
|
|
matcher.knnMatch(query, train, matches, 2);
|
2011-01-26 16:28:42 +01:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-12 12:23:03 +02:00
|
|
|
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2);
|
|
|
|
|
|
|
|
GPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
d_matcher.knnMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_allDist, 2);
|
2011-01-26 16:28:42 +01:00
|
|
|
GPU_OFF;
|
|
|
|
|
2011-08-17 13:32:24 +02:00
|
|
|
SUBTEST << "radiusMatch";
|
2012-01-11 09:58:39 +01:00
|
|
|
|
2011-08-29 13:31:52 +02:00
|
|
|
float max_distance = 2.0f;
|
2011-01-26 16:28:42 +01:00
|
|
|
|
2011-10-12 12:23:03 +02:00
|
|
|
matcher.radiusMatch(query, train, matches, max_distance);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
2011-01-26 16:28:42 +01:00
|
|
|
CPU_ON;
|
2011-01-26 16:35:41 +01:00
|
|
|
matcher.radiusMatch(query, train, matches, max_distance);
|
2011-01-26 16:28:42 +01:00
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
d_trainIdx.release();
|
|
|
|
|
2011-10-12 12:23:03 +02:00
|
|
|
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
2011-01-26 16:28:42 +01:00
|
|
|
GPU_ON;
|
2011-10-12 12:23:03 +02:00
|
|
|
d_matcher.radiusMatchSingle(d_query, d_train, d_trainIdx, d_distance, d_nMatches, max_distance);
|
2011-08-17 13:32:24 +02:00
|
|
|
GPU_OFF;
|
2011-01-28 08:45:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(magnitude)
|
|
|
|
{
|
|
|
|
Mat x, y, mag;
|
|
|
|
gpu::GpuMat d_x, d_y, d_mag;
|
|
|
|
|
|
|
|
for (int size = 2000; size <= 4000; size += 1000)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 32FC1";
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
gen(x, size, size, CV_32F, 0, 1);
|
|
|
|
gen(y, size, size, CV_32F, 0, 1);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
magnitude(x, y, mag);
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
magnitude(x, y, mag);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_x.upload(x);
|
|
|
|
d_y.upload(y);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::magnitude(d_x, d_y, d_mag);
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::magnitude(d_x, d_y, d_mag);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(add)
|
|
|
|
{
|
|
|
|
Mat src1, src2, dst;
|
|
|
|
gpu::GpuMat d_src1, d_src2, d_dst;
|
|
|
|
|
|
|
|
for (int size = 2000; size <= 4000; size += 1000)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 32FC1";
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
gen(src1, size, size, CV_32F, 0, 1);
|
|
|
|
gen(src2, size, size, CV_32F, 0, 1);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
add(src1, src2, dst);
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
add(src1, src2, dst);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src1.upload(src1);
|
|
|
|
d_src2.upload(src2);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::add(d_src1, d_src2, d_dst);
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::add(d_src1, d_src2, d_dst);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(log)
|
|
|
|
{
|
|
|
|
Mat src, dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
|
|
|
for (int size = 2000; size <= 4000; size += 1000)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 32F";
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
gen(src, size, size, CV_32F, 1, 10);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
log(src, dst);
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
log(src, dst);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2011-01-28 08:45:01 +01:00
|
|
|
|
|
|
|
gpu::log(d_src, d_dst);
|
|
|
|
|
|
|
|
GPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::log(d_src, d_dst);
|
2011-01-28 08:45:01 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-01-28 09:38:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(mulSpectrums)
|
|
|
|
{
|
|
|
|
Mat src1, src2, dst;
|
|
|
|
gpu::GpuMat d_src1, d_src2, d_dst;
|
|
|
|
|
|
|
|
for (int size = 2000; size <= 4000; size += 1000)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size;
|
2011-01-28 09:38:01 +01:00
|
|
|
|
|
|
|
gen(src1, size, size, CV_32FC2, Scalar::all(0), Scalar::all(1));
|
|
|
|
gen(src2, size, size, CV_32FC2, Scalar::all(0), Scalar::all(1));
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
mulSpectrums(src1, src2, dst, 0, true);
|
2011-01-28 09:38:01 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
mulSpectrums(src1, src2, dst, 0, true);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src1.upload(src1);
|
|
|
|
d_src2.upload(src2);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::mulSpectrums(d_src1, d_src2, d_dst, 0, true);
|
2011-01-28 09:38:01 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::mulSpectrums(d_src1, d_src2, d_dst, 0, true);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(resize)
|
|
|
|
{
|
|
|
|
Mat src, dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
|
|
|
for (int size = 1000; size <= 3000; size += 1000)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 8UC4, up";
|
2011-09-12 12:13:14 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gen(src, size, size, CV_8UC4, 0, 256);
|
2011-01-28 09:38:01 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
resize(src, dst, Size(), 2.0, 2.0);
|
2011-09-12 12:13:14 +02:00
|
|
|
|
|
|
|
CPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
resize(src, dst, Size(), 2.0, 2.0);
|
2011-09-12 12:13:14 +02:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2011-09-12 12:13:14 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::resize(d_src, d_dst, Size(), 2.0, 2.0);
|
2011-09-12 12:13:14 +02:00
|
|
|
|
|
|
|
GPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::resize(d_src, d_dst, Size(), 2.0, 2.0);
|
2011-09-12 12:13:14 +02:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int size = 1000; size <= 3000; size += 1000)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 8UC4, down";
|
2011-09-12 12:13:14 +02:00
|
|
|
|
|
|
|
gen(src, size, size, CV_8UC4, 0, 256);
|
2011-01-28 09:38:01 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
resize(src, dst, Size(), 0.5, 0.5);
|
2011-09-12 12:13:14 +02:00
|
|
|
|
|
|
|
CPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
resize(src, dst, Size(), 0.5, 0.5);
|
2011-09-12 12:13:14 +02:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2011-09-12 12:13:14 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::resize(d_src, d_dst, Size(), 0.5, 0.5);
|
2011-09-12 12:13:14 +02:00
|
|
|
|
2011-01-28 09:38:01 +01:00
|
|
|
GPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::resize(d_src, d_dst, Size(), 0.5, 0.5);
|
2011-01-28 09:38:01 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-02 08:34:18 +01:00
|
|
|
TEST(cvtColor)
|
|
|
|
{
|
|
|
|
Mat src, dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
|
|
|
gen(src, 4000, 4000, CV_8UC1, 0, 255);
|
|
|
|
d_src.upload(src);
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << "4000x4000, 8UC1, CV_GRAY2BGRA";
|
2011-02-02 08:34:18 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
cvtColor(src, dst, CV_GRAY2BGRA, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
cvtColor(src, dst, CV_GRAY2BGRA, 4);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::cvtColor(d_src, d_dst, CV_GRAY2BGRA, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::cvtColor(d_src, d_dst, CV_GRAY2BGRA, 4);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << "4000x4000, 8UC3 vs 8UC4, CV_BGR2YCrCb";
|
2011-02-02 08:34:18 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
cvtColor(src, dst, CV_BGR2YCrCb);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
cvtColor(src, dst, CV_BGR2YCrCb);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::cvtColor(d_src, d_dst, CV_BGR2YCrCb, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::cvtColor(d_src, d_dst, CV_BGR2YCrCb, 4);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << "4000x4000, 8UC4, CV_YCrCb2BGR";
|
2011-02-02 08:34:18 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
cvtColor(src, dst, CV_YCrCb2BGR, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
cvtColor(src, dst, CV_YCrCb2BGR, 4);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::cvtColor(d_src, d_dst, CV_YCrCb2BGR, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::cvtColor(d_src, d_dst, CV_YCrCb2BGR, 4);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << "4000x4000, 8UC3 vs 8UC4, CV_BGR2XYZ";
|
2011-02-02 08:34:18 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
cvtColor(src, dst, CV_BGR2XYZ);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
cvtColor(src, dst, CV_BGR2XYZ);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::cvtColor(d_src, d_dst, CV_BGR2XYZ, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::cvtColor(d_src, d_dst, CV_BGR2XYZ, 4);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << "4000x4000, 8UC4, CV_XYZ2BGR";
|
2011-02-02 08:34:18 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
cvtColor(src, dst, CV_XYZ2BGR, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
cvtColor(src, dst, CV_XYZ2BGR, 4);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::cvtColor(d_src, d_dst, CV_XYZ2BGR, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::cvtColor(d_src, d_dst, CV_XYZ2BGR, 4);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << "4000x4000, 8UC3 vs 8UC4, CV_BGR2HSV";
|
2011-02-02 08:34:18 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
cvtColor(src, dst, CV_BGR2HSV);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
cvtColor(src, dst, CV_BGR2HSV);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::cvtColor(d_src, d_dst, CV_BGR2HSV, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::cvtColor(d_src, d_dst, CV_BGR2HSV, 4);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << "4000x4000, 8UC4, CV_HSV2BGR";
|
2011-02-02 08:34:18 +01:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
cvtColor(src, dst, CV_HSV2BGR, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
cvtColor(src, dst, CV_HSV2BGR, 4);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::cvtColor(d_src, d_dst, CV_HSV2BGR, 4);
|
2011-02-02 08:34:18 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::cvtColor(d_src, d_dst, CV_HSV2BGR, 4);
|
|
|
|
GPU_OFF;
|
|
|
|
|
|
|
|
cv::swap(src, dst);
|
|
|
|
d_src.swap(d_dst);
|
2011-02-04 09:16:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(erode)
|
|
|
|
{
|
|
|
|
Mat src, dst, ker;
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::GpuMat d_src, d_buf, d_dst;
|
2011-02-04 09:16:09 +01:00
|
|
|
|
|
|
|
for (int size = 2000; size <= 4000; size += 1000)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size;
|
2011-02-04 09:16:09 +01:00
|
|
|
|
|
|
|
gen(src, size, size, CV_8UC4, Scalar::all(0), Scalar::all(256));
|
|
|
|
ker = getStructuringElement(MORPH_RECT, Size(3, 3));
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
erode(src, dst, ker);
|
2011-02-04 09:16:09 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
erode(src, dst, ker);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::erode(d_src, d_dst, ker, d_buf);
|
2011-02-04 09:16:09 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::erode(d_src, d_dst, ker, d_buf);
|
2011-02-04 09:16:09 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-02-16 09:31:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(threshold)
|
|
|
|
{
|
|
|
|
Mat src, dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
for (int size = 2000; size <= 4000; size += 1000)
|
2011-02-16 09:31:45 +01:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 8UC1, THRESH_BINARY";
|
2011-02-16 09:31:45 +01:00
|
|
|
|
|
|
|
gen(src, size, size, CV_8U, 0, 100);
|
|
|
|
|
2011-08-17 13:32:24 +02:00
|
|
|
threshold(src, dst, 50.0, 0.0, THRESH_BINARY);
|
2011-02-16 09:31:45 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
threshold(src, dst, 50.0, 0.0, THRESH_BINARY);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::threshold(d_src, d_dst, 50.0, 0.0, THRESH_BINARY);
|
2011-02-16 09:31:45 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::threshold(d_src, d_dst, 50.0, 0.0, THRESH_BINARY);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
2012-02-08 12:02:32 +01: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);
|
|
|
|
|
|
|
|
gpu::threshold(d_src, d_dst, 50.0, 0.0, THRESH_TRUNC);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::threshold(d_src, d_dst, 50.0, 0.0, THRESH_TRUNC);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-08-17 13:32:24 +02:00
|
|
|
}
|
2011-02-16 09:31:45 +01:00
|
|
|
|
2011-08-17 13:32:24 +02:00
|
|
|
TEST(pow)
|
|
|
|
{
|
|
|
|
Mat src, dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
|
|
|
for (int size = 1000; size <= 4000; size += 1000)
|
2011-02-16 09:31:45 +01:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 32F";
|
2011-02-16 09:31:45 +01:00
|
|
|
|
|
|
|
gen(src, size, size, CV_32F, 0, 100);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
pow(src, -2.0, dst);
|
2011-02-16 09:31:45 +01:00
|
|
|
|
2011-08-17 13:32:24 +02:00
|
|
|
CPU_ON;
|
|
|
|
pow(src, -2.0, dst);
|
2011-02-16 09:31:45 +01:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::pow(d_src, -2.0, d_dst);
|
2011-02-16 09:31:45 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
2011-08-17 13:32:24 +02:00
|
|
|
gpu::pow(d_src, -2.0, d_dst);
|
2011-02-16 09:31:45 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-02-21 12:14:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(projectPoints)
|
|
|
|
{
|
|
|
|
Mat src;
|
|
|
|
vector<Point2f> dst;
|
|
|
|
gpu::GpuMat d_src, d_dst;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-03-01 09:02:27 +01:00
|
|
|
for (int size = (int)1e6, count = 0; size >= 1e5 && count < 5; size = int(size / 1.4), count++)
|
2011-02-21 12:14:12 +01:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size;
|
2011-02-21 12:14:12 +01:00
|
|
|
|
|
|
|
gen(src, 1, size, CV_32FC3, Scalar::all(0), Scalar::all(10));
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
projectPoints(src, rvec, tvec, camera_mat, Mat::zeros(1, 8, CV_32F), dst);
|
2011-02-21 12:14:12 +01:00
|
|
|
|
|
|
|
CPU_ON;
|
2011-05-05 13:44:47 +02:00
|
|
|
projectPoints(src, rvec, tvec, camera_mat, Mat::zeros(1, 8, CV_32F), dst);
|
2011-02-21 12:14:12 +01:00
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src.upload(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::projectPoints(d_src, rvec, tvec, camera_mat, Mat(), d_dst);
|
2011-02-21 12:14:12 +01:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::projectPoints(d_src, rvec, tvec, camera_mat, Mat(), d_dst);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
2011-03-01 10:17:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
void InitSolvePnpRansac()
|
2011-04-18 17:14:32 +02:00
|
|
|
{
|
|
|
|
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;
|
2011-03-07 15:01:18 +01:00
|
|
|
gpu::solvePnPRansac(object, image, Mat::eye(3, 3, CV_32F), Mat(), rvec, tvec);
|
2011-03-01 10:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 09:48:39 +01:00
|
|
|
TEST(solvePnPRansac)
|
2011-03-01 10:17:22 +01:00
|
|
|
{
|
|
|
|
InitSolvePnpRansac();
|
|
|
|
|
2011-04-18 17:14:32 +02:00
|
|
|
for (int num_points = 5000; num_points <= 300000; num_points = int(num_points * 3.76))
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << num_points;
|
2011-04-18 17:14:32 +02:00
|
|
|
|
|
|
|
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;
|
2011-05-05 13:44:47 +02:00
|
|
|
solvePnPRansac(object, image, camera_mat, Mat::zeros(1, 8, CV_32F), rvec, tvec, false, num_iters,
|
2011-04-18 17:14:32 +02:00
|
|
|
max_dist, int(num_points * 0.05), inliers_cpu);
|
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
GPU_ON;
|
2011-05-05 13:44:47 +02:00
|
|
|
gpu::solvePnPRansac(object, image, camera_mat, Mat::zeros(1, 8, CV_32F), rvec, tvec, false, num_iters,
|
2011-04-18 17:14:32 +02:00
|
|
|
max_dist, int(num_points * 0.05), &inliers_gpu);
|
2011-03-07 14:36:47 +01:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-04-27 07:29:02 +02:00
|
|
|
}
|
2011-06-30 16:39:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
TEST(GaussianBlur)
|
|
|
|
{
|
2011-09-28 13:52:26 +02:00
|
|
|
for (int size = 1000; size <= 4000; size += 1000)
|
2011-06-30 16:39:48 +02:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 8UC4";
|
2011-06-30 16:39:48 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
Mat src, dst;
|
|
|
|
|
|
|
|
gen(src, size, size, CV_8UC4, 0, 256);
|
2011-06-30 16:39:48 +02:00
|
|
|
|
2011-09-28 13:52:26 +02:00
|
|
|
GaussianBlur(src, dst, Size(3, 3), 1);
|
2011-06-30 16:39:48 +02:00
|
|
|
|
|
|
|
CPU_ON;
|
2011-09-28 13:52:26 +02:00
|
|
|
GaussianBlur(src, dst, Size(3, 3), 1);
|
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
gpu::GpuMat d_src(src);
|
|
|
|
gpu::GpuMat d_dst(src.size(), src.type());
|
|
|
|
gpu::GpuMat d_buf;
|
|
|
|
|
|
|
|
gpu::GaussianBlur(d_src, d_dst, Size(3, 3), d_buf, 1);
|
2011-06-30 16:39:48 +02:00
|
|
|
|
|
|
|
GPU_ON;
|
2011-09-28 13:52:26 +02:00
|
|
|
gpu::GaussianBlur(d_src, d_dst, Size(3, 3), d_buf, 1);
|
2011-06-30 16:39:48 +02:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
2011-08-01 10:15:31 +02:00
|
|
|
|
|
|
|
TEST(pyrDown)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
for (int size = 4000; size >= 1000; size -= 1000)
|
2011-08-24 13:16:42 +02:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 8UC4";
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
Mat src, dst;
|
|
|
|
gen(src, size, size, CV_8UC4, 0, 256);
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
pyrDown(src, dst);
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
CPU_ON;
|
|
|
|
pyrDown(src, dst);
|
|
|
|
CPU_OFF;
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::GpuMat d_src(src);
|
|
|
|
gpu::GpuMat d_dst;
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::pyrDown(d_src, d_dst);
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
GPU_ON;
|
|
|
|
gpu::pyrDown(d_src, d_dst);
|
|
|
|
GPU_OFF;
|
2011-08-01 10:15:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(pyrUp)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
for (int size = 2000; size >= 1000; size -= 1000)
|
2011-08-24 13:16:42 +02:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", 8UC4";
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
Mat src, dst;
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gen(src, size, size, CV_8UC4, 0, 256);
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
pyrUp(src, dst);
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
CPU_ON;
|
|
|
|
pyrUp(src, dst);
|
|
|
|
CPU_OFF;
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::GpuMat d_src(src);
|
|
|
|
gpu::GpuMat d_dst;
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::pyrUp(d_src, d_dst);
|
2011-08-24 13:16:42 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
GPU_ON;
|
|
|
|
gpu::pyrUp(d_src, d_dst);
|
|
|
|
GPU_OFF;
|
2011-08-01 10:15:31 +02:00
|
|
|
}
|
|
|
|
}
|
2011-08-03 14:10:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
TEST(equalizeHist)
|
|
|
|
{
|
|
|
|
for (int size = 1000; size < 4000; size += 1000)
|
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size;
|
|
|
|
|
|
|
|
Mat src, dst;
|
|
|
|
|
|
|
|
gen(src, size, size, CV_8UC1, 0, 256);
|
2011-08-03 14:10:36 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
equalizeHist(src, dst);
|
2011-08-03 14:10:36 +02:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
equalizeHist(src, dst);
|
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
gpu::GpuMat d_src(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::GpuMat d_dst;
|
|
|
|
gpu::GpuMat d_hist;
|
|
|
|
gpu::GpuMat d_buf;
|
|
|
|
|
|
|
|
gpu::equalizeHist(d_src, d_dst, d_hist, d_buf);
|
2011-08-03 14:10:36 +02:00
|
|
|
|
|
|
|
GPU_ON;
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::equalizeHist(d_src, d_dst, d_hist, d_buf);
|
2011-08-03 14:10:36 +02:00
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
2011-08-08 10:53:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Canny)
|
|
|
|
{
|
|
|
|
Mat img = imread(abspath("aloeL.jpg"), CV_LOAD_IMAGE_GRAYSCALE);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
gpu::GpuMat d_img(img);
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::GpuMat d_edges;
|
|
|
|
gpu::CannyBuf d_buf;
|
|
|
|
|
|
|
|
gpu::Canny(d_img, d_buf, d_edges, 50.0, 100.0);
|
2011-08-08 10:53:55 +02:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::Canny(d_img, d_buf, d_edges, 50.0, 100.0);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
2011-09-26 10:14:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
TEST(reduce)
|
|
|
|
{
|
|
|
|
for (int size = 1000; size < 4000; size += 1000)
|
|
|
|
{
|
|
|
|
Mat src;
|
|
|
|
gen(src, size, size, CV_32F, 0, 255);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
Mat dst0;
|
|
|
|
Mat dst1;
|
2011-09-26 10:14:31 +02:00
|
|
|
|
|
|
|
gpu::GpuMat d_src(src);
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::GpuMat d_dst0;
|
|
|
|
gpu::GpuMat d_dst1;
|
|
|
|
|
|
|
|
SUBTEST << size << 'x' << size << ", dim = 0";
|
2011-09-26 10:14:31 +02:00
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
reduce(src, dst0, 0, CV_REDUCE_MIN);
|
2011-09-26 10:14:31 +02:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
reduce(src, dst0, 0, CV_REDUCE_MIN);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::reduce(d_src, d_dst0, 0, CV_REDUCE_MIN);
|
|
|
|
|
2011-09-26 10:14:31 +02:00
|
|
|
GPU_ON;
|
|
|
|
gpu::reduce(d_src, d_dst0, 0, CV_REDUCE_MIN);
|
|
|
|
GPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size << ", dim = 1";
|
|
|
|
|
|
|
|
reduce(src, dst1, 1, CV_REDUCE_MIN);
|
2011-09-26 10:14:31 +02:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
reduce(src, dst1, 1, CV_REDUCE_MIN);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
gpu::reduce(d_src, d_dst1, 1, CV_REDUCE_MIN);
|
|
|
|
|
2011-09-26 10:14:31 +02:00
|
|
|
GPU_ON;
|
|
|
|
gpu::reduce(d_src, d_dst1, 1, CV_REDUCE_MIN);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
2011-10-19 15:29:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
TEST(gemm)
|
|
|
|
{
|
|
|
|
Mat src1, src2, src3, dst;
|
|
|
|
gpu::GpuMat d_src1, d_src2, d_src3, d_dst;
|
|
|
|
|
2012-01-11 09:58:39 +01:00
|
|
|
for (int size = 512; size <= 1024; size *= 2)
|
2011-10-19 15:29:54 +02:00
|
|
|
{
|
2012-01-11 09:58:39 +01:00
|
|
|
SUBTEST << size << 'x' << size;
|
2011-10-19 15:29:54 +02:00
|
|
|
|
|
|
|
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));
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gemm(src1, src2, 1.0, src3, 1.0, dst);
|
2011-10-19 15:29:54 +02:00
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
gemm(src1, src2, 1.0, src3, 1.0, dst);
|
|
|
|
CPU_OFF;
|
|
|
|
|
2011-10-31 09:51:00 +01:00
|
|
|
d_src1.upload(src1);
|
|
|
|
d_src2.upload(src2);
|
|
|
|
d_src3.upload(src3);
|
2012-01-11 09:58:39 +01:00
|
|
|
|
|
|
|
gpu::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
|
2011-10-19 15:29:54 +02:00
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
gpu::gemm(d_src1, d_src2, 1.0, d_src3, 1.0, d_dst);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|
2012-02-13 13:57:27 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
gpu::GoodFeaturesToTrackDetector_GPU detector(8000, 0.01, 0.0);
|
|
|
|
|
|
|
|
gpu::GpuMat d_src(src);
|
|
|
|
gpu::GpuMat d_pts;
|
|
|
|
|
|
|
|
detector(d_src, d_pts);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
detector(d_src, d_pts);
|
|
|
|
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;
|
|
|
|
|
|
|
|
calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, noArray());
|
|
|
|
|
|
|
|
CPU_ON;
|
|
|
|
calcOpticalFlowPyrLK(frame0, frame1, pts, nextPts, status, noArray());
|
|
|
|
CPU_OFF;
|
|
|
|
|
|
|
|
gpu::PyrLKOpticalFlow d_pyrLK;
|
|
|
|
|
|
|
|
gpu::GpuMat d_frame0(frame0);
|
|
|
|
gpu::GpuMat d_frame1(frame1);
|
|
|
|
|
|
|
|
gpu::GpuMat d_pts;
|
|
|
|
Mat pts_mat(1, pts.size(), CV_32FC2, (void*)&pts[0]);
|
|
|
|
d_pts.upload(pts_mat);
|
|
|
|
|
|
|
|
gpu::GpuMat d_nextPts;
|
|
|
|
gpu::GpuMat d_status;
|
|
|
|
gpu::GpuMat d_err;
|
|
|
|
|
|
|
|
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status);
|
|
|
|
|
|
|
|
GPU_ON;
|
|
|
|
d_pyrLK.sparse(d_frame0, d_frame1, d_pts, d_nextPts, d_status);
|
|
|
|
GPU_OFF;
|
|
|
|
}
|
|
|
|
}
|