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
647d4ae1
Commit
647d4ae1
authored
Aug 15, 2012
by
Vladislav Vinogradov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'hough-lines-gpu'
parents
3b07e977
7928cec6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
307 additions
and
3 deletions
+307
-3
gpumat.hpp
modules/core/include/opencv2/core/gpumat.hpp
+3
-0
gpumat.cpp
modules/core/src/gpumat.cpp
+1
-1
gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+6
-0
perf_imgproc.cpp
modules/gpu/perf/perf_imgproc.cpp
+47
-0
perf_imgproc.cpp
modules/gpu/perf_cpu/perf_imgproc.cpp
+41
-0
hough.cu
modules/gpu/src/cuda/hough.cu
+0
-0
hough.cpp
modules/gpu/src/hough.cpp
+144
-0
emulation.hpp
modules/gpu/src/opencv2/gpu/device/emulation.hpp
+4
-2
test_imgproc.cpp
modules/gpu/test/test_imgproc.cpp
+61
-0
No files found.
modules/core/include/opencv2/core/gpumat.hpp
View file @
647d4ae1
...
...
@@ -112,6 +112,8 @@ namespace cv { namespace gpu
int
multiProcessorCount
()
const
{
return
multi_processor_count_
;
}
size_t
sharedMemPerBlock
()
const
{
return
sharedMemPerBlock_
;
}
size_t
freeMemory
()
const
;
size_t
totalMemory
()
const
;
...
...
@@ -133,6 +135,7 @@ namespace cv { namespace gpu
int
multi_processor_count_
;
int
majorVersion_
;
int
minorVersion_
;
size_t
sharedMemPerBlock_
;
};
CV_EXPORTS
void
printCudaDeviceInfo
(
int
device
);
...
...
modules/core/src/gpumat.cpp
View file @
647d4ae1
...
...
@@ -42,7 +42,6 @@
#include "precomp.hpp"
#include "opencv2/core/gpumat.hpp"
#include <iostream>
#ifdef HAVE_CUDA
...
...
@@ -301,6 +300,7 @@ void cv::gpu::DeviceInfo::query()
multi_processor_count_
=
prop
.
multiProcessorCount
;
majorVersion_
=
prop
.
major
;
minorVersion_
=
prop
.
minor
;
sharedMemPerBlock_
=
prop
.
sharedMemPerBlock
;
}
void
cv
::
gpu
::
DeviceInfo
::
queryMemory
(
size_t
&
free_memory
,
size_t
&
total_memory
)
const
...
...
modules/gpu/include/opencv2/gpu/gpu.hpp
View file @
647d4ae1
...
...
@@ -820,6 +820,12 @@ private:
int
nLayers_
;
};
CV_EXPORTS
void
HoughLines
(
const
GpuMat
&
src
,
GpuMat
&
lines
,
float
rho
,
float
theta
,
int
threshold
,
bool
doSort
=
false
,
int
maxLines
=
4096
);
CV_EXPORTS
void
HoughLines
(
const
GpuMat
&
src
,
GpuMat
&
lines
,
GpuMat
&
accum
,
GpuMat
&
buf
,
float
rho
,
float
theta
,
int
threshold
,
bool
doSort
=
false
,
int
maxLines
=
4096
);
CV_EXPORTS
void
HoughLinesTransform
(
const
GpuMat
&
src
,
GpuMat
&
accum
,
GpuMat
&
buf
,
float
rho
,
float
theta
);
CV_EXPORTS
void
HoughLinesGet
(
const
GpuMat
&
accum
,
GpuMat
&
lines
,
float
rho
,
float
theta
,
int
threshold
,
bool
doSort
=
false
,
int
maxLines
=
4096
);
CV_EXPORTS
void
HoughLinesDownload
(
const
GpuMat
&
d_lines
,
OutputArray
h_lines
,
OutputArray
h_voices
=
noArray
());
////////////////////////////// Matrix reductions //////////////////////////////
//! computes mean value and standard deviation of all or selected array elements
...
...
modules/gpu/perf/perf_imgproc.cpp
View file @
647d4ae1
...
...
@@ -1331,4 +1331,51 @@ INSTANTIATE_TEST_CASE_P(ImgProc, ImagePyramid_getLayer, testing::Combine(
MatType
(
CV_16UC1
),
MatType
(
CV_16UC3
),
MatType
(
CV_16UC4
),
MatType
(
CV_32FC1
),
MatType
(
CV_32FC3
),
MatType
(
CV_32FC4
))));
//////////////////////////////////////////////////////////////////////
// HoughLines
IMPLEMENT_PARAM_CLASS
(
DoSort
,
bool
)
GPU_PERF_TEST
(
HoughLines
,
cv
::
gpu
::
DeviceInfo
,
cv
::
Size
,
DoSort
)
{
declare
.
time
(
30.0
);
const
cv
::
gpu
::
DeviceInfo
devInfo
=
GET_PARAM
(
0
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
const
cv
::
Size
size
=
GET_PARAM
(
1
);
const
bool
doSort
=
GET_PARAM
(
2
);
const
float
rho
=
1.0
f
;
const
float
theta
=
CV_PI
/
180.0
f
;
const
int
threshold
=
300
;
cv
::
RNG
rng
(
123456789
);
cv
::
Mat
src
(
size
,
CV_8UC1
,
cv
::
Scalar
::
all
(
0
));
const
int
numLines
=
rng
.
uniform
(
500
,
2000
);
for
(
int
i
=
0
;
i
<
numLines
;
++
i
)
{
cv
::
Point
p1
(
rng
.
uniform
(
0
,
src
.
cols
),
rng
.
uniform
(
0
,
src
.
rows
));
cv
::
Point
p2
(
rng
.
uniform
(
0
,
src
.
cols
),
rng
.
uniform
(
0
,
src
.
rows
));
cv
::
line
(
src
,
p1
,
p2
,
cv
::
Scalar
::
all
(
255
),
2
);
}
cv
::
gpu
::
GpuMat
d_src
(
src
);
cv
::
gpu
::
GpuMat
d_lines
;
cv
::
gpu
::
GpuMat
d_accum
;
cv
::
gpu
::
GpuMat
d_buf
;
cv
::
gpu
::
HoughLines
(
d_src
,
d_lines
,
d_accum
,
d_buf
,
rho
,
theta
,
threshold
,
doSort
);
TEST_CYCLE
()
{
cv
::
gpu
::
HoughLines
(
d_src
,
d_lines
,
d_accum
,
d_buf
,
rho
,
theta
,
threshold
,
doSort
);
}
}
INSTANTIATE_TEST_CASE_P
(
ImgProc
,
HoughLines
,
testing
::
Combine
(
ALL_DEVICES
,
GPU_TYPICAL_MAT_SIZES
,
testing
::
Values
(
DoSort
(
false
),
DoSort
(
true
))));
#endif
modules/gpu/perf_cpu/perf_imgproc.cpp
View file @
647d4ae1
...
...
@@ -727,4 +727,45 @@ INSTANTIATE_TEST_CASE_P(ImgProc, CvtColor, testing::Combine(
CvtColorInfo
(
1
,
3
,
cv
::
COLOR_BayerGR2BGR
),
CvtColorInfo
(
4
,
4
,
cv
::
COLOR_RGBA2mRGBA
))));
//////////////////////////////////////////////////////////////////////
// HoughLines
IMPLEMENT_PARAM_CLASS
(
DoSort
,
bool
)
GPU_PERF_TEST
(
HoughLines
,
cv
::
gpu
::
DeviceInfo
,
cv
::
Size
,
DoSort
)
{
declare
.
time
(
30.0
);
const
cv
::
Size
size
=
GET_PARAM
(
1
);
const
float
rho
=
1.0
f
;
const
float
theta
=
CV_PI
/
180.0
f
;
const
int
threshold
=
300
;
cv
::
RNG
rng
(
123456789
);
cv
::
Mat
src
(
size
,
CV_8UC1
,
cv
::
Scalar
::
all
(
0
));
const
int
numLines
=
rng
.
uniform
(
500
,
2000
);
for
(
int
i
=
0
;
i
<
numLines
;
++
i
)
{
cv
::
Point
p1
(
rng
.
uniform
(
0
,
src
.
cols
),
rng
.
uniform
(
0
,
src
.
rows
));
cv
::
Point
p2
(
rng
.
uniform
(
0
,
src
.
cols
),
rng
.
uniform
(
0
,
src
.
rows
));
cv
::
line
(
src
,
p1
,
p2
,
cv
::
Scalar
::
all
(
255
),
2
);
}
std
::
vector
<
cv
::
Vec2f
>
lines
;
cv
::
HoughLines
(
src
,
lines
,
rho
,
theta
,
threshold
);
TEST_CYCLE
()
{
cv
::
HoughLines
(
src
,
lines
,
rho
,
theta
,
threshold
);
}
}
INSTANTIATE_TEST_CASE_P
(
ImgProc
,
HoughLines
,
testing
::
Combine
(
ALL_DEVICES
,
GPU_TYPICAL_MAT_SIZES
,
testing
::
Values
(
DoSort
(
false
),
DoSort
(
true
))));
#endif
modules/gpu/src/cuda/hough.cu
0 → 100644
View file @
647d4ae1
This diff is collapsed.
Click to expand it.
modules/gpu/src/hough.cpp
0 → 100644
View file @
647d4ae1
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "precomp.hpp"
#if !defined (HAVE_CUDA)
void
cv
::
gpu
::
HoughLinesTransform
(
const
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
float
,
float
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
HoughLinesGet
(
const
GpuMat
&
,
GpuMat
&
,
float
,
float
,
int
,
bool
,
int
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
HoughLines
(
const
GpuMat
&
,
GpuMat
&
,
float
,
float
,
int
,
bool
,
int
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
HoughLines
(
const
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
GpuMat
&
,
float
,
float
,
int
,
bool
,
int
)
{
throw_nogpu
();
}
void
cv
::
gpu
::
HoughLinesDownload
(
const
GpuMat
&
,
OutputArray
,
OutputArray
)
{
throw_nogpu
();
}
#else
/* !defined (HAVE_CUDA) */
namespace
cv
{
namespace
gpu
{
namespace
device
{
namespace
hough
{
int
buildPointList_gpu
(
DevMem2Db
src
,
unsigned
int
*
list
);
void
linesAccum_gpu
(
const
unsigned
int
*
list
,
int
count
,
DevMem2Di
accum
,
float
rho
,
float
theta
,
size_t
sharedMemPerBlock
);
int
linesGetResult_gpu
(
DevMem2Di
accum
,
float2
*
out
,
int
*
voices
,
int
maxSize
,
float
rho
,
float
theta
,
float
threshold
,
bool
doSort
);
}
}}}
void
cv
::
gpu
::
HoughLinesTransform
(
const
GpuMat
&
src
,
GpuMat
&
accum
,
GpuMat
&
buf
,
float
rho
,
float
theta
)
{
using
namespace
cv
::
gpu
::
device
::
hough
;
CV_Assert
(
src
.
type
()
==
CV_8UC1
);
CV_Assert
(
src
.
cols
<
std
::
numeric_limits
<
unsigned
short
>::
max
());
CV_Assert
(
src
.
rows
<
std
::
numeric_limits
<
unsigned
short
>::
max
());
ensureSizeIsEnough
(
1
,
src
.
size
().
area
(),
CV_32SC1
,
buf
);
const
int
count
=
buildPointList_gpu
(
src
,
buf
.
ptr
<
unsigned
int
>
());
const
int
numangle
=
cvRound
(
CV_PI
/
theta
);
const
int
numrho
=
cvRound
(((
src
.
cols
+
src
.
rows
)
*
2
+
1
)
/
rho
);
CV_Assert
(
numangle
>
0
&&
numrho
>
0
);
ensureSizeIsEnough
(
numangle
+
2
,
numrho
+
2
,
CV_32SC1
,
accum
);
accum
.
setTo
(
cv
::
Scalar
::
all
(
0
));
cv
::
gpu
::
DeviceInfo
devInfo
;
if
(
count
>
0
)
linesAccum_gpu
(
buf
.
ptr
<
unsigned
int
>
(),
count
,
accum
,
rho
,
theta
,
devInfo
.
sharedMemPerBlock
());
}
void
cv
::
gpu
::
HoughLinesGet
(
const
GpuMat
&
accum
,
GpuMat
&
lines
,
float
rho
,
float
theta
,
int
threshold
,
bool
doSort
,
int
maxLines
)
{
using
namespace
cv
::
gpu
::
device
;
CV_Assert
(
accum
.
type
()
==
CV_32SC1
);
ensureSizeIsEnough
(
2
,
maxLines
,
CV_32FC2
,
lines
);
int
count
=
hough
::
linesGetResult_gpu
(
accum
,
lines
.
ptr
<
float2
>
(
0
),
lines
.
ptr
<
int
>
(
1
),
maxLines
,
rho
,
theta
,
threshold
,
doSort
);
if
(
count
>
0
)
lines
.
cols
=
count
;
else
lines
.
release
();
}
void
cv
::
gpu
::
HoughLines
(
const
GpuMat
&
src
,
GpuMat
&
lines
,
float
rho
,
float
theta
,
int
threshold
,
bool
doSort
,
int
maxLines
)
{
cv
::
gpu
::
GpuMat
accum
,
buf
;
HoughLines
(
src
,
lines
,
accum
,
buf
,
rho
,
theta
,
threshold
,
doSort
,
maxLines
);
}
void
cv
::
gpu
::
HoughLines
(
const
GpuMat
&
src
,
GpuMat
&
lines
,
GpuMat
&
accum
,
GpuMat
&
buf
,
float
rho
,
float
theta
,
int
threshold
,
bool
doSort
,
int
maxLines
)
{
HoughLinesTransform
(
src
,
accum
,
buf
,
rho
,
theta
);
HoughLinesGet
(
accum
,
lines
,
rho
,
theta
,
threshold
,
doSort
,
maxLines
);
}
void
cv
::
gpu
::
HoughLinesDownload
(
const
GpuMat
&
d_lines
,
OutputArray
h_lines_
,
OutputArray
h_voices_
)
{
if
(
d_lines
.
empty
())
{
h_lines_
.
release
();
if
(
h_voices_
.
needed
())
h_voices_
.
release
();
return
;
}
CV_Assert
(
d_lines
.
rows
==
2
&&
d_lines
.
type
()
==
CV_32FC2
);
h_lines_
.
create
(
1
,
d_lines
.
cols
,
CV_32FC2
);
cv
::
Mat
h_lines
=
h_lines_
.
getMat
();
d_lines
.
row
(
0
).
download
(
h_lines
);
if
(
h_voices_
.
needed
())
{
h_voices_
.
create
(
1
,
d_lines
.
cols
,
CV_32SC1
);
cv
::
Mat
h_voices
=
h_voices_
.
getMat
();
cv
::
gpu
::
GpuMat
d_voices
(
1
,
d_lines
.
cols
,
CV_32SC1
,
const_cast
<
int
*>
(
d_lines
.
ptr
<
int
>
(
1
)));
d_voices
.
download
(
h_voices
);
}
}
#endif
/* !defined (HAVE_CUDA) */
modules/gpu/src/opencv2/gpu/device/emulation.hpp
View file @
647d4ae1
...
...
@@ -99,7 +99,7 @@ namespace cv { namespace gpu { namespace device
}
template
<
typename
T
>
static
__device__
__forceinline__
void
atomicAdd
(
T
*
address
,
T
val
)
static
__device__
__forceinline__
T
atomicAdd
(
T
*
address
,
T
val
)
{
#if defined (__CUDA_ARCH__) && (__CUDA_ARCH__ < 120)
T
count
;
...
...
@@ -110,8 +110,10 @@ namespace cv { namespace gpu { namespace device
count
=
tag
|
(
count
+
val
);
*
address
=
count
;
}
while
(
*
address
!=
count
);
return
(
count
&
TAG_MASK
)
-
val
;
#else
::
atomicAdd
(
address
,
val
);
return
::
atomicAdd
(
address
,
val
);
#endif
}
...
...
modules/gpu/test/test_imgproc.cpp
View file @
647d4ae1
...
...
@@ -1124,4 +1124,65 @@ INSTANTIATE_TEST_CASE_P(GPU_ImgProc, CornerMinEigen, testing::Combine(
testing
::
Values
(
BlockSize
(
3
),
BlockSize
(
5
),
BlockSize
(
7
)),
testing
::
Values
(
ApertureSize
(
0
),
ApertureSize
(
3
),
ApertureSize
(
5
),
ApertureSize
(
7
))));
///////////////////////////////////////////////////////////////////////////////////////////////////////
// HoughLines
PARAM_TEST_CASE
(
HoughLines
,
cv
::
gpu
::
DeviceInfo
,
std
::
string
)
{
};
void
drawLines
(
cv
::
Mat
&
dst
,
const
std
::
vector
<
cv
::
Vec2f
>&
lines
)
{
for
(
size_t
i
=
0
;
i
<
lines
.
size
();
++
i
)
{
float
rho
=
lines
[
i
][
0
],
theta
=
lines
[
i
][
1
];
cv
::
Point
pt1
,
pt2
;
double
a
=
std
::
cos
(
theta
),
b
=
std
::
sin
(
theta
);
double
x0
=
a
*
rho
,
y0
=
b
*
rho
;
pt1
.
x
=
cvRound
(
x0
+
1000
*
(
-
b
));
pt1
.
y
=
cvRound
(
y0
+
1000
*
(
a
));
pt2
.
x
=
cvRound
(
x0
-
1000
*
(
-
b
));
pt2
.
y
=
cvRound
(
y0
-
1000
*
(
a
));
cv
::
line
(
dst
,
pt1
,
pt2
,
cv
::
Scalar
::
all
(
255
));
}
}
TEST_P
(
HoughLines
,
Accuracy
)
{
const
cv
::
gpu
::
DeviceInfo
devInfo
=
GET_PARAM
(
0
);
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
const
std
::
string
fileName
=
GET_PARAM
(
1
);
const
float
rho
=
1.0
f
;
const
float
theta
=
CV_PI
/
180.0
f
;
const
int
threshold
=
50
;
cv
::
Mat
img
=
readImage
(
fileName
,
cv
::
IMREAD_GRAYSCALE
);
ASSERT_FALSE
(
img
.
empty
());
cv
::
Mat
edges
;
cv
::
Canny
(
img
,
edges
,
50
,
200
);
cv
::
gpu
::
GpuMat
d_lines
;
cv
::
gpu
::
HoughLines
(
loadMat
(
edges
),
d_lines
,
rho
,
theta
,
threshold
);
std
::
vector
<
cv
::
Vec2f
>
lines
;
cv
::
gpu
::
HoughLinesDownload
(
d_lines
,
lines
);
cv
::
Mat
dst
(
img
.
size
(),
CV_8UC1
,
cv
::
Scalar
::
all
(
0
));
drawLines
(
dst
,
lines
);
std
::
vector
<
cv
::
Vec2f
>
lines_gold
;
cv
::
HoughLines
(
edges
,
lines_gold
,
rho
,
theta
,
threshold
);
cv
::
Mat
dst_gold
(
img
.
size
(),
CV_8UC1
,
cv
::
Scalar
::
all
(
0
));
drawLines
(
dst_gold
,
lines_gold
);
ASSERT_MAT_NEAR
(
dst_gold
,
dst
,
0.0
);
}
INSTANTIATE_TEST_CASE_P
(
GPU_ImgProc
,
HoughLines
,
testing
::
Combine
(
ALL_DEVICES
,
testing
::
Values
(
std
::
string
(
"../cv/shared/pic1.png"
),
std
::
string
(
"../cv/shared/pic3.png"
),
std
::
string
(
"../cv/shared/pic5.png"
),
std
::
string
(
"../cv/shared/pic6.png"
))));
}
// namespace
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