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
07d92d9e
Commit
07d92d9e
authored
Sep 04, 2012
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix android build warnings
parent
8325a28d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
57 deletions
+57
-57
bowmsctrainer.cpp
modules/contrib/src/bowmsctrainer.cpp
+11
-11
openfabmap.cpp
modules/contrib/src/openfabmap.cpp
+14
-14
haar.cpp
modules/objdetect/src/haar.cpp
+0
-0
pca.cpp
samples/cpp/pca.cpp
+32
-32
No files found.
modules/contrib/src/bowmsctrainer.cpp
View file @
07d92d9e
...
...
@@ -81,46 +81,46 @@ Mat BOWMSCTrainer::cluster() const {
return
cluster
(
mergedDescriptors
);
}
Mat
BOWMSCTrainer
::
cluster
(
const
Mat
&
descriptors
)
const
{
Mat
BOWMSCTrainer
::
cluster
(
const
Mat
&
_
descriptors
)
const
{
CV_Assert
(
!
descriptors
.
empty
());
CV_Assert
(
!
_
descriptors
.
empty
());
// TODO: sort the descriptors before clustering.
Mat
icovar
=
Mat
::
eye
(
descriptors
.
cols
,
descriptors
.
cols
,
descriptors
.
type
());
Mat
icovar
=
Mat
::
eye
(
_descriptors
.
cols
,
_descriptors
.
cols
,
_
descriptors
.
type
());
vector
<
Mat
>
initialCentres
;
initialCentres
.
push_back
(
descriptors
.
row
(
0
));
for
(
int
i
=
1
;
i
<
descriptors
.
rows
;
i
++
)
{
initialCentres
.
push_back
(
_
descriptors
.
row
(
0
));
for
(
int
i
=
1
;
i
<
_
descriptors
.
rows
;
i
++
)
{
double
minDist
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
initialCentres
.
size
();
j
++
)
{
minDist
=
std
::
min
(
minDist
,
cv
::
Mahalanobis
(
descriptors
.
row
(
i
),
initialCentres
[
j
],
cv
::
Mahalanobis
(
_
descriptors
.
row
(
i
),
initialCentres
[
j
],
icovar
));
}
if
(
minDist
>
clusterSize
)
initialCentres
.
push_back
(
descriptors
.
row
(
i
));
initialCentres
.
push_back
(
_
descriptors
.
row
(
i
));
}
std
::
vector
<
std
::
list
<
cv
::
Mat
>
>
clusters
;
clusters
.
resize
(
initialCentres
.
size
());
for
(
int
i
=
0
;
i
<
descriptors
.
rows
;
i
++
)
{
for
(
int
i
=
0
;
i
<
_
descriptors
.
rows
;
i
++
)
{
int
index
=
0
;
double
dist
=
0
,
minDist
=
DBL_MAX
;
for
(
size_t
j
=
0
;
j
<
initialCentres
.
size
();
j
++
)
{
dist
=
cv
::
Mahalanobis
(
descriptors
.
row
(
i
),
initialCentres
[
j
],
icovar
);
dist
=
cv
::
Mahalanobis
(
_
descriptors
.
row
(
i
),
initialCentres
[
j
],
icovar
);
if
(
dist
<
minDist
)
{
minDist
=
dist
;
index
=
(
int
)
j
;
}
}
clusters
[
index
].
push_back
(
descriptors
.
row
(
i
));
clusters
[
index
].
push_back
(
_
descriptors
.
row
(
i
));
}
// TODO: throw away small clusters.
Mat
vocabulary
;
Mat
centre
=
Mat
::
zeros
(
1
,
descriptors
.
cols
,
descriptors
.
type
());
Mat
centre
=
Mat
::
zeros
(
1
,
_descriptors
.
cols
,
_
descriptors
.
type
());
for
(
size_t
i
=
0
;
i
<
clusters
.
size
();
i
++
)
{
centre
.
setTo
(
0
);
for
(
std
::
list
<
cv
::
Mat
>::
iterator
Ci
=
clusters
[
i
].
begin
();
Ci
!=
clusters
[
i
].
end
();
Ci
++
)
{
...
...
modules/contrib/src/openfabmap.cpp
View file @
07d92d9e
...
...
@@ -63,7 +63,7 @@ namespace of2 {
static
double
logsumexp
(
double
a
,
double
b
)
{
return
a
>
b
?
log
(
1
+
exp
(
b
-
a
))
+
a
:
log
(
1
+
exp
(
a
-
b
))
+
b
;
}
FabMap
::
FabMap
(
const
Mat
&
_clTree
,
double
_PzGe
,
double
_PzGNe
,
int
_flags
,
int
_numSamples
)
:
clTree
(
_clTree
),
PzGe
(
_PzGe
),
PzGNe
(
_PzGNe
),
flags
(
...
...
@@ -445,16 +445,16 @@ FabMap1::~FabMap1() {
}
void
FabMap1
::
getLikelihoods
(
const
Mat
&
queryImgDescriptor
,
const
vector
<
Mat
>&
testIm
g
Descriptors
,
vector
<
IMatch
>&
matches
)
{
const
vector
<
Mat
>&
testIm
age
Descriptors
,
vector
<
IMatch
>&
matches
)
{
for
(
size_t
i
=
0
;
i
<
testIm
g
Descriptors
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
testIm
age
Descriptors
.
size
();
i
++
)
{
bool
zq
,
zpq
,
Lzq
;
double
logP
=
0
;
for
(
int
q
=
0
;
q
<
clTree
.
cols
;
q
++
)
{
zq
=
queryImgDescriptor
.
at
<
float
>
(
0
,
q
)
>
0
;
zpq
=
queryImgDescriptor
.
at
<
float
>
(
0
,
pq
(
q
))
>
0
;
Lzq
=
testIm
g
Descriptors
[
i
].
at
<
float
>
(
0
,
q
)
>
0
;
Lzq
=
testIm
age
Descriptors
[
i
].
at
<
float
>
(
0
,
q
)
>
0
;
logP
+=
log
((
this
->*
PzGL
)(
q
,
zq
,
zpq
,
Lzq
));
...
...
@@ -490,16 +490,16 @@ FabMapLUT::~FabMapLUT() {
}
void
FabMapLUT
::
getLikelihoods
(
const
Mat
&
queryImgDescriptor
,
const
vector
<
Mat
>&
testIm
g
Descriptors
,
vector
<
IMatch
>&
matches
)
{
const
vector
<
Mat
>&
testIm
age
Descriptors
,
vector
<
IMatch
>&
matches
)
{
double
precFactor
=
(
double
)
pow
(
10.0
,
-
precision
);
for
(
size_t
i
=
0
;
i
<
testIm
g
Descriptors
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
testIm
age
Descriptors
.
size
();
i
++
)
{
unsigned
long
long
int
logP
=
0
;
for
(
int
q
=
0
;
q
<
clTree
.
cols
;
q
++
)
{
logP
+=
table
[
q
][(
queryImgDescriptor
.
at
<
float
>
(
0
,
pq
(
q
))
>
0
)
+
((
queryImgDescriptor
.
at
<
float
>
(
0
,
q
)
>
0
)
<<
1
)
+
((
testIm
g
Descriptors
[
i
].
at
<
float
>
(
0
,
q
)
>
0
)
<<
2
)];
((
testIm
age
Descriptors
[
i
].
at
<
float
>
(
0
,
q
)
>
0
)
<<
2
)];
}
matches
.
push_back
(
IMatch
(
0
,(
int
)
i
,
-
precFactor
*
(
double
)
logP
,
0
));
}
...
...
@@ -518,7 +518,7 @@ FabMapFBO::~FabMapFBO() {
}
void
FabMapFBO
::
getLikelihoods
(
const
Mat
&
queryImgDescriptor
,
const
vector
<
Mat
>&
testIm
g
Descriptors
,
vector
<
IMatch
>&
matches
)
{
const
vector
<
Mat
>&
testIm
age
Descriptors
,
vector
<
IMatch
>&
matches
)
{
std
::
multiset
<
WordStats
>
wordData
;
setWordStatistics
(
queryImgDescriptor
,
wordData
);
...
...
@@ -526,7 +526,7 @@ void FabMapFBO::getLikelihoods(const Mat& queryImgDescriptor,
vector
<
int
>
matchIndices
;
vector
<
IMatch
>
queryMatches
;
for
(
size_t
i
=
0
;
i
<
testIm
g
Descriptors
.
size
();
i
++
)
{
for
(
size_t
i
=
0
;
i
<
testIm
age
Descriptors
.
size
();
i
++
)
{
queryMatches
.
push_back
(
IMatch
(
0
,(
int
)
i
,
0
,
0
));
matchIndices
.
push_back
((
int
)
i
);
}
...
...
@@ -543,7 +543,7 @@ void FabMapFBO::getLikelihoods(const Mat& queryImgDescriptor,
for
(
size_t
i
=
0
;
i
<
matchIndices
.
size
();
i
++
)
{
bool
Lzq
=
testIm
g
Descriptors
[
matchIndices
[
i
]].
at
<
float
>
(
0
,
wordIter
->
q
)
>
0
;
testIm
age
Descriptors
[
matchIndices
[
i
]].
at
<
float
>
(
0
,
wordIter
->
q
)
>
0
;
queryMatches
[
matchIndices
[
i
]].
likelihood
+=
log
((
this
->*
PzGL
)(
wordIter
->
q
,
zq
,
zpq
,
Lzq
));
currBest
=
...
...
@@ -689,17 +689,17 @@ void FabMap2::add(const vector<Mat>& queryImgDescriptors) {
}
void
FabMap2
::
getLikelihoods
(
const
Mat
&
queryImgDescriptor
,
const
vector
<
Mat
>&
testIm
g
Descriptors
,
vector
<
IMatch
>&
matches
)
{
const
vector
<
Mat
>&
testIm
age
Descriptors
,
vector
<
IMatch
>&
matches
)
{
if
(
&
testIm
gDescriptors
==
&
(
this
->
testImgDescriptors
)
)
{
if
(
&
testIm
ageDescriptors
==
&
testImgDescriptors
)
{
getIndexLikelihoods
(
queryImgDescriptor
,
testDefaults
,
testInvertedMap
,
matches
);
}
else
{
CV_Assert
(
!
(
flags
&
MOTION_MODEL
));
vector
<
double
>
defaults
;
std
::
map
<
int
,
vector
<
int
>
>
invertedMap
;
for
(
size_t
i
=
0
;
i
<
testIm
g
Descriptors
.
size
();
i
++
)
{
addToIndex
(
testIm
g
Descriptors
[
i
],
defaults
,
invertedMap
);
for
(
size_t
i
=
0
;
i
<
testIm
age
Descriptors
.
size
();
i
++
)
{
addToIndex
(
testIm
age
Descriptors
[
i
],
defaults
,
invertedMap
);
}
getIndexLikelihoods
(
queryImgDescriptor
,
defaults
,
invertedMap
,
matches
);
}
...
...
modules/objdetect/src/haar.cpp
View file @
07d92d9e
This diff is collapsed.
Click to expand it.
samples/cpp/pca.cpp
View file @
07d92d9e
/*
* pca.cpp
*
* Author:
* Author:
* Kevin Hughes <kevinhughes27[at]gmail[dot]com>
*
* Special Thanks to:
* Philipp Wagner <bytefish[at]gmx[dot]de>
*
* This program demonstrates how to use OpenCV PCA with a
* This program demonstrates how to use OpenCV PCA with a
* specified amount of variance to retain. The effect
* is illustrated further by using a trackbar to
* change the value for retained varaince.
...
...
@@ -17,9 +17,9 @@
* on this list of images. The author recommends using
* the first 15 faces of the AT&T face data set:
* http://www.cl.cam.ac.uk/research/dtg/attarchive/facedatabase.html
*
*
* so for example your input text file would look like this:
*
*
* <path_to_at&t_faces>/orl_faces/s1/1.pgm
* <path_to_at&t_faces>/orl_faces/s2/1.pgm
* <path_to_at&t_faces>/orl_faces/s3/1.pgm
...
...
@@ -50,7 +50,7 @@ using namespace std;
///////////////////////
// Functions
void
read_imgList
(
const
string
&
filename
,
vector
<
Mat
>&
images
)
{
static
void
read_imgList
(
const
string
&
filename
,
vector
<
Mat
>&
images
)
{
std
::
ifstream
file
(
filename
.
c_str
(),
ifstream
::
in
);
if
(
!
file
)
{
string
error_message
=
"No valid input file was given, please check the given filename."
;
...
...
@@ -62,19 +62,19 @@ void read_imgList(const string& filename, vector<Mat>& images) {
}
}
Mat
formatImagesForPCA
(
const
vector
<
Mat
>
&
data
)
static
Mat
formatImagesForPCA
(
const
vector
<
Mat
>
&
data
)
{
Mat
dst
(
data
.
size
(),
data
[
0
].
rows
*
data
[
0
].
cols
,
CV_32F
);
for
(
unsigned
int
i
=
0
;
i
<
data
.
size
();
i
++
)
{
Mat
image_row
=
data
[
i
].
clone
().
reshape
(
1
,
1
);
Mat
row_i
=
dst
.
row
(
i
);
image_row
.
convertTo
(
row_i
,
CV_32F
);
image_row
.
convertTo
(
row_i
,
CV_32F
);
}
return
dst
;
}
Mat
toGrayscale
(
InputArray
_src
)
{
static
Mat
toGrayscale
(
InputArray
_src
)
{
Mat
src
=
_src
.
getMat
();
// only allow one channel
if
(
src
.
channels
()
!=
1
)
{
...
...
@@ -95,22 +95,22 @@ struct params
string
winName
;
};
void
onTrackbar
(
int
pos
,
void
*
ptr
)
{
static
void
onTrackbar
(
int
pos
,
void
*
ptr
)
{
cout
<<
"Retained Variance = "
<<
pos
<<
"% "
;
cout
<<
"re-calculating PCA..."
<<
std
::
flush
;
double
var
=
pos
/
100.0
;
struct
params
*
p
=
(
struct
params
*
)
ptr
;
p
->
pca
=
PCA
(
p
->
data
,
cv
::
Mat
(),
CV_PCA_DATA_AS_ROW
,
var
);
Mat
point
=
p
->
pca
.
project
(
p
->
data
.
row
(
0
));
Mat
reconstruction
=
p
->
pca
.
backProject
(
point
);
reconstruction
=
reconstruction
.
reshape
(
p
->
ch
,
p
->
rows
);
reconstruction
=
toGrayscale
(
reconstruction
);
imshow
(
p
->
winName
,
reconstruction
);
cout
<<
"done! # of principal components: "
<<
p
->
pca
.
eigenvectors
.
rows
<<
endl
;
}
...
...
@@ -118,19 +118,19 @@ void onTrackbar(int pos, void* ptr)
///////////////////////
// Main
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
if
(
argc
!=
2
)
{
cout
<<
"usage: "
<<
argv
[
0
]
<<
" <image_list.txt>"
<<
endl
;
exit
(
1
);
}
// Get the path to your CSV.
string
imgList
=
string
(
argv
[
1
]);
// vector to hold the images
vector
<
Mat
>
images
;
// Read in the data. This can fail if not valid
try
{
read_imgList
(
imgList
,
images
);
...
...
@@ -138,29 +138,29 @@ int main(int argc, char** argv)
cerr
<<
"Error opening file
\"
"
<<
imgList
<<
"
\"
. Reason: "
<<
e
.
msg
<<
endl
;
exit
(
1
);
}
// Quit if there are not enough images for this demo.
if
(
images
.
size
()
<=
1
)
{
string
error_message
=
"This demo needs at least 2 images to work. Please add more images to your data set!"
;
CV_Error
(
CV_StsError
,
error_message
);
}
// Reshape and stack images into a rowMatrix
Mat
data
=
formatImagesForPCA
(
images
);
// perform PCA
PCA
pca
(
data
,
cv
::
Mat
(),
CV_PCA_DATA_AS_ROW
,
0.95
);
// trackbar is initially set here, also this is a common value for retainedVariance
// Demonstration of the effect of retainedVariance on the first image
// Demonstration of the effect of retainedVariance on the first image
Mat
point
=
pca
.
project
(
data
.
row
(
0
));
// project into the eigenspace, thus the image becomes a "point"
Mat
reconstruction
=
pca
.
backProject
(
point
);
// re-create the image from the "point"
reconstruction
=
reconstruction
.
reshape
(
images
[
0
].
channels
(),
images
[
0
].
rows
);
// reshape from a row vector into image shape
reconstruction
=
toGrayscale
(
reconstruction
);
// re-scale for displaying purposes
// init highgui window
string
winName
=
"Reconstruction | press 'q' to quit"
;
namedWindow
(
winName
,
CV_WINDOW_NORMAL
);
// params struct to pass to the trackbar handler
params
p
;
p
.
data
=
data
;
...
...
@@ -168,17 +168,17 @@ int main(int argc, char** argv)
p
.
rows
=
images
[
0
].
rows
;
p
.
pca
=
pca
;
p
.
winName
=
winName
;
// create the tracbar
int
pos
=
95
;
createTrackbar
(
"Retained Variance (%)"
,
winName
,
&
pos
,
100
,
onTrackbar
,
(
void
*
)
&
p
);
createTrackbar
(
"Retained Variance (%)"
,
winName
,
&
pos
,
100
,
onTrackbar
,
(
void
*
)
&
p
);
// display until user presses q
imshow
(
winName
,
reconstruction
);
char
key
=
0
;
while
(
key
!=
'q'
)
key
=
waitKey
();
return
0
;
return
0
;
}
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