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
46498520
Commit
46498520
authored
Sep 05, 2013
by
Mathieu Barnachon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update PR after mdim review.
parent
43c98188
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
108 deletions
+22
-108
object_categorization.rst
modules/features2d/doc/object_categorization.rst
+7
-0
features2d.hpp
modules/features2d/include/opencv2/features2d.hpp
+3
-35
bagofwords.cpp
modules/features2d/src/bagofwords.cpp
+12
-73
No files found.
modules/features2d/doc/object_categorization.rst
View file @
46498520
...
...
@@ -118,6 +118,7 @@ The class declaration is the following: ::
public:
BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
const Ptr<DescriptorMatcher>& dmatcher );
BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher );
virtual ~BOWImgDescriptorExtractor(){}
void setVocabulary( const Mat& vocabulary );
...
...
@@ -126,6 +127,8 @@ The class declaration is the following: ::
Mat& imgDescriptor,
vector<vector<int> >* pointIdxsOfClusters=0,
Mat* descriptors=0 );
void compute( const Mat& descriptors, Mat& imgDescriptor,
std::vector<std::vector<int> >* pointIdxsOfClusters=0 );
int descriptorSize() const;
int descriptorType() const;
...
...
@@ -141,6 +144,7 @@ BOWImgDescriptorExtractor::BOWImgDescriptorExtractor
The constructor.
.. ocv:function:: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor, const Ptr<DescriptorMatcher>& dmatcher )
.. ocv:function:: BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher )
:param dextractor: Descriptor extractor that is used to compute descriptors for an input image and its keypoints.
...
...
@@ -171,11 +175,14 @@ BOWImgDescriptorExtractor::compute
Computes an image descriptor using the set visual vocabulary.
.. ocv:function:: void BOWImgDescriptorExtractor::compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& imgDescriptor, vector<vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 )
.. ocv:function:: void BOWImgDescriptorExtractor::compute( const Mat& descriptors, Mat& imgDescriptor, std::vector<std::vector<int> >* pointIdxsOfClusters )
:param image: Image, for which the descriptor is computed.
:param keypoints: Keypoints detected in the input image.
:param descriptors: Computed descriptors to match with vocabulary.
:param imgDescriptor: Computed output image descriptor.
:param pointIdxsOfClusters: Indices of keypoints that belong to the cluster. This means that ``pointIdxsOfClusters[i]`` are keypoint indices that belong to the ``i`` -th cluster (word of vocabulary) returned if it is non-zero.
...
...
modules/features2d/include/opencv2/features2d.hpp
View file @
46498520
...
...
@@ -1502,12 +1502,15 @@ class CV_EXPORTS BOWImgDescriptorExtractor
public
:
BOWImgDescriptorExtractor
(
const
Ptr
<
DescriptorExtractor
>&
dextractor
,
const
Ptr
<
DescriptorMatcher
>&
dmatcher
);
BOWImgDescriptorExtractor
(
const
Ptr
<
DescriptorMatcher
>&
dmatcher
);
virtual
~
BOWImgDescriptorExtractor
();
void
setVocabulary
(
const
Mat
&
vocabulary
);
const
Mat
&
getVocabulary
()
const
;
void
compute
(
const
Mat
&
image
,
std
::
vector
<
KeyPoint
>&
keypoints
,
Mat
&
imgDescriptor
,
std
::
vector
<
std
::
vector
<
int
>
>*
pointIdxsOfClusters
=
0
,
Mat
*
descriptors
=
0
);
void
compute
(
const
Mat
&
keypointDescriptors
,
Mat
&
imgDescriptor
,
std
::
vector
<
std
::
vector
<
int
>
>*
pointIdxsOfClusters
=
0
);
// compute() is not constant because DescriptorMatcher::match is not constant
int
descriptorSize
()
const
;
...
...
@@ -1519,41 +1522,6 @@ protected:
Ptr
<
DescriptorMatcher
>
dmatcher
;
};
/*
* Class to match image descriptors using bag of visual words.
*/
class
CV_EXPORTS
BOWImgDescriptorMatcher
{
public
:
BOWImgDescriptorMatcher
(
const
Ptr
<
DescriptorMatcher
>&
_dmatcher
);
virtual
~
BOWImgDescriptorMatcher
();
/*
* Compute the matching of the current descriptor according to the vocabulary.
*
* vocDescriptor the descriptors to match
* pointIdxsOfClusters vector of matching
*/
void
compute
(
const
Mat
&
descriptors
,
Mat
&
vocDescriptor
,
std
::
vector
<
std
::
vector
<
int
>
>
*
pointIdxsOfClusters
=
0
);
/*
* Set the vocabulary
*/
void
setVocabulary
(
const
Mat
&
vocabulary
);
const
Mat
&
getVocabulary
()
const
;
int
descriptorSize
()
const
;
int
descriptorType
()
const
;
protected
:
Mat
vocabulary
;
Ptr
<
DescriptorMatcher
>
dmatcher
;
private
:
int
_type
;
};
}
/* namespace cv */
#endif
modules/features2d/src/bagofwords.cpp
View file @
46498520
...
...
@@ -121,6 +121,10 @@ BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorExtrac
dextractor
(
_dextractor
),
dmatcher
(
_dmatcher
)
{}
BOWImgDescriptorExtractor
::
BOWImgDescriptorExtractor
(
const
Ptr
<
DescriptorMatcher
>&
_dmatcher
)
:
dmatcher
(
_dmatcher
)
{}
BOWImgDescriptorExtractor
::~
BOWImgDescriptorExtractor
()
{}
...
...
@@ -144,38 +148,11 @@ void BOWImgDescriptorExtractor::compute( const Mat& image, std::vector<KeyPoint>
if
(
keypoints
.
empty
()
)
return
;
int
clusterCount
=
descriptorSize
();
// = vocabulary.rows
// Compute descriptors for the image.
Mat
descriptors
;
dextractor
->
compute
(
image
,
keypoints
,
descriptors
);
// Match keypoint descriptors to cluster center (to vocabulary)
std
::
vector
<
DMatch
>
matches
;
dmatcher
->
match
(
descriptors
,
matches
);
// Compute image descriptor
if
(
pointIdxsOfClusters
)
{
pointIdxsOfClusters
->
clear
();
pointIdxsOfClusters
->
resize
(
clusterCount
);
}
imgDescriptor
=
Mat
(
1
,
clusterCount
,
descriptorType
(),
Scalar
::
all
(
0.0
)
);
float
*
dptr
=
(
float
*
)
imgDescriptor
.
data
;
for
(
size_t
i
=
0
;
i
<
matches
.
size
();
i
++
)
{
int
queryIdx
=
matches
[
i
].
queryIdx
;
int
trainIdx
=
matches
[
i
].
trainIdx
;
// cluster index
CV_Assert
(
queryIdx
==
(
int
)
i
);
dptr
[
trainIdx
]
=
dptr
[
trainIdx
]
+
1.
f
;
if
(
pointIdxsOfClusters
)
(
*
pointIdxsOfClusters
)[
trainIdx
].
push_back
(
queryIdx
);
}
// Normalize image descriptor.
imgDescriptor
/=
descriptors
.
rows
;
compute
(
descriptors
,
imgDescriptor
,
pointIdxsOfClusters
);
// Add the descriptors of image keypoints
if
(
_descriptors
)
{
...
...
@@ -193,44 +170,16 @@ int BOWImgDescriptorExtractor::descriptorType() const
return
CV_32FC1
;
}
BOWImgDescriptorMatcher
::
BOWImgDescriptorMatcher
(
const
Ptr
<
DescriptorMatcher
>&
_dmatcher
)
:
dmatcher
(
_dmatcher
),
_type
(
-
1
)
{}
BOWImgDescriptorMatcher
::~
BOWImgDescriptorMatcher
()
{}
void
BOWImgDescriptorMatcher
::
setVocabulary
(
const
Mat
&
_vocabulary
)
{
dmatcher
->
clear
();
CV_Assert
(
_vocabulary
.
type
()
==
CV_32F
);
vocabulary
=
_vocabulary
;
dmatcher
->
add
(
std
::
vector
<
Mat
>
(
1
,
vocabulary
)
);
}
const
Mat
&
BOWImgDescriptorMatcher
::
getVocabulary
()
const
void
BOWImgDescriptorExtractor
::
compute
(
const
Mat
&
descriptors
,
Mat
&
imgDescriptor
,
std
::
vector
<
std
::
vector
<
int
>
>*
pointIdxsOfClusters
)
{
return
vocabulary
;
}
CV_Assert
(
vocabulary
.
empty
()
!=
false
);
void
BOWImgDescriptorMatcher
::
compute
(
const
Mat
&
descriptors
,
Mat
&
vocDescriptor
,
std
::
vector
<
std
::
vector
<
int
>
>
*
pointIdxsOfClusters
)
{
vocDescriptor
.
release
();
int
clusterCount
=
descriptorSize
();
// = vocabulary.rows
_type
=
descriptors
.
type
();
Mat
_descriptors
;
if
(
_type
!=
CV_32F
)
descriptors
.
convertTo
(
_descriptors
,
CV_32F
);
else
descriptors
.
copyTo
(
_descriptors
);
// Match keypoint descriptors to cluster center (to vocabulary)
std
::
vector
<
DMatch
>
matches
;
dmatcher
->
match
(
_
descriptors
,
matches
);
dmatcher
->
match
(
descriptors
,
matches
);
// Compute image descriptor
if
(
pointIdxsOfClusters
)
{
...
...
@@ -238,8 +187,8 @@ void BOWImgDescriptorMatcher::compute( const Mat & descriptors, Mat& vocDescript
pointIdxsOfClusters
->
resize
(
clusterCount
);
}
vocDescriptor
=
Mat
::
zeros
(
1
,
clusterCount
,
descriptorType
(
)
);
float
*
dptr
=
(
float
*
)
voc
Descriptor
.
data
;
imgDescriptor
=
Mat
(
1
,
clusterCount
,
descriptorType
(),
Scalar
::
all
(
0.0
)
);
float
*
dptr
=
(
float
*
)
img
Descriptor
.
data
;
for
(
size_t
i
=
0
;
i
<
matches
.
size
();
i
++
)
{
int
queryIdx
=
matches
[
i
].
queryIdx
;
...
...
@@ -252,17 +201,7 @@ void BOWImgDescriptorMatcher::compute( const Mat & descriptors, Mat& vocDescript
}
// Normalize image descriptor.
vocDescriptor
/=
descriptors
.
rows
;
}
int
BOWImgDescriptorMatcher
::
descriptorSize
()
const
{
return
vocabulary
.
empty
()
?
0
:
vocabulary
.
rows
;
}
int
BOWImgDescriptorMatcher
::
descriptorType
()
const
{
return
_type
;
imgDescriptor
/=
descriptors
.
rows
;
}
}
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