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
da9be823
Commit
da9be823
authored
Aug 01, 2014
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix cv::gpu::resize for INTER_LINEAR, now it produces the same result as CPU version
parent
bab826a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
16 deletions
+62
-16
resize.cu
modules/gpu/src/cuda/resize.cu
+25
-9
test_resize.cpp
modules/gpu/test/test_resize.cpp
+37
-7
No files found.
modules/gpu/src/cuda/resize.cu
View file @
da9be823
...
...
@@ -77,8 +77,8 @@ namespace cv { namespace gpu { namespace device
if (dst_x < dst.cols && dst_y < dst.rows)
{
const float src_x =
dst_x * fx
;
const float src_y =
dst_y * fy
;
const float src_x =
(dst_x + 0.5f) * fx - 0.5f
;
const float src_y =
(dst_y + 0.5f) * fy - 0.5f
;
work_type out = VecTraits<work_type>::all(0);
...
...
@@ -86,16 +86,18 @@ namespace cv { namespace gpu { namespace device
const int y1 = __float2int_rd(src_y);
const int x2 = x1 + 1;
const int y2 = y1 + 1;
const int x2_read = ::min(x2, src.cols - 1);
const int y2_read = ::min(y2, src.rows - 1);
const int x1_read = ::max(::min(x1, src.cols - 1), 0);
const int y1_read = ::max(::min(y1, src.rows - 1), 0);
const int x2_read = ::max(::min(x2, src.cols - 1), 0);
const int y2_read = ::max(::min(y2, src.rows - 1), 0);
T src_reg = src(y1
, x1
);
T src_reg = src(y1
_read, x1_read
);
out = out + src_reg * ((x2 - src_x) * (y2 - src_y));
src_reg = src(y1, x2_read);
src_reg = src(y1
_read
, x2_read);
out = out + src_reg * ((src_x - x1) * (y2 - src_y));
src_reg = src(y2_read, x1);
src_reg = src(y2_read, x1
_read
);
out = out + src_reg * ((x2 - src_x) * (src_y - y1));
src_reg = src(y2_read, x2_read);
...
...
@@ -119,6 +121,20 @@ namespace cv { namespace gpu { namespace device
}
}
template <class Ptr2D, typename T> __global__ void resize_linear(const Ptr2D src, PtrStepSz<T> dst, const float fy, const float fx)
{
const int dst_x = blockDim.x * blockIdx.x + threadIdx.x;
const int dst_y = blockDim.y * blockIdx.y + threadIdx.y;
if (dst_x < dst.cols && dst_y < dst.rows)
{
const float src_x = (dst_x + 0.5f) * fx - 0.5f;
const float src_y = (dst_y + 0.5f) * fy - 0.5f;
dst(dst_y, dst_x) = src(src_y, src_x);
}
}
template <typename Ptr2D, typename T> __global__ void resize_area(const Ptr2D src, PtrStepSz<T> dst)
{
const int x = blockDim.x * blockIdx.x + threadIdx.x;
...
...
@@ -231,7 +247,7 @@ namespace cv { namespace gpu { namespace device
TextureAccessor<T> texSrc = texAccessor(src, 0, 0);
LinearFilter< TextureAccessor<T> > filteredSrc(texSrc);
resize<<<grid, block>>>(filteredSrc, dst, fy, fx);
resize
_linear
<<<grid, block>>>(filteredSrc, dst, fy, fx);
}
else
{
...
...
@@ -241,7 +257,7 @@ namespace cv { namespace gpu { namespace device
BorderReader<TextureAccessor<T>, BrdReplicate<T> > brdSrc(texSrc, brd);
LinearFilter< BorderReader<TextureAccessor<T>, BrdReplicate<T> > > filteredSrc(brdSrc);
resize<<<grid, block>>>(filteredSrc, dst, fy, fx);
resize
_linear
<<<grid, block>>>(filteredSrc, dst, fy, fx);
}
cudaSafeCall( cudaGetLastError() );
...
...
modules/gpu/test/test_resize.cpp
View file @
da9be823
...
...
@@ -73,6 +73,28 @@ namespace
}
}
template
<
typename
T
,
template
<
typename
>
class
Interpolator
>
void
resizeLinearImpl
(
const
cv
::
Mat
&
src
,
cv
::
Mat
&
dst
,
double
fx
,
double
fy
)
{
const
int
cn
=
src
.
channels
();
cv
::
Size
dsize
(
cv
::
saturate_cast
<
int
>
(
src
.
cols
*
fx
),
cv
::
saturate_cast
<
int
>
(
src
.
rows
*
fy
));
dst
.
create
(
dsize
,
src
.
type
());
float
ifx
=
static_cast
<
float
>
(
1.0
/
fx
);
float
ify
=
static_cast
<
float
>
(
1.0
/
fy
);
for
(
int
y
=
0
;
y
<
dsize
.
height
;
++
y
)
{
for
(
int
x
=
0
;
x
<
dsize
.
width
;
++
x
)
{
for
(
int
c
=
0
;
c
<
cn
;
++
c
)
dst
.
at
<
T
>
(
y
,
x
*
cn
+
c
)
=
Interpolator
<
T
>::
getValue
(
src
,
(
y
+
0.5
f
)
*
ify
-
0.5
f
,
(
x
+
0.5
f
)
*
ifx
-
0.5
f
,
c
,
cv
::
BORDER_REPLICATE
);
}
}
}
void
resizeGold
(
const
cv
::
Mat
&
src
,
cv
::
Mat
&
dst
,
double
fx
,
double
fy
,
int
interpolation
)
{
typedef
void
(
*
func_t
)(
const
cv
::
Mat
&
src
,
cv
::
Mat
&
dst
,
double
fx
,
double
fy
);
...
...
@@ -90,12 +112,12 @@ namespace
static
const
func_t
linear_funcs
[]
=
{
resizeImpl
<
unsigned
char
,
LinearInterpolator
>
,
resizeImpl
<
signed
char
,
LinearInterpolator
>
,
resizeImpl
<
unsigned
short
,
LinearInterpolator
>
,
resizeImpl
<
short
,
LinearInterpolator
>
,
resizeImpl
<
int
,
LinearInterpolator
>
,
resizeImpl
<
float
,
LinearInterpolator
>
resize
Linear
Impl
<
unsigned
char
,
LinearInterpolator
>
,
resize
Linear
Impl
<
signed
char
,
LinearInterpolator
>
,
resize
Linear
Impl
<
unsigned
short
,
LinearInterpolator
>
,
resize
Linear
Impl
<
short
,
LinearInterpolator
>
,
resize
Linear
Impl
<
int
,
LinearInterpolator
>
,
resize
Linear
Impl
<
float
,
LinearInterpolator
>
};
static
const
func_t
cubic_funcs
[]
=
...
...
@@ -203,7 +225,15 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, ResizeSameAsHost, testing::Combine(
DIFFERENT_SIZES
,
testing
::
Values
(
MatType
(
CV_8UC1
),
MatType
(
CV_8UC3
),
MatType
(
CV_8UC4
),
MatType
(
CV_16UC1
),
MatType
(
CV_16UC3
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC3
),
MatType
(
CV_32FC4
)),
testing
::
Values
(
0.3
,
0.5
),
testing
::
Values
(
Interpolation
(
cv
::
INTER_NEAREST
),
Interpolation
(
cv
::
INTER_AREA
)),
testing
::
Values
(
Interpolation
(
cv
::
INTER_NEAREST
),
Interpolation
(
cv
::
INTER_LINEAR
),
Interpolation
(
cv
::
INTER_AREA
)),
WHOLE_SUBMAT
));
INSTANTIATE_TEST_CASE_P
(
GPU_ImgProc2
,
ResizeSameAsHost
,
testing
::
Combine
(
ALL_DEVICES
,
DIFFERENT_SIZES
,
testing
::
Values
(
MatType
(
CV_8UC1
),
MatType
(
CV_8UC3
),
MatType
(
CV_8UC4
),
MatType
(
CV_16UC1
),
MatType
(
CV_16UC3
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC3
),
MatType
(
CV_32FC4
)),
testing
::
Values
(
0.3
,
0.5
,
1.5
,
2.0
),
testing
::
Values
(
Interpolation
(
cv
::
INTER_NEAREST
),
Interpolation
(
cv
::
INTER_LINEAR
)),
WHOLE_SUBMAT
));
#endif // HAVE_CUDA
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