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
6eb1426e
Commit
6eb1426e
authored
Jul 02, 2014
by
edgarriba
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First version Ransac (DOESN'T COMPILE)
parent
ada2879f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
2 deletions
+88
-2
solvepnp.cpp
modules/calib3d/src/solvepnp.cpp
+88
-2
No files found.
modules/calib3d/src/solvepnp.cpp
View file @
6eb1426e
...
...
@@ -273,12 +273,72 @@ namespace cv
}
}
class
PnPRansacCallback
:
public
PointSetRegistrator
::
Callback
{
public
:
bool
checkSubset
(
InputArray
_ms1
,
InputArray
_ms2
,
int
count
)
const
{
// which kind of checking??
return
false
;
}
/* Pre: True */
/* Post: compute _model with given points */
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
bool
useExtrinsicGuess
=
true
;
int
flags
=
cv
::
ITERATIVE
;
bool
correspondence
=
cv
::
solvePnP
(
opoints
,
ipoints
,
cameraMatrix
,
distCoeffs
,
rvec
,
tvec
,
useExtrinsicGuess
,
flags
);
return
correspondence
;
}
/* Pre: True */
/* Post: fill _err with projection errors */
void
computeError
(
InputArray
_m1
,
InputArray
_m2
,
InputArray
_model
,
OutputArray
_err
)
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
int
i
,
count
=
opoints
.
cols
;
Mat
projpoints
(
count
,
2
,
CV_64FC1
);
cv
::
projectPoints
(
opoints
,
rvec
,
tvec
,
cameraMatrix
,
distCoeffs
,
projpoints
);
const
Point2f
*
ipoints_ptr
=
ipoints
.
ptr
<
Point2f
>
();
const
Point2f
*
projpoints_ptr
=
projpoints
.
ptr
<
Point2f
>
();
_err
.
create
(
count
,
1
,
CV_64FC1
);
float
*
err
=
_err
.
getMat
().
ptr
<
float
>
();
for
(
i
=
0
;
i
<
count
;
++
i
)
{
err
[
i
]
=
cv
::
norm
(
ipoints_ptr
[
i
]
-
projpoints_ptr
[
i
]
);
}
}
};
void
cv
::
solvePnPRansac
(
InputArray
_opoints
,
InputArray
_ipoints
,
InputArray
_cameraMatrix
,
InputArray
_distCoeffs
,
OutputArray
_rvec
,
OutputArray
_tvec
,
bool
useExtrinsicGuess
,
int
iterationsCount
,
float
reprojectionError
,
int
minInliersCount
,
OutputArray
_inliers
,
int
flags
)
{
// NO CHANGES
Mat
opoints
=
_opoints
.
getMat
(),
ipoints
=
_ipoints
.
getMat
();
Mat
cameraMatrix
=
_cameraMatrix
.
getMat
(),
distCoeffs
=
_distCoeffs
.
getMat
();
...
...
@@ -305,8 +365,34 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
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
);
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 parameters
std
::
vector
<
int
>
localInliers
;
// 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
// OLD IMPLEMENTATION
/*std::vector<int> localInliers;
Mat localRvec, localTvec;
rvec.copyTo(localRvec);
tvec.copyTo(localTvec);
...
...
@@ -345,6 +431,6 @@ void cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
Rodrigues(R, rvec);
if( _inliers.needed() )
_inliers.release();
}
}
*/
return
;
}
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