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
28716d7f
Commit
28716d7f
authored
Nov 12, 2012
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Canny
parent
e2995956
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
82 deletions
+51
-82
gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+8
-16
canny.cu
modules/gpu/src/cuda/canny.cu
+0
-0
imgproc.cpp
modules/gpu/src/imgproc.cpp
+42
-65
test_imgproc.cpp
modules/gpu/test/test_imgproc.cpp
+1
-1
No files found.
modules/gpu/include/opencv2/gpu/gpu.hpp
View file @
28716d7f
...
...
@@ -792,31 +792,23 @@ private:
GpuMat
lab
,
l
,
ab
;
};
struct
CV_EXPORTS
CannyBuf
;
CV_EXPORTS
void
Canny
(
const
GpuMat
&
image
,
GpuMat
&
edges
,
double
low_thresh
,
double
high_thresh
,
int
apperture_size
=
3
,
bool
L2gradient
=
false
);
CV_EXPORTS
void
Canny
(
const
GpuMat
&
image
,
CannyBuf
&
buf
,
GpuMat
&
edges
,
double
low_thresh
,
double
high_thresh
,
int
apperture_size
=
3
,
bool
L2gradient
=
false
);
CV_EXPORTS
void
Canny
(
const
GpuMat
&
dx
,
const
GpuMat
&
dy
,
GpuMat
&
edges
,
double
low_thresh
,
double
high_thresh
,
bool
L2gradient
=
false
);
CV_EXPORTS
void
Canny
(
const
GpuMat
&
dx
,
const
GpuMat
&
dy
,
CannyBuf
&
buf
,
GpuMat
&
edges
,
double
low_thresh
,
double
high_thresh
,
bool
L2gradient
=
false
);
struct
CV_EXPORTS
CannyBuf
{
CannyBuf
()
{}
explicit
CannyBuf
(
const
Size
&
image_size
,
int
apperture_size
=
3
)
{
create
(
image_size
,
apperture_size
);}
CannyBuf
(
const
GpuMat
&
dx_
,
const
GpuMat
&
dy_
);
void
create
(
const
Size
&
image_size
,
int
apperture_size
=
3
);
void
release
();
GpuMat
dx
,
dy
;
GpuMat
dx_buf
,
dy_buf
;
GpuMat
edgeBuf
;
GpuMat
trackBuf1
,
trackBuf
2
;
GpuMat
mag
;
GpuMat
map
;
GpuMat
st1
,
st
2
;
Ptr
<
FilterEngine_GPU
>
filterDX
,
filterDY
;
};
CV_EXPORTS
void
Canny
(
const
GpuMat
&
image
,
GpuMat
&
edges
,
double
low_thresh
,
double
high_thresh
,
int
apperture_size
=
3
,
bool
L2gradient
=
false
);
CV_EXPORTS
void
Canny
(
const
GpuMat
&
image
,
CannyBuf
&
buf
,
GpuMat
&
edges
,
double
low_thresh
,
double
high_thresh
,
int
apperture_size
=
3
,
bool
L2gradient
=
false
);
CV_EXPORTS
void
Canny
(
const
GpuMat
&
dx
,
const
GpuMat
&
dy
,
GpuMat
&
edges
,
double
low_thresh
,
double
high_thresh
,
bool
L2gradient
=
false
);
CV_EXPORTS
void
Canny
(
const
GpuMat
&
dx
,
const
GpuMat
&
dy
,
CannyBuf
&
buf
,
GpuMat
&
edges
,
double
low_thresh
,
double
high_thresh
,
bool
L2gradient
=
false
);
class
CV_EXPORTS
ImagePyramid
{
public
:
...
...
modules/gpu/src/cuda/canny.cu
View file @
28716d7f
This diff is collapsed.
Click to expand it.
modules/gpu/src/imgproc.cpp
View file @
28716d7f
...
...
@@ -91,7 +91,6 @@ void cv::gpu::Canny(const GpuMat&, GpuMat&, double, double, int, bool) { throw_n
void
cv
::
gpu
::
Canny
(
const
GpuMat
&
,
CannyBuf
&
,
GpuMat
&
,
double
,
double
,
int
,
bool
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
Canny
(
const
GpuMat
&
,
const
GpuMat
&
,
GpuMat
&
,
double
,
double
,
bool
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
Canny
(
const
GpuMat
&
,
const
GpuMat
&
,
CannyBuf
&
,
GpuMat
&
,
double
,
double
,
bool
)
{
throw_nogpu
();
}
cv
::
gpu
::
CannyBuf
::
CannyBuf
(
const
GpuMat
&
,
const
GpuMat
&
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
CannyBuf
::
create
(
const
Size
&
,
int
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
CannyBuf
::
release
()
{
throw_nogpu
();
}
...
...
@@ -1466,92 +1465,76 @@ void cv::gpu::convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result,
//////////////////////////////////////////////////////////////////////////////
// Canny
cv
::
gpu
::
CannyBuf
::
CannyBuf
(
const
GpuMat
&
dx_
,
const
GpuMat
&
dy_
)
:
dx
(
dx_
),
dy
(
dy_
)
{
CV_Assert
(
dx_
.
type
()
==
CV_32SC1
&&
dy_
.
type
()
==
CV_32SC1
&&
dx_
.
size
()
==
dy_
.
size
());
create
(
dx_
.
size
(),
-
1
);
}
void
cv
::
gpu
::
CannyBuf
::
create
(
const
Size
&
image_size
,
int
apperture_size
)
{
ensureSizeIsEnough
(
image_size
,
CV_32SC1
,
dx
);
ensureSizeIsEnough
(
image_size
,
CV_32SC1
,
dy
);
if
(
apperture_size
==
3
)
if
(
apperture_size
>
0
)
{
ensureSizeIsEnough
(
image_size
,
CV_32SC1
,
dx_buf
);
ensureSizeIsEnough
(
image_size
,
CV_32SC1
,
dy_buf
);
}
else
if
(
apperture_size
>
0
)
{
if
(
!
filterDX
)
ensureSizeIsEnough
(
image_size
,
CV_32SC1
,
dx
);
ensureSizeIsEnough
(
image_size
,
CV_32SC1
,
dy
);
if
(
apperture_size
!=
3
)
{
filterDX
=
createDerivFilter_GPU
(
CV_8UC1
,
CV_32S
,
1
,
0
,
apperture_size
,
BORDER_REPLICATE
);
if
(
!
filterDY
)
filterDY
=
createDerivFilter_GPU
(
CV_8UC1
,
CV_32S
,
0
,
1
,
apperture_size
,
BORDER_REPLICATE
);
}
}
ensureSizeIsEnough
(
image_size
.
height
+
2
,
image_size
.
width
+
2
,
CV_32FC1
,
edgeBuf
);
ensureSizeIsEnough
(
image_size
,
CV_32FC1
,
mag
);
ensureSizeIsEnough
(
image_size
,
CV_32SC1
,
map
);
ensureSizeIsEnough
(
1
,
image_size
.
width
*
image_size
.
height
,
CV_16UC2
,
trackBuf
1
);
ensureSizeIsEnough
(
1
,
image_size
.
width
*
image_size
.
height
,
CV_16UC2
,
trackBuf
2
);
ensureSizeIsEnough
(
1
,
image_size
.
area
(),
CV_16UC2
,
st
1
);
ensureSizeIsEnough
(
1
,
image_size
.
area
(),
CV_16UC2
,
st
2
);
}
void
cv
::
gpu
::
CannyBuf
::
release
()
{
dx
.
release
();
dy
.
release
();
dx_buf
.
release
();
dy_buf
.
release
();
edgeBuf
.
release
();
trackBuf1
.
release
();
trackBuf2
.
release
();
mag
.
release
();
map
.
release
();
st1
.
release
();
st2
.
release
();
}
namespace
c
v
{
namespace
gpu
{
namespace
device
namespace
c
anny
{
namespace
canny
{
void
calcSobelRowPass_gpu
(
PtrStepb
src
,
PtrStepi
dx_buf
,
PtrStepi
dy_buf
,
int
rows
,
int
cols
);
void
calcMagnitude_gpu
(
PtrStepi
dx_buf
,
PtrStepi
dy_buf
,
PtrStepi
dx
,
PtrStepi
dy
,
PtrStepf
mag
,
int
rows
,
int
cols
,
bool
L2Grad
);
void
calcMagnitude_gpu
(
PtrStepi
dx
,
PtrStepi
dy
,
PtrStepf
mag
,
int
rows
,
int
cols
,
bool
L2Grad
);
void
calcMagnitude
(
PtrStepSzb
srcWhole
,
int
xoff
,
int
yoff
,
PtrStepSzi
dx
,
PtrStepSzi
dy
,
PtrStepSzf
mag
,
bool
L2Grad
);
void
calcMagnitude
(
PtrStepSzi
dx
,
PtrStepSzi
dy
,
PtrStepSzf
mag
,
bool
L2Grad
);
void
calcMap_gpu
(
PtrStepi
dx
,
PtrStepi
dy
,
PtrStepf
mag
,
PtrStepi
map
,
int
rows
,
int
cols
,
float
low_thresh
,
float
high_thresh
);
void
calcMap
(
PtrStepSzi
dx
,
PtrStepSzi
dy
,
PtrStepSzf
mag
,
PtrStepSzi
map
,
float
low_thresh
,
float
high_thresh
);
void
edgesHysteresisLocal_gpu
(
PtrStepi
map
,
ushort2
*
st1
,
int
rows
,
int
cols
);
void
edgesHysteresisLocal
(
PtrStepSzi
map
,
ushort2
*
st1
);
void
edgesHysteresisGlobal_gpu
(
PtrStepi
map
,
ushort2
*
st1
,
ushort2
*
st2
,
int
rows
,
int
cols
);
void
edgesHysteresisGlobal
(
PtrStepSzi
map
,
ushort2
*
st1
,
ushort2
*
st2
);
void
getEdges_gpu
(
PtrStepi
map
,
PtrStepb
dst
,
int
rows
,
int
cols
);
}
}}}
void
getEdges
(
PtrStepSzi
map
,
PtrStepSzb
dst
);
}
namespace
{
void
CannyCaller
(
CannyBuf
&
buf
,
GpuMat
&
dst
,
float
low_thresh
,
float
high_thresh
)
void
CannyCaller
(
const
GpuMat
&
dx
,
const
GpuMat
&
dy
,
CannyBuf
&
buf
,
GpuMat
&
dst
,
float
low_thresh
,
float
high_thresh
)
{
using
namespace
::
cv
::
gpu
::
device
::
canny
;
using
namespace
canny
;
calcMap
_gpu
(
buf
.
dx
,
buf
.
dy
,
buf
.
edgeBuf
,
buf
.
edgeBuf
,
dst
.
rows
,
dst
.
cols
,
low_thresh
,
high_thresh
);
calcMap
(
dx
,
dy
,
buf
.
mag
,
buf
.
map
,
low_thresh
,
high_thresh
);
edgesHysteresisLocal
_gpu
(
buf
.
edgeBuf
,
buf
.
trackBuf1
.
ptr
<
ushort2
>
(),
dst
.
rows
,
dst
.
cols
);
edgesHysteresisLocal
(
buf
.
map
,
buf
.
st1
.
ptr
<
ushort2
>
()
);
edgesHysteresisGlobal
_gpu
(
buf
.
edgeBuf
,
buf
.
trackBuf1
.
ptr
<
ushort2
>
(),
buf
.
trackBuf2
.
ptr
<
ushort2
>
(),
dst
.
rows
,
dst
.
cols
);
edgesHysteresisGlobal
(
buf
.
map
,
buf
.
st1
.
ptr
<
ushort2
>
(),
buf
.
st2
.
ptr
<
ushort2
>
()
);
getEdges
_gpu
(
buf
.
edgeBuf
,
dst
,
dst
.
rows
,
dst
.
cols
);
getEdges
(
buf
.
map
,
dst
);
}
}
void
cv
::
gpu
::
Canny
(
const
GpuMat
&
src
,
GpuMat
&
dst
,
double
low_thresh
,
double
high_thresh
,
int
apperture_size
,
bool
L2gradient
)
{
CannyBuf
buf
(
src
.
size
(),
apperture_size
)
;
CannyBuf
buf
;
Canny
(
src
,
buf
,
dst
,
low_thresh
,
high_thresh
,
apperture_size
,
L2gradient
);
}
void
cv
::
gpu
::
Canny
(
const
GpuMat
&
src
,
CannyBuf
&
buf
,
GpuMat
&
dst
,
double
low_thresh
,
double
high_thresh
,
int
apperture_size
,
bool
L2gradient
)
{
using
namespace
::
cv
::
gpu
::
device
::
canny
;
using
namespace
canny
;
CV_Assert
(
src
.
type
()
==
CV_8UC1
);
...
...
@@ -1562,37 +1545,37 @@ void cv::gpu::Canny(const GpuMat& src, CannyBuf& buf, GpuMat& dst, double low_th
std
::
swap
(
low_thresh
,
high_thresh
);
dst
.
create
(
src
.
size
(),
CV_8U
);
dst
.
setTo
(
Scalar
::
all
(
0
));
buf
.
create
(
src
.
size
(),
apperture_size
);
buf
.
edgeBuf
.
setTo
(
Scalar
::
all
(
0
));
if
(
apperture_size
==
3
)
{
calcSobelRowPass_gpu
(
src
,
buf
.
dx_buf
,
buf
.
dy_buf
,
src
.
rows
,
src
.
cols
);
Size
wholeSize
;
Point
ofs
;
src
.
locateROI
(
wholeSize
,
ofs
);
GpuMat
srcWhole
(
wholeSize
,
src
.
type
(),
src
.
datastart
,
src
.
step
);
calcMagnitude
_gpu
(
buf
.
dx_buf
,
buf
.
dy_buf
,
buf
.
dx
,
buf
.
dy
,
buf
.
edgeBuf
,
src
.
rows
,
src
.
cols
,
L2gradient
);
calcMagnitude
(
srcWhole
,
ofs
.
x
,
ofs
.
y
,
buf
.
dx
,
buf
.
dy
,
buf
.
mag
,
L2gradient
);
}
else
{
buf
.
filterDX
->
apply
(
src
,
buf
.
dx
,
Rect
(
0
,
0
,
src
.
cols
,
src
.
rows
));
buf
.
filterDY
->
apply
(
src
,
buf
.
dy
,
Rect
(
0
,
0
,
src
.
cols
,
src
.
rows
));
calcMagnitude
_gpu
(
buf
.
dx
,
buf
.
dy
,
buf
.
edgeBuf
,
src
.
rows
,
src
.
cols
,
L2gradient
);
calcMagnitude
(
buf
.
dx
,
buf
.
dy
,
buf
.
mag
,
L2gradient
);
}
CannyCaller
(
buf
,
dst
,
static_cast
<
float
>
(
low_thresh
),
static_cast
<
float
>
(
high_thresh
));
CannyCaller
(
buf
.
dx
,
buf
.
dy
,
buf
,
dst
,
static_cast
<
float
>
(
low_thresh
),
static_cast
<
float
>
(
high_thresh
));
}
void
cv
::
gpu
::
Canny
(
const
GpuMat
&
dx
,
const
GpuMat
&
dy
,
GpuMat
&
dst
,
double
low_thresh
,
double
high_thresh
,
bool
L2gradient
)
{
CannyBuf
buf
(
dx
,
dy
)
;
CannyBuf
buf
;
Canny
(
dx
,
dy
,
buf
,
dst
,
low_thresh
,
high_thresh
,
L2gradient
);
}
void
cv
::
gpu
::
Canny
(
const
GpuMat
&
dx
,
const
GpuMat
&
dy
,
CannyBuf
&
buf
,
GpuMat
&
dst
,
double
low_thresh
,
double
high_thresh
,
bool
L2gradient
)
{
using
namespace
::
cv
::
gpu
::
device
::
canny
;
using
namespace
canny
;
CV_Assert
(
TargetArchs
::
builtWith
(
SHARED_ATOMICS
)
&&
DeviceInfo
().
supports
(
SHARED_ATOMICS
));
CV_Assert
(
dx
.
type
()
==
CV_32SC1
&&
dy
.
type
()
==
CV_32SC1
&&
dx
.
size
()
==
dy
.
size
());
...
...
@@ -1601,17 +1584,11 @@ void cv::gpu::Canny(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& d
std
::
swap
(
low_thresh
,
high_thresh
);
dst
.
create
(
dx
.
size
(),
CV_8U
);
dst
.
setTo
(
Scalar
::
all
(
0
));
buf
.
dx
=
dx
;
buf
.
dy
=
dy
;
buf
.
create
(
dx
.
size
(),
-
1
);
buf
.
edgeBuf
.
setTo
(
Scalar
::
all
(
0
));
calcMagnitude
_gpu
(
dx
,
dy
,
buf
.
edgeBuf
,
dx
.
rows
,
dx
.
cols
,
L2gradient
);
calcMagnitude
(
dx
,
dy
,
buf
.
mag
,
L2gradient
);
CannyCaller
(
buf
,
dst
,
static_cast
<
float
>
(
low_thresh
),
static_cast
<
float
>
(
high_thresh
));
CannyCaller
(
dx
,
dy
,
buf
,
dst
,
static_cast
<
float
>
(
low_thresh
),
static_cast
<
float
>
(
high_thresh
));
}
#endif
/* !defined (HAVE_CUDA) */
modules/gpu/test/test_imgproc.cpp
View file @
28716d7f
...
...
@@ -313,7 +313,7 @@ TEST_P(Canny, Accuracy)
cv
::
Mat
edges_gold
;
cv
::
Canny
(
img
,
edges_gold
,
low_thresh
,
high_thresh
,
apperture_size
,
useL2gradient
);
EXPECT_MAT_SIMILAR
(
edges_gold
,
edges
,
1
e-2
);
EXPECT_MAT_SIMILAR
(
edges_gold
,
edges
,
2
e-2
);
}
}
...
...
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