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
be38864d
Commit
be38864d
authored
Dec 27, 2010
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added buffered version of gpu::convolve
parent
e5d1b9ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
45 deletions
+99
-45
gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+28
-1
imgproc_gpu.cpp
modules/gpu/src/imgproc_gpu.cpp
+71
-44
No files found.
modules/gpu/include/opencv2/gpu/gpu.hpp
View file @
be38864d
...
...
@@ -656,7 +656,34 @@ namespace cv
//! computes convolution (or cross-correlation) of two images using discrete Fourier transform
//! supports source images of 32FC1 type only
//! result matrix will have 32FC1 type
CV_EXPORTS
void
convolve
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
bool
ccorr
=
false
);
CV_EXPORTS
void
convolve
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
bool
ccorr
=
false
);
struct
CV_EXPORTS
ConvolveBuf
;
//! buffered version
CV_EXPORTS
void
convolve
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
bool
ccorr
,
ConvolveBuf
&
buf
);
struct
CV_EXPORTS
ConvolveBuf
{
ConvolveBuf
()
{}
ConvolveBuf
(
Size
image_size
,
Size
templ_size
)
{
create
(
image_size
,
templ_size
);
}
void
create
(
Size
image_size
,
Size
templ_size
);
private
:
static
Size
estimateBlockSize
(
Size
result_size
,
Size
templ_size
);
friend
void
convolve
(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
bool
,
ConvolveBuf
&
);
Size
result_size
;
Size
block_size
;
Size
dft_size
;
int
spect_len
;
GpuMat
image_spect
,
templ_spect
,
result_spect
;
GpuMat
image_block
,
templ_block
,
result_data
;
};
//! computes the proximity map for the raster template and the image where the template is searched for
CV_EXPORTS
void
matchTemplate
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
int
method
);
...
...
modules/gpu/src/imgproc_gpu.cpp
View file @
be38864d
...
...
@@ -77,7 +77,9 @@ void cv::gpu::cornerMinEigenVal(const GpuMat&, GpuMat&, int, int, int) { throw_n
void
cv
::
gpu
::
mulSpectrums
(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
int
,
bool
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
mulAndScaleSpectrums
(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
int
,
float
,
bool
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
dft
(
const
GpuMat
&
,
GpuMat
&
,
Size
,
int
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
ConvolveBuf
::
create
(
Size
,
Size
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
convolve
(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
bool
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
convolve
(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
bool
,
ConvolveBuf
&
)
{
throw_nogpu
();
}
#else
/* !defined (HAVE_CUDA) */
...
...
@@ -1211,36 +1213,65 @@ void cv::gpu::dft(const GpuMat& src, GpuMat& dst, Size dft_size, int flags)
}
//////////////////////////////////////////////////////////////////////////////
// c
rossCorr
// c
onvolve
namespace
void
cv
::
gpu
::
ConvolveBuf
::
create
(
Size
image_size
,
Size
templ_size
)
{
// Estimates optimal block size
void
convolveOptBlockSize
(
int
w
,
int
h
,
int
tw
,
int
th
,
int
&
bw
,
int
&
bh
)
{
int
major
,
minor
;
getComputeCapability
(
getDevice
(),
major
,
minor
);
result_size
=
Size
(
image_size
.
width
-
templ_size
.
width
+
1
,
image_size
.
height
-
templ_size
.
height
+
1
);
block_size
=
estimateBlockSize
(
result_size
,
templ_size
);
dft_size
.
width
=
getOptimalDFTSize
(
block_size
.
width
+
templ_size
.
width
-
1
);
dft_size
.
height
=
getOptimalDFTSize
(
block_size
.
width
+
templ_size
.
height
-
1
);
createContinuous
(
dft_size
,
CV_32F
,
image_block
);
createContinuous
(
dft_size
,
CV_32F
,
templ_block
);
createContinuous
(
dft_size
,
CV_32F
,
result_data
);
spect_len
=
dft_size
.
height
*
(
dft_size
.
width
/
2
+
1
);
createContinuous
(
1
,
spect_len
,
CV_32FC2
,
image_spect
);
createContinuous
(
1
,
spect_len
,
CV_32FC2
,
templ_spect
);
createContinuous
(
1
,
spect_len
,
CV_32FC2
,
result_spect
);
block_size
.
width
=
std
::
min
(
dft_size
.
width
-
templ_size
.
width
+
1
,
result_size
.
width
);
block_size
.
height
=
std
::
min
(
dft_size
.
height
-
templ_size
.
height
+
1
,
result_size
.
height
);
}
int
scale
=
40
;
int
bh_min
=
1024
;
int
bw_min
=
1024
;
// Check whether we use Fermi generation or newer GPU
if
(
major
>=
2
)
{
bh_min
=
2048
;
bw_min
=
2048
;
}
Size
cv
::
gpu
::
ConvolveBuf
::
estimateBlockSize
(
Size
result_size
,
Size
templ_size
)
{
int
major
,
minor
;
getComputeCapability
(
getDevice
(),
major
,
minor
);
bw
=
std
::
max
(
tw
*
scale
,
bw_min
);
bh
=
std
::
max
(
th
*
scale
,
bh_min
);
bw
=
std
::
min
(
bw
,
w
);
bh
=
std
::
min
(
bh
,
h
);
int
scale
=
40
;
Size
bsize_min
(
1024
,
1024
);
// Check whether we use Fermi generation or newer GPU
if
(
major
>=
2
)
{
bsize_min
.
width
=
2048
;
bsize_min
.
height
=
2048
;
}
Size
bsize
(
std
::
max
(
templ_size
.
width
*
scale
,
bsize_min
.
width
),
std
::
max
(
templ_size
.
height
*
scale
,
bsize_min
.
height
));
bsize
.
width
=
std
::
min
(
bsize
.
width
,
result_size
.
width
);
bsize
.
height
=
std
::
min
(
bsize
.
height
,
result_size
.
height
);
return
bsize
;
}
void
cv
::
gpu
::
convolve
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
bool
ccorr
)
{
ConvolveBuf
buf
;
convolve
(
image
,
templ
,
result
,
ccorr
,
buf
);
}
void
cv
::
gpu
::
convolve
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
bool
ccorr
)
void
cv
::
gpu
::
convolve
(
const
GpuMat
&
image
,
const
GpuMat
&
templ
,
GpuMat
&
result
,
bool
ccorr
,
ConvolveBuf
&
buf
)
{
StaticAssert
<
sizeof
(
float
)
==
sizeof
(
cufftReal
)
>::
check
();
StaticAssert
<
sizeof
(
float
)
*
2
==
sizeof
(
cufftComplex
)
>::
check
();
...
...
@@ -1248,32 +1279,25 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result,
CV_Assert
(
image
.
type
()
==
CV_32F
);
CV_Assert
(
templ
.
type
()
==
CV_32F
);
result
.
create
(
image
.
rows
-
templ
.
rows
+
1
,
image
.
cols
-
templ
.
cols
+
1
,
CV_32F
);
buf
.
create
(
image
.
size
(),
templ
.
size
());
result
.
create
(
buf
.
result_size
,
CV_32F
);
Size
block_size
;
convolveOptBlockSize
(
result
.
cols
,
result
.
rows
,
templ
.
cols
,
templ
.
rows
,
block_size
.
width
,
block_size
.
height
)
;
Size
&
block_size
=
buf
.
block_size
;
Size
&
dft_size
=
buf
.
dft_size
;
int
&
spect_len
=
buf
.
spect_len
;
Size
dft_size
;
dft_size
.
width
=
getOptimalDFTSize
(
block_size
.
width
+
templ
.
cols
-
1
)
;
dft_size
.
height
=
getOptimalDFTSize
(
block_size
.
width
+
templ
.
rows
-
1
)
;
GpuMat
&
image_block
=
buf
.
image_block
;
GpuMat
&
templ_block
=
buf
.
templ_block
;
GpuMat
&
result_data
=
buf
.
result_data
;
block_size
.
width
=
std
::
min
(
dft_size
.
width
-
templ
.
cols
+
1
,
result
.
cols
);
block_size
.
height
=
std
::
min
(
dft_size
.
height
-
templ
.
rows
+
1
,
result
.
rows
);
int
spect_len
=
dft_size
.
height
*
(
dft_size
.
width
/
2
+
1
);
GpuMat
image_spect
=
createContinuous
(
1
,
spect_len
,
CV_32FC2
);
GpuMat
templ_spect
=
createContinuous
(
1
,
spect_len
,
CV_32FC2
);
GpuMat
result_spect
=
createContinuous
(
1
,
spect_len
,
CV_32FC2
);
GpuMat
&
image_spect
=
buf
.
image_spect
;
GpuMat
&
templ_spect
=
buf
.
templ_spect
;
GpuMat
&
result_spect
=
buf
.
result_spect
;
cufftHandle
planR2C
,
planC2R
;
cufftSafeCall
(
cufftPlan2d
(
&
planC2R
,
dft_size
.
height
,
dft_size
.
width
,
CUFFT_C2R
));
cufftSafeCall
(
cufftPlan2d
(
&
planR2C
,
dft_size
.
height
,
dft_size
.
width
,
CUFFT_R2C
));
GpuMat
image_block
=
createContinuous
(
dft_size
,
CV_32F
);
GpuMat
templ_block
=
createContinuous
(
dft_size
,
CV_32F
);
GpuMat
result_data
=
createContinuous
(
dft_size
,
CV_32F
);
GpuMat
templ_roi
(
templ
.
size
(),
CV_32F
,
templ
.
data
,
templ
.
step
);
copyMakeBorder
(
templ_roi
,
templ_block
,
0
,
templ_block
.
rows
-
templ_roi
.
rows
,
0
,
templ_block
.
cols
-
templ_roi
.
cols
,
0
);
...
...
@@ -1288,9 +1312,10 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result,
{
Size
image_roi_size
(
std
::
min
(
x
+
dft_size
.
width
,
image
.
cols
)
-
x
,
std
::
min
(
y
+
dft_size
.
height
,
image
.
rows
)
-
y
);
GpuMat
image_roi
(
image_roi_size
,
CV_32F
,
(
void
*
)(
image
.
ptr
<
float
>
(
y
)
+
x
),
image
.
step
);
copyMakeBorder
(
image_roi
,
image_block
,
0
,
image_block
.
rows
-
image_roi
.
rows
,
0
,
image_block
.
cols
-
image_roi
.
cols
,
0
);
GpuMat
image_roi
(
image_roi_size
,
CV_32F
,
(
void
*
)(
image
.
ptr
<
float
>
(
y
)
+
x
),
image
.
step
);
copyMakeBorder
(
image_roi
,
image_block
,
0
,
image_block
.
rows
-
image_roi
.
rows
,
0
,
image_block
.
cols
-
image_roi
.
cols
,
0
);
cufftSafeCall
(
cufftExecR2C
(
planR2C
,
image_block
.
ptr
<
cufftReal
>
(),
image_spect
.
ptr
<
cufftComplex
>
()));
...
...
@@ -1301,8 +1326,10 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result,
Size
result_roi_size
(
std
::
min
(
x
+
block_size
.
width
,
result
.
cols
)
-
x
,
std
::
min
(
y
+
block_size
.
height
,
result
.
rows
)
-
y
);
GpuMat
result_roi
(
result_roi_size
,
result
.
type
(),
(
void
*
)(
result
.
ptr
<
float
>
(
y
)
+
x
),
result
.
step
);
GpuMat
result_block
(
result_roi_size
,
result_data
.
type
(),
result_data
.
ptr
(),
result_data
.
step
);
GpuMat
result_roi
(
result_roi_size
,
result
.
type
(),
(
void
*
)(
result
.
ptr
<
float
>
(
y
)
+
x
),
result
.
step
);
GpuMat
result_block
(
result_roi_size
,
result_data
.
type
(),
result_data
.
ptr
(),
result_data
.
step
);
result_block
.
copyTo
(
result_roi
);
}
}
...
...
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