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
eb8c0b8b
Commit
eb8c0b8b
authored
Feb 28, 2011
by
Alexey Spizhevoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parallelized hypotheses evaluation cycle in gpu::solvePnpRansac
parent
cae59a7c
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
31 deletions
+60
-31
gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+0
-2
calib3d.cpp
modules/gpu/src/calib3d.cpp
+59
-29
precomp.hpp
modules/gpu/src/precomp.hpp
+1
-0
No files found.
modules/gpu/include/opencv2/gpu/gpu.hpp
View file @
eb8c0b8b
...
...
@@ -874,13 +874,11 @@ namespace cv
use_extrinsic_guess
(
false
),
num_iters
(
100
),
max_dist
(
2.
f
),
min_num_inliers
(
-
1
),
inliers
(
NULL
)
{}
int
subset_size
;
bool
use_extrinsic_guess
;
int
num_iters
;
float
max_dist
;
int
min_num_inliers
;
vector
<
int
>*
inliers
;
};
...
...
modules/gpu/src/calib3d.cpp
View file @
eb8c0b8b
...
...
@@ -173,46 +173,41 @@ namespace
}
while
(
was
);
}
}
}
void
cv
::
gpu
::
solvePnpRansac
(
const
Mat
&
object
,
const
Mat
&
image
,
const
Mat
&
camera_mat
,
const
Mat
&
dist_coef
,
Mat
&
rvec
,
Mat
&
tvec
,
SolvePnpRansacParams
params
)
{
CV_Assert
(
object
.
rows
==
1
&&
object
.
cols
>
0
&&
object
.
type
()
==
CV_32FC3
);
CV_Assert
(
image
.
rows
==
1
&&
image
.
cols
>
1
&&
image
.
type
()
==
CV_32FC2
);
CV_Assert
(
object
.
cols
==
image
.
cols
);
CV_Assert
(
camera_mat
.
size
()
==
Size
(
3
,
3
)
&&
camera_mat
.
type
()
==
CV_32F
);
CV_Assert
(
dist_coef
.
empty
());
// We don't support undistortion for now
CV_Assert
(
!
params
.
use_extrinsic_guess
);
// We don't support initial guess for now
// Computes rotation, translation pair for small subsets if the input data
class
TransformHypothesesGenerator
{
public
:
TransformHypothesesGenerator
(
const
Mat
&
object_
,
const
Mat
&
image_
,
const
Mat
&
camera_mat_
,
int
num_points_
,
int
subset_size_
,
Mat
rot_matrices_
,
Mat
transl_vectors_
)
:
object
(
&
object_
),
image
(
&
image_
),
camera_mat
(
&
camera_mat_
),
num_points
(
num_points_
),
subset_size
(
subset_size_
),
rot_matrices
(
rot_matrices_
),
transl_vectors
(
transl_vectors_
)
{}
const
int
num_points
=
object
.
cols
;
void
operator
()(
const
BlockedRange
&
range
)
const
{
// We assume that input is undistorted
Mat
empty_dist_coef
;
// Current hypothesis input
vector
<
int
>
subset_indices
(
params
.
subset_size
);
Mat_
<
Point3f
>
object_subset
(
1
,
params
.
subset_size
);
Mat_
<
Point2f
>
image_subset
(
1
,
params
.
subset_size
);
// Input data for generation of the current hypothesis
vector
<
int
>
subset_indices
(
subset_size
);
Mat_
<
Point3f
>
object_subset
(
1
,
subset_size
);
Mat_
<
Point2f
>
image_subset
(
1
,
subset_size
);
// Current hypothesis result
// Current hypothesis data
Mat
rot_vec
(
1
,
3
,
CV_64F
);
Mat
rot_mat
(
3
,
3
,
CV_64F
);
Mat
transl_vec
(
1
,
3
,
CV_64F
);
// All hypotheses results
Mat
rot_matrices
(
1
,
params
.
num_iters
*
9
,
CV_32F
);
Mat
transl_vectors
(
1
,
params
.
num_iters
*
3
,
CV_32F
);
// Generate set of (rotation, translation) hypotheses using small subsets
// of the input data
for
(
int
iter
=
0
;
iter
<
params
.
num_iters
;
++
iter
)
// TODO TBB?
for
(
int
iter
=
range
.
begin
();
iter
<
range
.
end
();
++
iter
)
{
selectRandom
(
params
.
subset_size
,
num_points
,
subset_indices
);
for
(
int
i
=
0
;
i
<
params
.
subset_size
;
++
i
)
selectRandom
(
subset_size
,
num_points
,
subset_indices
);
for
(
int
i
=
0
;
i
<
subset_size
;
++
i
)
{
object_subset
(
0
,
i
)
=
object
.
at
<
Point3f
>
(
subset_indices
[
i
]);
image_subset
(
0
,
i
)
=
image
.
at
<
Point2f
>
(
subset_indices
[
i
]);
object_subset
(
0
,
i
)
=
object
->
at
<
Point3f
>
(
subset_indices
[
i
]);
image_subset
(
0
,
i
)
=
image
->
at
<
Point2f
>
(
subset_indices
[
i
]);
}
solvePnP
(
object_subset
,
image_subset
,
camera_mat
,
dist_coef
,
rot_vec
,
transl_vec
);
solvePnP
(
object_subset
,
image_subset
,
*
camera_mat
,
empty_
dist_coef
,
rot_vec
,
transl_vec
);
// Remember translation vector
Mat
transl_vec_
=
transl_vectors
.
colRange
(
iter
*
3
,
(
iter
+
1
)
*
3
);
...
...
@@ -224,6 +219,40 @@ void cv::gpu::solvePnpRansac(const Mat& object, const Mat& image, const Mat& cam
Mat
rot_mat_
=
rot_matrices
.
colRange
(
iter
*
9
,
(
iter
+
1
)
*
9
).
reshape
(
0
,
3
);
rot_mat
.
convertTo
(
rot_mat_
,
CV_32F
);
}
}
const
Mat
*
object
;
const
Mat
*
image
;
const
Mat
*
camera_mat
;
int
num_points
;
int
subset_size
;
// Hypotheses storage (global)
Mat
rot_matrices
;
Mat
transl_vectors
;
};
}
void
cv
::
gpu
::
solvePnpRansac
(
const
Mat
&
object
,
const
Mat
&
image
,
const
Mat
&
camera_mat
,
const
Mat
&
dist_coef
,
Mat
&
rvec
,
Mat
&
tvec
,
SolvePnpRansacParams
params
)
{
CV_Assert
(
object
.
rows
==
1
&&
object
.
cols
>
0
&&
object
.
type
()
==
CV_32FC3
);
CV_Assert
(
image
.
rows
==
1
&&
image
.
cols
>
0
&&
image
.
type
()
==
CV_32FC2
);
CV_Assert
(
object
.
cols
==
image
.
cols
);
CV_Assert
(
camera_mat
.
size
()
==
Size
(
3
,
3
)
&&
camera_mat
.
type
()
==
CV_32F
);
CV_Assert
(
dist_coef
.
empty
());
// We don't support undistortion for now
CV_Assert
(
!
params
.
use_extrinsic_guess
);
// We don't support initial guess for now
const
int
num_points
=
object
.
cols
;
// Hypotheses storage (global)
Mat
rot_matrices
(
1
,
params
.
num_iters
*
9
,
CV_32F
);
Mat
transl_vectors
(
1
,
params
.
num_iters
*
3
,
CV_32F
);
// Generate set of hypotheses using small subsets of the input data
TransformHypothesesGenerator
body
(
object
,
image
,
camera_mat
,
num_points
,
params
.
subset_size
,
rot_matrices
,
transl_vectors
);
parallel_for
(
BlockedRange
(
0
,
params
.
num_iters
),
body
);
// Compute scores (i.e. number of inliers) for each hypothesis
GpuMat
d_object
(
object
);
...
...
@@ -241,7 +270,7 @@ void cv::gpu::solvePnpRansac(const Mat& object, const Mat& image, const Mat& cam
int
num_inliers
=
static_cast
<
int
>
(
best_score
);
// Extract the best hypothesis data
rot_mat
=
rot_matrices
.
colRange
(
best_idx
.
x
*
9
,
(
best_idx
.
x
+
1
)
*
9
).
reshape
(
0
,
3
);
Mat
rot_mat
=
rot_matrices
.
colRange
(
best_idx
.
x
*
9
,
(
best_idx
.
x
+
1
)
*
9
).
reshape
(
0
,
3
);
Rodrigues
(
rot_mat
,
rvec
);
rvec
=
rvec
.
reshape
(
0
,
1
);
tvec
=
transl_vectors
.
colRange
(
best_idx
.
x
*
3
,
(
best_idx
.
x
+
1
)
*
3
).
clone
();
...
...
@@ -278,3 +307,4 @@ void cv::gpu::solvePnpRansac(const Mat& object, const Mat& image, const Mat& cam
#endif
modules/gpu/src/precomp.hpp
View file @
eb8c0b8b
...
...
@@ -62,6 +62,7 @@
#include "opencv2/gpu/gpu.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/core/internal.hpp"
#if defined(HAVE_CUDA)
...
...
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