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
3c191777
Commit
3c191777
authored
Mar 05, 2014
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modified OpenCL SURF API and the tests in 2.4.x to prove that it gives different from CPU results
parent
ba451350
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
136 additions
and
14 deletions
+136
-14
ocl.hpp
modules/nonfree/include/opencv2/nonfree/ocl.hpp
+19
-3
nonfree_init.cpp
modules/nonfree/src/nonfree_init.cpp
+14
-0
surf_ocl.cpp
modules/nonfree/src/surf_ocl.cpp
+80
-0
test_features2d.cpp
modules/nonfree/test/test_features2d.cpp
+11
-5
test_rotation_and_scale_invariance.cpp
modules/nonfree/test/test_rotation_and_scale_invariance.cpp
+12
-6
No files found.
modules/nonfree/include/opencv2/nonfree/ocl.hpp
View file @
3c191777
...
@@ -53,7 +53,7 @@ namespace cv
...
@@ -53,7 +53,7 @@ namespace cv
//! Speeded up robust features, port from GPU module.
//! Speeded up robust features, port from GPU module.
////////////////////////////////// SURF //////////////////////////////////////////
////////////////////////////////// SURF //////////////////////////////////////////
class
CV_EXPORTS
SURF_OCL
class
CV_EXPORTS
SURF_OCL
:
public
Feature2D
{
{
public
:
public
:
enum
KeypointLayout
enum
KeypointLayout
...
@@ -72,10 +72,13 @@ namespace cv
...
@@ -72,10 +72,13 @@ namespace cv
SURF_OCL
();
SURF_OCL
();
//! the full constructor taking all the necessary parameters
//! the full constructor taking all the necessary parameters
explicit
SURF_OCL
(
double
_hessianThreshold
,
int
_nOctaves
=
4
,
explicit
SURF_OCL
(
double
_hessianThreshold
,
int
_nOctaves
=
4
,
int
_nOctaveLayers
=
2
,
bool
_extended
=
fals
e
,
float
_keypointsRatio
=
0.01
f
,
bool
_upright
=
false
);
int
_nOctaveLayers
=
2
,
bool
_extended
=
tru
e
,
float
_keypointsRatio
=
0.01
f
,
bool
_upright
=
false
);
//! returns the descriptor size in float's (64 or 128)
//! returns the descriptor size in float's (64 or 128)
int
descriptorSize
()
const
;
int
descriptorSize
()
const
;
int
descriptorType
()
const
;
//! upload host keypoints to device memory
//! upload host keypoints to device memory
void
uploadKeypoints
(
const
vector
<
cv
::
KeyPoint
>
&
keypoints
,
oclMat
&
keypointsocl
);
void
uploadKeypoints
(
const
vector
<
cv
::
KeyPoint
>
&
keypoints
,
oclMat
&
keypointsocl
);
//! download keypoints from device to host memory
//! download keypoints from device to host memory
...
@@ -103,6 +106,17 @@ namespace cv
...
@@ -103,6 +106,17 @@ namespace cv
void
operator
()(
const
oclMat
&
img
,
const
oclMat
&
mask
,
std
::
vector
<
KeyPoint
>
&
keypoints
,
std
::
vector
<
float
>
&
descriptors
,
void
operator
()(
const
oclMat
&
img
,
const
oclMat
&
mask
,
std
::
vector
<
KeyPoint
>
&
keypoints
,
std
::
vector
<
float
>
&
descriptors
,
bool
useProvidedKeypoints
=
false
);
bool
useProvidedKeypoints
=
false
);
//! finds the keypoints using fast hessian detector used in SURF
void
operator
()(
InputArray
img
,
InputArray
mask
,
CV_OUT
vector
<
KeyPoint
>&
keypoints
)
const
;
//! finds the keypoints and computes their descriptors. Optionally it can compute descriptors for the user-provided keypoints
void
operator
()(
InputArray
img
,
InputArray
mask
,
CV_OUT
vector
<
KeyPoint
>&
keypoints
,
OutputArray
descriptors
,
bool
useProvidedKeypoints
=
false
)
const
;
AlgorithmInfo
*
info
()
const
;
void
releaseMemory
();
void
releaseMemory
();
// SURF parameters
// SURF parameters
...
@@ -116,7 +130,9 @@ namespace cv
...
@@ -116,7 +130,9 @@ namespace cv
oclMat
sum
,
mask1
,
maskSum
,
intBuffer
;
oclMat
sum
,
mask1
,
maskSum
,
intBuffer
;
oclMat
det
,
trace
;
oclMat
det
,
trace
;
oclMat
maxPosBuffer
;
oclMat
maxPosBuffer
;
protected
:
void
detectImpl
(
const
Mat
&
image
,
vector
<
KeyPoint
>&
keypoints
,
const
Mat
&
mask
)
const
;
void
computeImpl
(
const
Mat
&
image
,
vector
<
KeyPoint
>&
keypoints
,
Mat
&
descriptors
)
const
;
};
};
}
}
}
}
...
...
modules/nonfree/src/nonfree_init.cpp
View file @
3c191777
...
@@ -63,6 +63,20 @@ CV_INIT_ALGORITHM(SIFT, "Feature2D.SIFT",
...
@@ -63,6 +63,20 @@ CV_INIT_ALGORITHM(SIFT, "Feature2D.SIFT",
obj
.
info
()
->
addParam
(
obj
,
"edgeThreshold"
,
obj
.
edgeThreshold
);
obj
.
info
()
->
addParam
(
obj
,
"edgeThreshold"
,
obj
.
edgeThreshold
);
obj
.
info
()
->
addParam
(
obj
,
"sigma"
,
obj
.
sigma
))
obj
.
info
()
->
addParam
(
obj
,
"sigma"
,
obj
.
sigma
))
#ifdef HAVE_OPENCV_OCL
namespace
ocl
{
CV_INIT_ALGORITHM
(
SURF_OCL
,
"Feature2D.SURF_OCL"
,
obj
.
info
()
->
addParam
(
obj
,
"hessianThreshold"
,
obj
.
hessianThreshold
);
obj
.
info
()
->
addParam
(
obj
,
"nOctaves"
,
obj
.
nOctaves
);
obj
.
info
()
->
addParam
(
obj
,
"nOctaveLayers"
,
obj
.
nOctaveLayers
);
obj
.
info
()
->
addParam
(
obj
,
"extended"
,
obj
.
extended
);
obj
.
info
()
->
addParam
(
obj
,
"upright"
,
obj
.
upright
))
}
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
bool
initModule_nonfree
(
void
)
bool
initModule_nonfree
(
void
)
...
...
modules/nonfree/src/surf_ocl.cpp
View file @
3c191777
...
@@ -305,6 +305,11 @@ int cv::ocl::SURF_OCL::descriptorSize() const
...
@@ -305,6 +305,11 @@ int cv::ocl::SURF_OCL::descriptorSize() const
return
extended
?
128
:
64
;
return
extended
?
128
:
64
;
}
}
int
cv
::
ocl
::
SURF_OCL
::
descriptorType
()
const
{
return
CV_32F
;
}
void
cv
::
ocl
::
SURF_OCL
::
uploadKeypoints
(
const
vector
<
KeyPoint
>
&
keypoints
,
oclMat
&
keypointsGPU
)
void
cv
::
ocl
::
SURF_OCL
::
uploadKeypoints
(
const
vector
<
KeyPoint
>
&
keypoints
,
oclMat
&
keypointsGPU
)
{
{
if
(
keypoints
.
empty
())
if
(
keypoints
.
empty
())
...
@@ -447,6 +452,81 @@ void cv::ocl::SURF_OCL::operator()(const oclMat &img, const oclMat &mask, vector
...
@@ -447,6 +452,81 @@ void cv::ocl::SURF_OCL::operator()(const oclMat &img, const oclMat &mask, vector
downloadDescriptors
(
descriptorsGPU
,
descriptors
);
downloadDescriptors
(
descriptorsGPU
,
descriptors
);
}
}
void
cv
::
ocl
::
SURF_OCL
::
operator
()(
InputArray
img
,
InputArray
mask
,
CV_OUT
vector
<
KeyPoint
>&
keypoints
)
const
{
this
->
operator
()(
img
,
mask
,
keypoints
,
noArray
(),
false
);
}
void
cv
::
ocl
::
SURF_OCL
::
operator
()(
InputArray
img
,
InputArray
mask
,
vector
<
KeyPoint
>
&
keypoints
,
OutputArray
descriptors
,
bool
useProvidedKeypoints
)
const
{
oclMat
_img
,
_mask
;
if
(
img
.
kind
()
==
_InputArray
::
OCL_MAT
)
_img
=
*
(
oclMat
*
)
img
.
obj
;
else
_img
.
upload
(
img
.
getMat
());
if
(
_img
.
channels
()
!=
1
)
{
oclMat
temp
;
cvtColor
(
_img
,
temp
,
COLOR_BGR2GRAY
);
_img
=
temp
;
}
if
(
!
mask
.
empty
()
)
{
if
(
mask
.
kind
()
==
_InputArray
::
OCL_MAT
)
_mask
=
*
(
oclMat
*
)
mask
.
obj
;
else
_mask
.
upload
(
mask
.
getMat
());
}
SURF_OCL_Invoker
surf
((
SURF_OCL
&
)
*
this
,
_img
,
_mask
);
oclMat
keypointsGPU
;
if
(
!
useProvidedKeypoints
||
!
upright
)
((
SURF_OCL
*
)
this
)
->
uploadKeypoints
(
keypoints
,
keypointsGPU
);
if
(
!
useProvidedKeypoints
)
surf
.
detectKeypoints
(
keypointsGPU
);
else
if
(
!
upright
)
surf
.
findOrientation
(
keypointsGPU
);
if
(
keypointsGPU
.
cols
*
keypointsGPU
.
rows
!=
0
)
((
SURF_OCL
*
)
this
)
->
downloadKeypoints
(
keypointsGPU
,
keypoints
);
if
(
descriptors
.
needed
()
)
{
oclMat
descriptorsGPU
;
surf
.
computeDescriptors
(
keypointsGPU
,
descriptorsGPU
,
descriptorSize
());
Size
sz
=
descriptorsGPU
.
size
();
if
(
descriptors
.
kind
()
==
_InputArray
::
STD_VECTOR
)
{
CV_Assert
(
descriptors
.
type
()
==
CV_32F
);
std
::
vector
<
float
>*
v
=
(
std
::
vector
<
float
>*
)
descriptors
.
obj
;
v
->
resize
(
sz
.
width
*
sz
.
height
);
Mat
m
(
sz
,
CV_32F
,
&
v
->
at
(
0
));
descriptorsGPU
.
download
(
m
);
}
else
{
descriptors
.
create
(
sz
,
CV_32F
);
Mat
m
=
descriptors
.
getMat
();
descriptorsGPU
.
download
(
m
);
}
}
}
void
cv
::
ocl
::
SURF_OCL
::
detectImpl
(
const
Mat
&
image
,
vector
<
KeyPoint
>&
keypoints
,
const
Mat
&
mask
)
const
{
(
*
this
)(
image
,
mask
,
keypoints
,
noArray
(),
false
);
}
void
cv
::
ocl
::
SURF_OCL
::
computeImpl
(
const
Mat
&
image
,
vector
<
KeyPoint
>&
keypoints
,
Mat
&
descriptors
)
const
{
(
*
this
)(
image
,
Mat
(),
keypoints
,
descriptors
,
true
);
}
void
cv
::
ocl
::
SURF_OCL
::
releaseMemory
()
void
cv
::
ocl
::
SURF_OCL
::
releaseMemory
()
{
{
sum
.
release
();
sum
.
release
();
...
...
modules/nonfree/test/test_features2d.cpp
View file @
3c191777
...
@@ -50,6 +50,12 @@ const string DETECTOR_DIR = FEATURES2D_DIR + "/feature_detectors";
...
@@ -50,6 +50,12 @@ const string DETECTOR_DIR = FEATURES2D_DIR + "/feature_detectors";
const
string
DESCRIPTOR_DIR
=
FEATURES2D_DIR
+
"/descriptor_extractors"
;
const
string
DESCRIPTOR_DIR
=
FEATURES2D_DIR
+
"/descriptor_extractors"
;
const
string
IMAGE_FILENAME
=
"tsukuba.png"
;
const
string
IMAGE_FILENAME
=
"tsukuba.png"
;
#ifdef HAVE_OPENCV_OCL
#define SURF_NAME "SURF_OCL"
#else
#define SURF_NAME "SURF"
#endif
/****************************************************************************************\
/****************************************************************************************\
* Regression tests for feature detectors comparing keypoints. *
* Regression tests for feature detectors comparing keypoints. *
\****************************************************************************************/
\****************************************************************************************/
...
@@ -978,7 +984,7 @@ TEST( Features2d_Detector_SIFT, regression )
...
@@ -978,7 +984,7 @@ TEST( Features2d_Detector_SIFT, regression )
TEST
(
Features2d_Detector_SURF
,
regression
)
TEST
(
Features2d_Detector_SURF
,
regression
)
{
{
CV_FeatureDetectorTest
test
(
"detector-surf"
,
FeatureDetector
::
create
(
"SURF"
)
);
CV_FeatureDetectorTest
test
(
"detector-surf"
,
FeatureDetector
::
create
(
SURF_NAME
)
);
test
.
safe_run
();
test
.
safe_run
();
}
}
...
@@ -995,7 +1001,7 @@ TEST( Features2d_DescriptorExtractor_SIFT, regression )
...
@@ -995,7 +1001,7 @@ TEST( Features2d_DescriptorExtractor_SIFT, regression )
TEST
(
Features2d_DescriptorExtractor_SURF
,
regression
)
TEST
(
Features2d_DescriptorExtractor_SURF
,
regression
)
{
{
CV_DescriptorExtractorTest
<
L2
<
float
>
>
test
(
"descriptor-surf"
,
0.05
f
,
CV_DescriptorExtractorTest
<
L2
<
float
>
>
test
(
"descriptor-surf"
,
0.05
f
,
DescriptorExtractor
::
create
(
"SURF"
)
);
DescriptorExtractor
::
create
(
SURF_NAME
)
);
test
.
safe_run
();
test
.
safe_run
();
}
}
...
@@ -1036,10 +1042,10 @@ TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression)
...
@@ -1036,10 +1042,10 @@ TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression)
const
int
sz
=
100
;
const
int
sz
=
100
;
const
int
k
=
3
;
const
int
k
=
3
;
Ptr
<
DescriptorExtractor
>
ext
=
DescriptorExtractor
::
create
(
"SURF"
);
Ptr
<
DescriptorExtractor
>
ext
=
DescriptorExtractor
::
create
(
SURF_NAME
);
ASSERT_TRUE
(
ext
!=
NULL
);
ASSERT_TRUE
(
ext
!=
NULL
);
Ptr
<
FeatureDetector
>
det
=
FeatureDetector
::
create
(
"SURF"
);
Ptr
<
FeatureDetector
>
det
=
FeatureDetector
::
create
(
SURF_NAME
);
//"%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"
//"%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"
ASSERT_TRUE
(
det
!=
NULL
);
ASSERT_TRUE
(
det
!=
NULL
);
...
@@ -1144,7 +1150,7 @@ protected:
...
@@ -1144,7 +1150,7 @@ protected:
};
};
TEST
(
Features2d_SIFTHomographyTest
,
regression
)
{
CV_DetectPlanarTest
test
(
"SIFT"
,
80
);
test
.
safe_run
();
}
TEST
(
Features2d_SIFTHomographyTest
,
regression
)
{
CV_DetectPlanarTest
test
(
"SIFT"
,
80
);
test
.
safe_run
();
}
TEST
(
Features2d_SURFHomographyTest
,
regression
)
{
CV_DetectPlanarTest
test
(
"SURF"
,
80
);
test
.
safe_run
();
}
TEST
(
Features2d_SURFHomographyTest
,
regression
)
{
CV_DetectPlanarTest
test
(
SURF_NAME
,
80
);
test
.
safe_run
();
}
class
FeatureDetectorUsingMaskTest
:
public
cvtest
::
BaseTest
class
FeatureDetectorUsingMaskTest
:
public
cvtest
::
BaseTest
{
{
...
...
modules/nonfree/test/test_rotation_and_scale_invariance.cpp
View file @
3c191777
...
@@ -48,6 +48,12 @@ using namespace cv;
...
@@ -48,6 +48,12 @@ using namespace cv;
const
string
IMAGE_TSUKUBA
=
"/features2d/tsukuba.png"
;
const
string
IMAGE_TSUKUBA
=
"/features2d/tsukuba.png"
;
const
string
IMAGE_BIKES
=
"/detectors_descriptors_evaluation/images_datasets/bikes/img1.png"
;
const
string
IMAGE_BIKES
=
"/detectors_descriptors_evaluation/images_datasets/bikes/img1.png"
;
#ifdef HAVE_OPENCV_OCL
#define SURF_NAME "Feature2D.SURF_OCL"
#else
#define SURF_NAME "Feature2D.SURF"
#endif
#define SHOW_DEBUG_LOG 0
#define SHOW_DEBUG_LOG 0
static
static
...
@@ -615,7 +621,7 @@ protected:
...
@@ -615,7 +621,7 @@ protected:
*/
*/
TEST
(
Features2d_RotationInvariance_Detector_SURF
,
regression
)
TEST
(
Features2d_RotationInvariance_Detector_SURF
,
regression
)
{
{
DetectorRotationInvarianceTest
test
(
Algorithm
::
create
<
FeatureDetector
>
(
"Feature2D.SURF"
),
DetectorRotationInvarianceTest
test
(
Algorithm
::
create
<
FeatureDetector
>
(
SURF_NAME
),
0.44
f
,
0.44
f
,
0.76
f
);
0.76
f
);
test
.
safe_run
();
test
.
safe_run
();
...
@@ -634,8 +640,8 @@ TEST(Features2d_RotationInvariance_Detector_SIFT, DISABLED_regression)
...
@@ -634,8 +640,8 @@ TEST(Features2d_RotationInvariance_Detector_SIFT, DISABLED_regression)
*/
*/
TEST
(
Features2d_RotationInvariance_Descriptor_SURF
,
regression
)
TEST
(
Features2d_RotationInvariance_Descriptor_SURF
,
regression
)
{
{
DescriptorRotationInvarianceTest
test
(
Algorithm
::
create
<
FeatureDetector
>
(
"Feature2D.SURF"
),
DescriptorRotationInvarianceTest
test
(
Algorithm
::
create
<
FeatureDetector
>
(
SURF_NAME
),
Algorithm
::
create
<
DescriptorExtractor
>
(
"Feature2D.SURF"
),
Algorithm
::
create
<
DescriptorExtractor
>
(
SURF_NAME
),
NORM_L1
,
NORM_L1
,
0.83
f
);
0.83
f
);
test
.
safe_run
();
test
.
safe_run
();
...
@@ -655,7 +661,7 @@ TEST(Features2d_RotationInvariance_Descriptor_SIFT, regression)
...
@@ -655,7 +661,7 @@ TEST(Features2d_RotationInvariance_Descriptor_SIFT, regression)
*/
*/
TEST
(
Features2d_ScaleInvariance_Detector_SURF
,
regression
)
TEST
(
Features2d_ScaleInvariance_Detector_SURF
,
regression
)
{
{
DetectorScaleInvarianceTest
test
(
Algorithm
::
create
<
FeatureDetector
>
(
"Feature2D.SURF"
),
DetectorScaleInvarianceTest
test
(
Algorithm
::
create
<
FeatureDetector
>
(
SURF_NAME
),
0.64
f
,
0.64
f
,
0.84
f
);
0.84
f
);
test
.
safe_run
();
test
.
safe_run
();
...
@@ -674,8 +680,8 @@ TEST(Features2d_ScaleInvariance_Detector_SIFT, regression)
...
@@ -674,8 +680,8 @@ TEST(Features2d_ScaleInvariance_Detector_SIFT, regression)
*/
*/
TEST
(
Features2d_ScaleInvariance_Descriptor_SURF
,
regression
)
TEST
(
Features2d_ScaleInvariance_Descriptor_SURF
,
regression
)
{
{
DescriptorScaleInvarianceTest
test
(
Algorithm
::
create
<
FeatureDetector
>
(
"Feature2D.SURF"
),
DescriptorScaleInvarianceTest
test
(
Algorithm
::
create
<
FeatureDetector
>
(
SURF_NAME
),
Algorithm
::
create
<
DescriptorExtractor
>
(
"Feature2D.SURF"
),
Algorithm
::
create
<
DescriptorExtractor
>
(
SURF_NAME
),
NORM_L1
,
NORM_L1
,
0.61
f
);
0.61
f
);
test
.
safe_run
();
test
.
safe_run
();
...
...
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