Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
ba32b447
Commit
ba32b447
authored
Jan 26, 2011
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added SURF perf. test, added working dir field (can be changed via CMD args)
parent
344db916
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
130 additions
and
24 deletions
+130
-24
performance.cpp
samples/gpu/performance/performance.cpp
+43
-6
performance.h
samples/gpu/performance/performance.h
+11
-0
tests.cpp
samples/gpu/performance/tests.cpp
+76
-18
No files found.
samples/gpu/performance/performance.cpp
View file @
ba32b447
#include <iomanip>
#include <stdexcept>
#include "performance.h"
using
namespace
std
;
...
...
@@ -25,8 +26,14 @@ void TestSystem::run()
(
*
it
)
->
run
();
flushSubtestData
();
}
catch
(
const
cv
::
Exception
&
)
catch
(
const
Exception
&
)
{
// Message is printed via callback
resetSubtestData
();
}
catch
(
const
runtime_error
&
e
)
{
printError
(
e
.
what
());
resetSubtestData
();
}
}
...
...
@@ -35,6 +42,12 @@ void TestSystem::run()
}
void
TestSystem
::
setWorkingDir
(
const
string
&
val
)
{
working_dir_
=
val
;
}
void
TestSystem
::
flushSubtestData
()
{
if
(
!
can_flush_
)
...
...
@@ -43,7 +56,7 @@ void TestSystem::flushSubtestData()
int
cpu_time
=
static_cast
<
int
>
(
cpu_elapsed_
/
getTickFrequency
()
*
1000.0
);
int
gpu_time
=
static_cast
<
int
>
(
gpu_elapsed_
/
getTickFrequency
()
*
1000.0
);
double
speedup
=
static_cast
<
double
>
(
cpu_
time
)
/
std
::
max
(
1
,
gpu_time
)
;
double
speedup
=
static_cast
<
double
>
(
cpu_
elapsed_
)
/
gpu_elapsed_
;
speedup_total_
+=
speedup
;
printItem
(
cpu_time
,
gpu_time
,
speedup
);
...
...
@@ -57,7 +70,7 @@ void TestSystem::printHeading()
{
cout
<<
setiosflags
(
ios_base
::
left
);
cout
<<
TAB
<<
setw
(
10
)
<<
"CPU, ms"
<<
setw
(
10
)
<<
"GPU, ms"
<<
setw
(
1
0
)
<<
"SPEEDUP"
<<
setw
(
1
4
)
<<
"SPEEDUP"
<<
"DESCRIPTION
\n
"
;
cout
<<
resetiosflags
(
ios_base
::
left
);
}
...
...
@@ -87,13 +100,19 @@ void TestSystem::printItem(double cpu_time, double gpu_time, double speedup)
stream
.
str
(
""
);
stream
<<
"x"
<<
setprecision
(
3
)
<<
speedup
;
cout
<<
setw
(
1
0
)
<<
stream
.
str
();
cout
<<
setw
(
1
4
)
<<
stream
.
str
();
cout
<<
description_
.
str
();
cout
<<
resetiosflags
(
ios_base
::
left
)
<<
endl
;
}
void
TestSystem
::
printError
(
const
std
::
string
&
msg
)
{
cout
<<
TAB
<<
"[error: "
<<
msg
<<
"] "
<<
description_
.
str
()
<<
endl
;
}
void
gen
(
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
,
Scalar
low
,
Scalar
high
)
{
mat
.
create
(
rows
,
cols
,
type
);
...
...
@@ -102,17 +121,34 @@ void gen(Mat& mat, int rows, int cols, int type, Scalar low, Scalar high)
}
string
abspath
(
const
string
&
relpath
)
{
return
TestSystem
::
instance
()
->
workingDir
()
+
relpath
;
}
int
CV_CDECL
cvErrorCallback
(
int
/*status*/
,
const
char
*
/*func_name*/
,
const
char
*
/*err_msg*/
,
const
char
*
/*file_name*/
,
const
char
*
err_msg
,
const
char
*
/*file_name*/
,
int
/*line*/
,
void
*
/*userdata*/
)
{
TestSystem
::
instance
()
->
printError
(
err_msg
);
return
0
;
}
int
main
()
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
2
)
{
cout
<<
"Usage: performance_gpu <working_dir_with_slash>
\n\n
"
;
}
else
{
TestSystem
::
instance
()
->
setWorkingDir
(
argv
[
1
]);
}
redirectError
(
cvErrorCallback
);
TestSystem
::
instance
()
->
run
();
return
0
;
}
\ No newline at end of file
samples/gpu/performance/performance.h
View file @
ba32b447
...
...
@@ -63,6 +63,12 @@ public:
can_flush_
=
true
;
}
void
setWorkingDir
(
const
std
::
string
&
val
);
const
std
::
string
&
workingDir
()
const
{
return
working_dir_
;
}
void
printError
(
const
std
::
string
&
msg
);
private
:
TestSystem
()
:
can_flush_
(
false
),
cpu_elapsed_
(
0
),
gpu_elapsed_
(
0
),
speedup_total_
(
0
.
0
),
num_subtests_called_
(
0
)
{};
...
...
@@ -81,6 +87,8 @@ private:
void
printSummary
();
void
printItem
(
double
cpu_time
,
double
gpu_time
,
double
speedup
);
std
::
string
working_dir_
;
std
::
vector
<
Runnable
*>
inits_
;
std
::
vector
<
Runnable
*>
tests_
;
...
...
@@ -128,4 +136,6 @@ private:
void
gen
(
cv
::
Mat
&
mat
,
int
rows
,
int
cols
,
int
type
,
cv
::
Scalar
low
,
cv
::
Scalar
high
);
std
::
string
abspath
(
const
std
::
string
&
relpath
);
#endif // OPENCV_GPU_SAMPLE_PERFORMANCE_H_
\ No newline at end of file
samples/gpu/performance/tests.cpp
View file @
ba32b447
#include <stdexcept>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/gpu/gpu.hpp>
#include "performance.h"
...
...
@@ -81,8 +83,20 @@ TEST(remap)
SUBTEST
<<
"src "
<<
size
<<
" and 8U, 32F maps"
;
gen
(
src
,
size
,
size
,
CV_8UC1
,
0
,
256
);
gen
(
xmap
,
size
,
size
,
CV_32F
,
0
,
size
);
gen
(
ymap
,
size
,
size
,
CV_32F
,
0
,
size
);
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.5
f
)
*
0.75
f
+
size
*
0.5
f
;
ymap_row
[
j
]
=
(
i
-
size
*
0.5
f
)
*
0.75
f
+
size
*
0.5
f
;
}
}
dst
.
create
(
xmap
.
size
(),
src
.
type
());
CPU_ON
;
...
...
@@ -97,22 +111,6 @@ TEST(remap)
GPU_ON
;
gpu
::
remap
(
d_src
,
d_dst
,
d_xmap
,
d_ymap
);
GPU_OFF
;
SUBTEST
<<
"src "
<<
size
<<
" and 8U, 32F singular maps"
;
gen
(
xmap
,
size
,
size
,
CV_32F
,
0
,
0
);
gen
(
ymap
,
size
,
size
,
CV_32F
,
0
,
0
);
CPU_ON
;
remap
(
src
,
dst
,
xmap
,
ymap
,
INTER_LINEAR
);
CPU_OFF
;
d_xmap
=
xmap
;
d_ymap
=
ymap
;
GPU_ON
;
gpu
::
remap
(
d_src
,
d_dst
,
d_xmap
,
d_ymap
);
GPU_OFF
;
}
}
...
...
@@ -217,3 +215,62 @@ TEST(norm)
GPU_OFF
;
}
}
TEST
(
meanShift
)
{
int
sp
=
10
,
sr
=
10
;
Mat
src
,
dst
;
gpu
::
GpuMat
d_src
,
d_dst
;
for
(
int
size
=
400
;
size
<=
800
;
size
*=
2
)
{
SUBTEST
<<
"size "
<<
size
<<
", 8UC3 vs 8UC4"
;
gen
(
src
,
size
,
size
,
CV_8UC3
,
Scalar
::
all
(
0
),
Scalar
::
all
(
256
));
dst
.
create
(
src
.
size
(),
src
.
type
());
CPU_ON
;
pyrMeanShiftFiltering
(
src
,
dst
,
sp
,
sr
);
CPU_OFF
;
gen
(
src
,
size
,
size
,
CV_8UC4
,
Scalar
::
all
(
0
),
Scalar
::
all
(
256
));
d_src
=
src
;
d_dst
.
create
(
d_src
.
size
(),
d_src
.
type
());
GPU_ON
;
gpu
::
meanShiftFiltering
(
d_src
,
d_dst
,
sp
,
sr
);
GPU_OFF
;
}
}
TEST
(
SURF
)
{
Mat
src1
=
imread
(
abspath
(
"bowlingL.png"
),
CV_LOAD_IMAGE_GRAYSCALE
);
Mat
src2
=
imread
(
abspath
(
"bowlingR.png"
),
CV_LOAD_IMAGE_GRAYSCALE
);
if
(
src1
.
empty
())
throw
runtime_error
(
"can't open bowlingL.png"
);
if
(
src2
.
empty
())
throw
runtime_error
(
"can't open bowlingR.png"
);
gpu
::
GpuMat
d_src1
(
src1
);
gpu
::
GpuMat
d_src2
(
src2
);
SURF
surf
;
vector
<
KeyPoint
>
keypoints1
,
keypoints2
;
CPU_ON
;
surf
(
src1
,
Mat
(),
keypoints1
);
surf
(
src2
,
Mat
(),
keypoints2
);
CPU_OFF
;
gpu
::
SURF_GPU
d_surf
;
gpu
::
GpuMat
d_keypoints1
,
d_keypoints2
;
gpu
::
GpuMat
d_descriptors1
,
d_descriptors2
;
GPU_ON
;
d_surf
(
d_src1
,
gpu
::
GpuMat
(),
d_keypoints1
);
d_surf
(
d_src2
,
gpu
::
GpuMat
(),
d_keypoints2
);
GPU_OFF
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment