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
4fbd2ef8
Commit
4fbd2ef8
authored
Jan 21, 2014
by
Andrey Pavlenko
Committed by
OpenCV Buildbot
Jan 21, 2014
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1290 from mbarnach:bow_desc
parents
9eca3ec8
fb9c59dd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
22 deletions
+43
-22
object_categorization.rst
modules/features2d/doc/object_categorization.rst
+7
-0
features2d.hpp
modules/features2d/include/opencv2/features2d.hpp
+3
-0
bagofwords.cpp
modules/features2d/src/bagofwords.cpp
+33
-22
No files found.
modules/features2d/doc/object_categorization.rst
View file @
4fbd2ef8
...
...
@@ -124,6 +124,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 );
...
...
@@ -132,6 +133,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;
...
...
@@ -147,6 +150,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.
...
...
@@ -177,11 +181,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& keypointDescriptors, Mat& imgDescriptor, std::vector<std::vector<int> >* pointIdxsOfClusters=0 )
:param image: Image, for which the descriptor is computed.
:param keypoints: Keypoints detected in the input image.
:param keypointDescriptors: 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 @
4fbd2ef8
...
...
@@ -1512,12 +1512,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
;
...
...
modules/features2d/src/bagofwords.cpp
View file @
4fbd2ef8
...
...
@@ -121,6 +121,10 @@ BOWImgDescriptorExtractor::BOWImgDescriptorExtractor( const Ptr<DescriptorExtrac
dextractor
(
_dextractor
),
dmatcher
(
_dmatcher
)
{}
BOWImgDescriptorExtractor
::
BOWImgDescriptorExtractor
(
const
Ptr
<
DescriptorMatcher
>&
_dmatcher
)
:
dmatcher
(
_dmatcher
)
{}
BOWImgDescriptorExtractor
::~
BOWImgDescriptorExtractor
()
{}
...
...
@@ -137,22 +141,44 @@ const Mat& BOWImgDescriptorExtractor::getVocabulary() const
}
void
BOWImgDescriptorExtractor
::
compute
(
const
Mat
&
image
,
std
::
vector
<
KeyPoint
>&
keypoints
,
Mat
&
imgDescriptor
,
std
::
vector
<
std
::
vector
<
int
>
>*
pointIdxsOfClusters
,
Mat
*
_
descriptors
)
std
::
vector
<
std
::
vector
<
int
>
>*
pointIdxsOfClusters
,
Mat
*
descriptors
)
{
imgDescriptor
.
release
();
if
(
keypoints
.
empty
()
)
return
;
int
clusterCount
=
descriptorSize
();
// = vocabulary.rows
// Compute descriptors for the image.
Mat
descriptors
;
dextractor
->
compute
(
image
,
keypoints
,
descriptors
);
Mat
_descriptors
;
dextractor
->
compute
(
image
,
keypoints
,
_descriptors
);
compute
(
_descriptors
,
imgDescriptor
,
pointIdxsOfClusters
);
// Add the descriptors of image keypoints
if
(
descriptors
)
{
*
descriptors
=
_descriptors
.
clone
();
}
}
int
BOWImgDescriptorExtractor
::
descriptorSize
()
const
{
return
vocabulary
.
empty
()
?
0
:
vocabulary
.
rows
;
}
int
BOWImgDescriptorExtractor
::
descriptorType
()
const
{
return
CV_32FC1
;
}
void
BOWImgDescriptorExtractor
::
compute
(
const
Mat
&
keypointDescriptors
,
Mat
&
imgDescriptor
,
std
::
vector
<
std
::
vector
<
int
>
>*
pointIdxsOfClusters
)
{
CV_Assert
(
vocabulary
.
empty
()
!=
false
);
int
clusterCount
=
descriptorSize
();
// = vocabulary.rows
// Match keypoint descriptors to cluster center (to vocabulary)
std
::
vector
<
DMatch
>
matches
;
dmatcher
->
match
(
d
escriptors
,
matches
);
dmatcher
->
match
(
keypointD
escriptors
,
matches
);
// Compute image descriptor
if
(
pointIdxsOfClusters
)
...
...
@@ -175,22 +201,7 @@ void BOWImgDescriptorExtractor::compute( const Mat& image, std::vector<KeyPoint>
}
// Normalize image descriptor.
imgDescriptor
/=
descriptors
.
rows
;
// Add the descriptors of image keypoints
if
(
_descriptors
)
{
*
_descriptors
=
descriptors
.
clone
();
}
}
int
BOWImgDescriptorExtractor
::
descriptorSize
()
const
{
return
vocabulary
.
empty
()
?
0
:
vocabulary
.
rows
;
}
int
BOWImgDescriptorExtractor
::
descriptorType
()
const
{
return
CV_32FC1
;
imgDescriptor
/=
keypointDescriptors
.
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