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
e0c4936c
Commit
e0c4936c
authored
Jul 03, 2014
by
edgarriba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Input/Output Arrays (DOES NOT COMPILE)
parent
6eb1426e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
28 deletions
+45
-28
solvepnp.cpp
modules/calib3d/src/solvepnp.cpp
+45
-28
No files found.
modules/calib3d/src/solvepnp.cpp
View file @
e0c4936c
...
...
@@ -280,26 +280,27 @@ public:
{
// which kind of checking??
return
fals
e
;
return
tru
e
;
}
/* Pre: True */
/* Post: compute _model with given points */
/* Post: compute _model with given points
an eturn number of found models
*/
int
runKernel
(
InputArray
_m1
,
InputArray
_m2
,
OutputArray
_model
)
const
{
Mat
opoints
=
_m1
.
getMat
(),
ipoints
=
_m2
.
getMat
();
Mat
rvec
,
tvec
;
// we supose to get it from _model
Mat
cameraMatrix
;
// we supose to get it from _model
Mat
distCoeffs
;
// we supose to get it from _model
Mat
cameraMatrix
=
_model
.
getMat
(
0
);
Mat
distCoeffs
=
_model
.
getMat
(
1
);
Mat
rvec
=
_model
.
getMat
(
2
);
Mat
tvec
=
_model
.
getMat
(
3
);
int
flags
=
_model
.
getMat
(
4
).
at
<
int
>
(
0
);
bool
useExtrinsicGuess
=
true
;
int
flags
=
cv
::
ITERATIVE
;
bool
correspondence
=
cv
::
solvePnP
(
opoints
,
ipoints
,
cameraMatrix
,
distCoeffs
,
rvec
,
tvec
,
useExtrinsicGuess
,
flags
);
return
correspondence
;
return
1
;
}
/* Pre: True */
...
...
@@ -309,9 +310,10 @@ public:
Mat
opoints
=
_m1
.
getMat
(),
ipoints
=
_m2
.
getMat
();
Mat
rvec
,
tvec
;
// we supose to get it from _model
Mat
cameraMatrix
;
// we supose to get it from _model
Mat
distCoeffs
;
// we supose to get it from _model
Mat
cameraMatrix
=
_model
.
getMat
(
0
);
Mat
distCoeffs
=
_model
.
getMat
(
1
);
Mat
rvec
=
_model
.
getMat
(
2
);
Mat
tvec
=
_model
.
getMat
(
3
);
int
i
,
count
=
opoints
.
cols
;
...
...
@@ -325,9 +327,7 @@ public:
float
*
err
=
_err
.
getMat
().
ptr
<
float
>
();
for
(
i
=
0
;
i
<
count
;
++
i
)
{
err
[
i
]
=
cv
::
norm
(
ipoints_ptr
[
i
]
-
projpoints_ptr
[
i
]
);
}
err
[
i
]
=
cv
::
norm
(
ipoints_ptr
[
i
]
-
projpoints_ptr
[
i
]
);
}
};
...
...
@@ -359,36 +359,53 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
if
(
minInliersCount
<=
0
)
minInliersCount
=
objectPoints
.
cols
;
cv
::
pnpransac
::
Parameters
params
;
params
.
iterationsCount
=
iterationsCount
;
params
.
iterationsCount
=
iterationsCount
;
// maxIters
params
.
minInliersCount
=
minInliersCount
;
params
.
reprojectionError
=
reprojectionError
;
params
.
reprojectionError
=
reprojectionError
;
// threshold
params
.
useExtrinsicGuess
=
useExtrinsicGuess
;
params
.
camera
.
init
(
cameraMatrix
,
distCoeffs
);
params
.
flags
=
flags
;
// END NO CHANGES
// I/O containers
std
::
vector
<
cv
::
Mat
>
out_model
;
out_model
.
push_back
(
rvec
);
out_model
.
push_back
(
tvec
);
cv
::
Mat
flag
(
1
,
1
,
CV_8UC1
);
flag
.
at
<
int
>
(
0
)
=
params
.
flags
;
// Embed input model to a Mat
std
::
vector
<
cv
::
Mat
>
_model
;
_model
.
push_back
(
_cameraMatrix
.
getMat
());
// 3x3
_model
.
push_back
(
_distCoeffs
.
getMat
());
// 4x1
_model
.
push_back
(
_rvec
.
getMat
());
// 3x1
_model
.
push_back
(
_tvec
.
getMat
());
// 3x1
_model
.
push_back
(
flag
);
// 1x1
cv
::
Mat
local_inliers
;
Ptr
<
PointSetRegistrator
::
Callback
>
cb
=
makePtr
<
PnPRansacCallback
>
();
// pointer to callback
int
model_points
=
7
;
// number of model points. From fundamentalMatrix, must change
double
param1
=
params
.
iterationsCount
;
// Ransac parameters
double
param2
=
params
.
reprojectionError
;
// Ransac parameters
int
param3
=
params
.
iterationsCount
;
//
Ransac parameter
s
double
param1
=
params
.
reprojectionError
;
// reprojection error
double
param2
=
0.99
;
// confidence
int
param3
=
params
.
iterationsCount
;
//
number maximum iteration
s
// call Ransac
int
result
=
createRANSACPointSetRegistrator
(
cb
,
model_points
,
param1
,
param2
,
param3
)
->
run
(
objectPoints
,
imagePoints
,
out_model
,
_inliers
);
// NOT COMPILES
//out_model[0].copyTo(_rvec); // out Rvec
//out_model[1].copyTo(_tvec); // out Tvec
// NO COMPILE, IT DOESN'T LIKE vector<Mat> in run
int
result
=
createRANSACPointSetRegistrator
(
cb
,
model_points
,
param1
,
param2
,
param3
)
->
run
(
objectPoints
,
imagePoints
,
_model
,
local_inliers
);
_rvec
.
assign
(
_model
.
at
<
cv
::
Mat
>
(
2
));
// output rotation vector
_tvec
.
assign
(
_model
.
at
<
cv
::
Mat
>
(
3
));
// output translation vector
// output inliers vector
int
count
=
0
;
for
(
int
i
=
0
;
i
<
local_inliers
.
rows
;
++
i
)
{
if
(
local_inliers
.
at
<
int
>
(
i
)
==
1
)
{
cv
::
Mat
&
inliers
=
_inliers
.
getMat
().
at
<
int
>
(
count
)
=
i
;
count
++
;
}
}
// OLD IMPLEMENTATION
...
...
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