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
147f3ebf
Commit
147f3ebf
authored
Feb 28, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
flann: use OpenCV theRNG()
std::rand() has no thread-safe guarantee.
parent
53e68546
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
3 deletions
+34
-3
kdtree_index.h
modules/flann/include/opencv2/flann/kdtree_index.h
+5
-0
lsh_table.h
modules/flann/include/opencv2/flann/lsh_table.h
+4
-0
random.h
modules/flann/include/opencv2/flann/random.h
+25
-3
No files found.
modules/flann/include/opencv2/flann/kdtree_index.h
View file @
147f3ebf
...
...
@@ -125,7 +125,12 @@ public:
/* Construct the randomized trees. */
for
(
int
i
=
0
;
i
<
trees_
;
i
++
)
{
/* Randomize the order of vectors to allow for unbiased sampling. */
#ifndef OPENCV_FLANN_USE_STD_RAND
cv
::
randShuffle
(
vind_
);
#else
std
::
random_shuffle
(
vind_
.
begin
(),
vind_
.
end
());
#endif
tree_roots_
[
i
]
=
divideTree
(
&
vind_
[
0
],
int
(
size_
)
);
}
}
...
...
modules/flann/include/opencv2/flann/lsh_table.h
View file @
147f3ebf
...
...
@@ -350,7 +350,11 @@ inline LshTable<unsigned char>::LshTable(unsigned int feature_size, unsigned int
// A bit brutal but fast to code
std
::
vector
<
size_t
>
indices
(
feature_size
*
CHAR_BIT
);
for
(
size_t
i
=
0
;
i
<
feature_size
*
CHAR_BIT
;
++
i
)
indices
[
i
]
=
i
;
#ifndef OPENCV_FLANN_USE_STD_RAND
cv
::
randShuffle
(
indices
);
#else
std
::
random_shuffle
(
indices
.
begin
(),
indices
.
end
());
#endif
// Generate a random set of order of subsignature_size_ bits
for
(
unsigned
int
i
=
0
;
i
<
key_size_
;
++
i
)
{
...
...
modules/flann/include/opencv2/flann/random.h
View file @
147f3ebf
...
...
@@ -40,13 +40,31 @@
namespace
cvflann
{
inline
int
rand
()
{
#ifndef OPENCV_FLANN_USE_STD_RAND
# if INT_MAX == RAND_MAX
int
v
=
cv
::
theRNG
().
next
()
&
INT_MAX
;
# else
int
v
=
cv
::
theRNG
().
uniform
(
0
,
RAND_MAX
+
1
);
# endif
#else
int
v
=
std
::
rand
();
#endif // OPENCV_FLANN_USE_STD_RAND
return
v
;
}
/**
* Seeds the random number generator
* @param seed Random seed
*/
inline
void
seed_random
(
unsigned
int
seed
)
{
srand
(
seed
);
#ifndef OPENCV_FLANN_USE_STD_RAND
cv
::
theRNG
()
=
cv
::
RNG
(
seed
);
#else
std
::
srand
(
seed
);
#endif
}
/*
...
...
@@ -60,7 +78,7 @@ inline void seed_random(unsigned int seed)
*/
inline
double
rand_double
(
double
high
=
1
.
0
,
double
low
=
0
)
{
return
low
+
((
high
-
low
)
*
(
std
::
rand
()
/
(
RAND_MAX
+
1
.
0
)));
return
low
+
((
high
-
low
)
*
(
rand
()
/
(
RAND_MAX
+
1
.
0
)));
}
/**
...
...
@@ -71,7 +89,7 @@ inline double rand_double(double high = 1.0, double low = 0)
*/
inline
int
rand_int
(
int
high
=
RAND_MAX
,
int
low
=
0
)
{
return
low
+
(
int
)
(
double
(
high
-
low
)
*
(
std
::
rand
()
/
(
RAND_MAX
+
1
.
0
)));
return
low
+
(
int
)
(
double
(
high
-
low
)
*
(
rand
()
/
(
RAND_MAX
+
1
.
0
)));
}
/**
...
...
@@ -107,7 +125,11 @@ public:
for
(
int
i
=
0
;
i
<
size_
;
++
i
)
vals_
[
i
]
=
i
;
// shuffle the elements in the array
#ifndef OPENCV_FLANN_USE_STD_RAND
cv
::
randShuffle
(
vals_
);
#else
std
::
random_shuffle
(
vals_
.
begin
(),
vals_
.
end
());
#endif
counter_
=
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