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
8e380639
Commit
8e380639
authored
Sep 10, 2010
by
Kirill Kornyakov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gpu::add now supports 8UC4 and 32FC1
parent
a2a3ec69
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
117 additions
and
32 deletions
+117
-32
arithm.cpp
modules/gpu/src/arithm.cpp
+24
-11
precomp.hpp
modules/gpu/src/precomp.hpp
+1
-0
npp_image_addition.cpp
tests/gpu/src/npp_image_addition.cpp
+92
-21
No files found.
modules/gpu/src/arithm.cpp
View file @
8e380639
...
...
@@ -41,7 +41,6 @@
//M*/
#include "precomp.hpp"
#include "npp.h" //TODO: move to the precomp.hpp
using
namespace
cv
;
using
namespace
cv
::
gpu
;
...
...
@@ -55,24 +54,39 @@ void cv::gpu::add(const GpuMat& src1, const GpuMat& src2, GpuMat& dst) { throw_n
void
cv
::
gpu
::
add
(
const
GpuMat
&
src1
,
const
GpuMat
&
src2
,
GpuMat
&
dst
)
{
dst
.
create
(
src1
.
size
(),
src1
.
type
()
);
CV_Assert
(
src1
.
size
()
==
src2
.
size
()
&&
src1
.
type
()
==
src2
.
type
());
dst
.
create
(
src1
.
size
(),
src1
.
type
()
);
CV_DbgAssert
(
src1
.
depth
()
==
CV_8U
||
src1
.
depth
()
==
CV_32F
);
CV_DbgAssert
(
src1
.
channels
()
==
1
||
src1
.
channels
()
==
4
);
int
nChannels
=
src1
.
channels
();
CV_DbgAssert
((
src1
.
depth
()
==
CV_8U
&&
nChannels
==
1
||
nChannels
==
4
)
||
(
src1
.
depth
()
==
CV_32F
&&
nChannels
==
1
));
NppiSize
sz
;
sz
.
width
=
src1
.
cols
;
sz
.
width
=
src1
.
cols
;
sz
.
height
=
src1
.
rows
;
if
(
src1
.
depth
()
==
CV_8U
)
{
nppiAdd_8u_C1RSfs
((
const
Npp8u
*
)
src1
.
ptr
<
char
>
(),
src1
.
step
,
(
const
Npp8u
*
)
src2
.
ptr
<
char
>
(),
src2
.
step
,
(
Npp8u
*
)
dst
.
ptr
<
char
>
(),
dst
.
step
,
sz
,
0
);
if
(
nChannels
==
1
)
{
nppiAdd_8u_C1RSfs
((
const
Npp8u
*
)
src1
.
ptr
<
char
>
(),
src1
.
step
,
(
const
Npp8u
*
)
src2
.
ptr
<
char
>
(),
src2
.
step
,
(
Npp8u
*
)
dst
.
ptr
<
char
>
(),
dst
.
step
,
sz
,
0
);
}
else
{
nppiAdd_8u_C4RSfs
((
const
Npp8u
*
)
src1
.
ptr
<
char
>
(),
src1
.
step
,
(
const
Npp8u
*
)
src2
.
ptr
<
char
>
(),
src2
.
step
,
(
Npp8u
*
)
dst
.
ptr
<
char
>
(),
dst
.
step
,
sz
,
0
);
}
}
else
//if (src1.depth() == CV_32F)
{
nppiAdd_32f_C1R
((
const
Npp32f
*
)
src1
.
ptr
<
float
>
(),
src1
.
step
,
(
const
Npp32f
*
)
src2
.
ptr
<
float
>
(),
src2
.
step
,
(
Npp32f
*
)
dst
.
ptr
<
float
>
(),
dst
.
step
,
sz
);
}
//TODO: implement other depths
}
#endif
/* !defined (HAVE_CUDA) */
\ No newline at end of file
modules/gpu/src/precomp.hpp
View file @
8e380639
...
...
@@ -62,6 +62,7 @@
#include "cuda_shared.hpp"
#include "cuda_runtime_api.h"
#include "opencv2/gpu/stream_accessor.hpp"
#include "npp.h"
#else
/* defined(HAVE_CUDA) */
...
...
tests/gpu/src/npp_image_addition.cpp
View file @
8e380639
...
...
@@ -40,7 +40,8 @@
//M*/
#include "gputest.hpp"
#include "highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using
namespace
cv
;
using
namespace
std
;
...
...
@@ -54,6 +55,13 @@ public:
protected
:
void
run
(
int
);
int
test8UC1
(
const
Mat
&
imgL
,
const
Mat
&
imgR
);
int
test8UC4
(
const
Mat
&
imgL
,
const
Mat
&
imgR
);
int
test32FC1
(
const
Mat
&
imgL
,
const
Mat
&
imgR
);
int
test
(
const
Mat
&
imgL
,
const
Mat
&
imgR
);
int
CheckNorm
(
const
Mat
&
m1
,
const
Mat
&
m2
);
};
CV_GpuNppImageAdditionTest
::
CV_GpuNppImageAdditionTest
()
:
CvTest
(
"GPU-NppImageAddition"
,
"add"
)
...
...
@@ -62,40 +70,102 @@ CV_GpuNppImageAdditionTest::CV_GpuNppImageAdditionTest(): CvTest( "GPU-NppImageA
CV_GpuNppImageAdditionTest
::~
CV_GpuNppImageAdditionTest
()
{}
void
CV_GpuNppImageAdditionTest
::
run
(
int
)
int
CV_GpuNppImageAdditionTest
::
test8UC1
(
const
Mat
&
imgL
,
const
Mat
&
imgR
)
{
cv
::
Mat
img_l
=
cv
::
imread
(
std
::
string
(
ts
->
get_data_path
())
+
"stereobm/aloe-L.png"
,
0
);
cv
::
Mat
img_r
=
cv
::
imread
(
std
::
string
(
ts
->
get_data_path
())
+
"stereobm/aloe-R.png"
,
0
);
cv
::
Mat
imgL_C1
;
cv
::
Mat
imgR_C1
;
cvtColor
(
imgL
,
imgL_C1
,
CV_BGR2GRAY
);
cvtColor
(
imgR
,
imgR_C1
,
CV_BGR2GRAY
);
if
(
img_l
.
empty
()
||
img_r
.
empty
())
{
ts
->
set_failed_test_info
(
CvTS
::
FAIL_MISSING_TEST_DATA
);
return
;
}
return
test
(
imgL_C1
,
imgR_C1
);
}
int
CV_GpuNppImageAdditionTest
::
test8UC4
(
const
Mat
&
imgL
,
const
Mat
&
imgR
)
{
cv
::
Mat
imgL_C4
;
cv
::
Mat
imgR_C4
;
cvtColor
(
imgL
,
imgL_C4
,
CV_BGR2BGRA
);
cvtColor
(
imgR
,
imgR_C4
,
CV_BGR2BGRA
);
return
test
(
imgL_C4
,
imgR_C4
);
}
int
CV_GpuNppImageAdditionTest
::
test32FC1
(
const
Mat
&
imgL
,
const
Mat
&
imgR
)
{
cv
::
Mat
imgL_C1
;
cv
::
Mat
imgR_C1
;
cvtColor
(
imgL
,
imgL_C1
,
CV_BGR2GRAY
);
cvtColor
(
imgR
,
imgR_C1
,
CV_BGR2GRAY
);
imgL_C1
.
convertTo
(
imgL_C1
,
CV_32F
);
imgR_C1
.
convertTo
(
imgR_C1
,
CV_32F
);
return
test
(
imgL_C1
,
imgR_C1
);
}
int
CV_GpuNppImageAdditionTest
::
test
(
const
Mat
&
imgL
,
const
Mat
&
imgR
)
{
cv
::
Mat
cpuAdd
;
cv
::
add
(
img
_l
,
img_r
,
cpuAdd
);
cv
::
add
(
img
L
,
imgR
,
cpuAdd
);
GpuMat
gpuL
(
img
_l
);
GpuMat
gpuR
(
img
_r
);
GpuMat
gpuL
(
img
L
);
GpuMat
gpuR
(
img
R
);
GpuMat
gpuAdd
;
cv
::
gpu
::
add
(
gpuL
,
gpuR
,
gpuAdd
);
//namedWindow("gpu");
//imshow("gpu", gpuAdd);
//namedWindow("cpu");
//imshow("cpu", cpuAdd);
//waitKey(1000);
return
CheckNorm
(
cpuAdd
,
gpuAdd
);
}
double
ret
=
norm
(
cpuAdd
,
gpuAdd
);
int
CV_GpuNppImageAdditionTest
::
CheckNorm
(
const
Mat
&
m1
,
const
Mat
&
m2
)
{
double
ret
=
norm
(
m1
,
m2
);
if
(
ret
<
1.0
)
ts
->
set_failed_test_info
(
CvTS
::
OK
);
{
return
CvTS
::
OK
;
}
else
{
ts
->
printf
(
CvTS
::
CONSOLE
,
"
\n
Norm: %f
\n
"
,
ret
);
ts
->
set_failed_test_info
(
CvTS
::
FAIL_GENERIC
);
ts
->
printf
(
CvTS
::
LOG
,
"
\n
Norm: %f
\n
"
,
ret
);
return
CvTS
::
FAIL_GENERIC
;
}
}
void
CV_GpuNppImageAdditionTest
::
run
(
int
)
{
//load images
cv
::
Mat
img_l
=
cv
::
imread
(
std
::
string
(
ts
->
get_data_path
())
+
"stereobm/aloe-L.png"
);
cv
::
Mat
img_r
=
cv
::
imread
(
std
::
string
(
ts
->
get_data_path
())
+
"stereobm/aloe-R.png"
);
if
(
img_l
.
empty
()
||
img_r
.
empty
())
{
ts
->
set_failed_test_info
(
CvTS
::
FAIL_MISSING_TEST_DATA
);
return
;
}
//run tests
int
testResult
=
test8UC1
(
img_l
,
img_r
);
if
(
testResult
!=
CvTS
::
OK
)
{
ts
->
set_failed_test_info
(
testResult
);
return
;
}
testResult
=
test8UC4
(
img_l
,
img_r
);
if
(
testResult
!=
CvTS
::
OK
)
{
ts
->
set_failed_test_info
(
testResult
);
return
;
}
testResult
=
test32FC1
(
img_l
,
img_r
);
if
(
testResult
!=
CvTS
::
OK
)
{
ts
->
set_failed_test_info
(
testResult
);
return
;
}
ts
->
set_failed_test_info
(
CvTS
::
OK
);
}
CV_GpuNppImageAdditionTest
CV_GpuNppImageAddition_test
;
\ 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