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
d40cb396
Commit
d40cb396
authored
Jun 29, 2014
by
Ilya Lavrenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SSE2 optimization of magnitude calculation
parent
2d81595e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
2 deletions
+46
-2
canny.cpp
modules/imgproc/src/canny.cpp
+46
-2
No files found.
modules/imgproc/src/canny.cpp
View file @
d40cb396
...
@@ -348,6 +348,10 @@ void cv::Canny( InputArray _src, OutputArray _dst,
...
@@ -348,6 +348,10 @@ void cv::Canny( InputArray _src, OutputArray _dst,
#define CANNY_PUSH(d) *(d) = uchar(2), *stack_top++ = (d)
#define CANNY_PUSH(d) *(d) = uchar(2), *stack_top++ = (d)
#define CANNY_POP(d) (d) = *--stack_top
#define CANNY_POP(d) (d) = *--stack_top
#if CV_SSE2
bool
haveSSE2
=
checkHardwareSupport
(
CV_CPU_SSE2
);
#endif
// calculate magnitude and angle of gradient, perform non-maxima suppression.
// calculate magnitude and angle of gradient, perform non-maxima suppression.
// fill the map with one of the following values:
// fill the map with one of the following values:
// 0 - the pixel might belong to an edge
// 0 - the pixel might belong to an edge
...
@@ -363,12 +367,52 @@ void cv::Canny( InputArray _src, OutputArray _dst,
...
@@ -363,12 +367,52 @@ void cv::Canny( InputArray _src, OutputArray _dst,
if
(
!
L2gradient
)
if
(
!
L2gradient
)
{
{
for
(
int
j
=
0
;
j
<
src
.
cols
*
cn
;
j
++
)
int
j
=
0
,
width
=
src
.
cols
*
cn
;
#if CV_SSE2
if
(
haveSSE2
)
{
__m128i
v_zero
=
_mm_setzero_si128
();
for
(
;
j
<=
width
-
8
;
j
+=
8
)
{
__m128i
v_dx
=
_mm_loadu_si128
((
const
__m128i
*
)(
_dx
+
j
));
__m128i
v_dy
=
_mm_loadu_si128
((
const
__m128i
*
)(
_dy
+
j
));
v_dx
=
_mm_max_epi16
(
v_dx
,
_mm_sub_epi16
(
v_zero
,
v_dx
));
v_dy
=
_mm_max_epi16
(
v_dy
,
_mm_sub_epi16
(
v_zero
,
v_dy
));
__m128i
v_norm
=
_mm_add_epi32
(
_mm_unpacklo_epi16
(
v_dx
,
v_zero
),
_mm_unpacklo_epi16
(
v_dy
,
v_zero
));
_mm_storeu_si128
((
__m128i
*
)(
_norm
+
j
),
v_norm
);
v_norm
=
_mm_add_epi32
(
_mm_unpackhi_epi16
(
v_dx
,
v_zero
),
_mm_unpackhi_epi16
(
v_dy
,
v_zero
));
_mm_storeu_si128
((
__m128i
*
)(
_norm
+
j
+
4
),
v_norm
);
}
}
#endif
for
(
;
j
<
width
;
++
j
)
_norm
[
j
]
=
std
::
abs
(
int
(
_dx
[
j
]))
+
std
::
abs
(
int
(
_dy
[
j
]));
_norm
[
j
]
=
std
::
abs
(
int
(
_dx
[
j
]))
+
std
::
abs
(
int
(
_dy
[
j
]));
}
}
else
else
{
{
for
(
int
j
=
0
;
j
<
src
.
cols
*
cn
;
j
++
)
int
j
=
0
,
width
=
src
.
cols
*
cn
;
#if CV_SSE2
if
(
haveSSE2
)
{
for
(
;
j
<=
width
-
8
;
j
+=
8
)
{
__m128i
v_dx
=
_mm_loadu_si128
((
const
__m128i
*
)(
_dx
+
j
));
__m128i
v_dy
=
_mm_loadu_si128
((
const
__m128i
*
)(
_dy
+
j
));
__m128i
v_dx_ml
=
_mm_mullo_epi16
(
v_dx
,
v_dx
),
v_dx_mh
=
_mm_mulhi_epi16
(
v_dx
,
v_dx
);
__m128i
v_dy_ml
=
_mm_mullo_epi16
(
v_dy
,
v_dy
),
v_dy_mh
=
_mm_mulhi_epi16
(
v_dy
,
v_dy
);
__m128i
v_norm
=
_mm_add_epi32
(
_mm_unpacklo_epi16
(
v_dx_ml
,
v_dx_mh
),
_mm_unpacklo_epi16
(
v_dy_ml
,
v_dy_mh
));
_mm_storeu_si128
((
__m128i
*
)(
_norm
+
j
),
v_norm
);
v_norm
=
_mm_add_epi32
(
_mm_unpackhi_epi16
(
v_dx_ml
,
v_dx_mh
),
_mm_unpackhi_epi16
(
v_dy_ml
,
v_dy_mh
));
_mm_storeu_si128
((
__m128i
*
)(
_norm
+
j
+
4
),
v_norm
);
}
}
#endif
for
(
;
j
<
width
;
++
j
)
_norm
[
j
]
=
int
(
_dx
[
j
])
*
_dx
[
j
]
+
int
(
_dy
[
j
])
*
_dy
[
j
];
_norm
[
j
]
=
int
(
_dx
[
j
])
*
_dx
[
j
]
+
int
(
_dy
[
j
])
*
_dy
[
j
];
}
}
...
...
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