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
205775ed
Commit
205775ed
authored
Sep 16, 2015
by
Pavel Rojtberg
Committed by
Pavel Rojtberg
Dec 11, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
calibrateCamera: only allocate and compute rvecs, tvecs when needed
also replace C defines with C++ enums
parent
8e67f0ba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
27 deletions
+34
-27
calibration.cpp
modules/calib3d/src/calibration.cpp
+34
-27
No files found.
modules/calib3d/src/calibration.cpp
View file @
205775ed
...
...
@@ -1254,7 +1254,7 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
CV_Error
(
CV_StsUnsupportedFormat
,
"the array of point counters must be 1-dimensional integer vector"
);
//when the thin prism model is used the distortion coefficients matrix must have 12 parameters
if
((
flags
&
C
V_C
ALIB_THIN_PRISM_MODEL
)
&&
(
distCoeffs
->
cols
*
distCoeffs
->
rows
!=
12
))
if
((
flags
&
CALIB_THIN_PRISM_MODEL
)
&&
(
distCoeffs
->
cols
*
distCoeffs
->
rows
!=
12
))
CV_Error
(
CV_StsBadArg
,
"Thin prism model must have 12 parameters in the distortion matrix"
);
nimages
=
npoints
->
rows
*
npoints
->
cols
;
...
...
@@ -1332,14 +1332,14 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
if
(
distCoeffs
->
rows
*
distCoeffs
->
cols
*
CV_MAT_CN
(
distCoeffs
->
type
)
<
8
)
{
if
(
distCoeffs
->
rows
*
distCoeffs
->
cols
*
CV_MAT_CN
(
distCoeffs
->
type
)
<
5
)
flags
|=
C
V_C
ALIB_FIX_K3
;
flags
|=
C
V_CALIB_FIX_K4
|
CV_CALIB_FIX_K5
|
CV_
CALIB_FIX_K6
;
flags
|=
CALIB_FIX_K3
;
flags
|=
C
ALIB_FIX_K4
|
CALIB_FIX_K5
|
CALIB_FIX_K6
;
}
const
double
minValidAspectRatio
=
0.01
;
const
double
maxValidAspectRatio
=
100.0
;
// 1. initialize intrinsic parameters & LM solver
if
(
flags
&
C
V_C
ALIB_USE_INTRINSIC_GUESS
)
if
(
flags
&
CALIB_USE_INTRINSIC_GUESS
)
{
cvConvert
(
cameraMatrix
,
&
matA
);
if
(
A
(
0
,
0
)
<=
0
||
A
(
1
,
1
)
<=
0
)
...
...
@@ -1356,7 +1356,7 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
A
(
0
,
1
)
=
A
(
1
,
0
)
=
A
(
2
,
0
)
=
A
(
2
,
1
)
=
0.
;
A
(
2
,
2
)
=
1.
;
if
(
flags
&
C
V_C
ALIB_FIX_ASPECT_RATIO
)
if
(
flags
&
CALIB_FIX_ASPECT_RATIO
)
{
aspectRatio
=
A
(
0
,
0
)
/
A
(
1
,
1
);
...
...
@@ -1376,7 +1376,7 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
for
(
i
=
0
;
i
<
total
;
i
++
)
matM
.
at
<
Point3d
>
(
i
).
z
=
0.
;
if
(
flags
&
C
V_C
ALIB_FIX_ASPECT_RATIO
)
if
(
flags
&
CALIB_FIX_ASPECT_RATIO
)
{
aspectRatio
=
cvmGet
(
cameraMatrix
,
0
,
0
);
aspectRatio
/=
cvmGet
(
cameraMatrix
,
1
,
1
);
...
...
@@ -1406,8 +1406,8 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
param
[
6
]
=
param
[
7
]
=
0
;
mask
[
6
]
=
mask
[
7
]
=
0
;
}
if
(
!
(
flags
&
C
V_C
ALIB_RATIONAL_MODEL
)
)
flags
|=
C
V_CALIB_FIX_K4
+
CV_CALIB_FIX_K5
+
CV_
CALIB_FIX_K6
;
if
(
!
(
flags
&
CALIB_RATIONAL_MODEL
)
)
flags
|=
C
ALIB_FIX_K4
+
CALIB_FIX_K5
+
CALIB_FIX_K6
;
if
(
!
(
flags
&
CV_CALIB_THIN_PRISM_MODEL
))
flags
|=
CALIB_FIX_S1_S2_S3_S4
;
...
...
@@ -1451,7 +1451,7 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
bool
proceed
=
solver
.
updateAlt
(
_param
,
_JtJ
,
_JtErr
,
_errNorm
);
double
*
param
=
solver
.
param
->
data
.
db
,
*
pparam
=
solver
.
prevParam
->
data
.
db
;
if
(
flags
&
C
V_C
ALIB_FIX_ASPECT_RATIO
)
if
(
flags
&
CALIB_FIX_ASPECT_RATIO
)
{
param
[
0
]
=
param
[
1
]
*
aspectRatio
;
pparam
[
0
]
=
pparam
[
1
]
*
aspectRatio
;
...
...
@@ -1487,9 +1487,9 @@ CV_IMPL double cvCalibrateCamera2( const CvMat* objectPoints,
if
(
solver
.
state
==
CvLevMarq
::
CALC_J
)
{
cvProjectPoints2
(
&
_Mi
,
&
_ri
,
&
_ti
,
&
matA
,
&
_k
,
&
_mp
,
&
_dpdr
,
&
_dpdt
,
(
flags
&
C
V_C
ALIB_FIX_FOCAL_LENGTH
)
?
0
:
&
_dpdf
,
(
flags
&
C
V_C
ALIB_FIX_PRINCIPAL_POINT
)
?
0
:
&
_dpdc
,
&
_dpdk
,
(
flags
&
C
V_C
ALIB_FIX_ASPECT_RATIO
)
?
aspectRatio
:
0
);
(
flags
&
CALIB_FIX_FOCAL_LENGTH
)
?
0
:
&
_dpdf
,
(
flags
&
CALIB_FIX_PRINCIPAL_POINT
)
?
0
:
&
_dpdc
,
&
_dpdk
,
(
flags
&
CALIB_FIX_ASPECT_RATIO
)
?
aspectRatio
:
0
);
}
else
cvProjectPoints2
(
&
_Mi
,
&
_ri
,
&
_ti
,
&
matA
,
&
_k
,
&
_mp
);
...
...
@@ -3215,10 +3215,22 @@ double cv::calibrateCamera( InputArrayOfArrays _objectPoints,
if
(
!
(
flags
&
CALIB_RATIONAL_MODEL
)
&&
(
!
(
flags
&
CALIB_THIN_PRISM_MODEL
)))
distCoeffs
=
distCoeffs
.
rows
==
1
?
distCoeffs
.
colRange
(
0
,
5
)
:
distCoeffs
.
rowRange
(
0
,
5
);
int
i
;
size_t
nimages
=
_objectPoints
.
total
();
int
nimages
=
int
(
_objectPoints
.
total
());
CV_Assert
(
nimages
>
0
);
Mat
objPt
,
imgPt
,
npoints
,
rvecM
((
int
)
nimages
,
3
,
CV_64FC1
),
tvecM
((
int
)
nimages
,
3
,
CV_64FC1
);
Mat
objPt
,
imgPt
,
npoints
,
rvecM
,
tvecM
;
bool
rvecs_needed
=
_rvecs
.
needed
(),
tvecs_needed
=
_tvecs
.
needed
();
if
(
rvecs_needed
)
{
_rvecs
.
create
(
nimages
,
1
,
CV_64FC3
);
rvecM
.
create
(
nimages
,
3
,
CV_64F
);
}
if
(
tvecs_needed
)
{
_tvecs
.
create
(
nimages
,
1
,
CV_64FC3
);
tvecM
.
create
(
nimages
,
3
,
CV_64F
);
}
collectCalibrationData
(
_objectPoints
,
_imagePoints
,
noArray
(),
objPt
,
imgPt
,
0
,
npoints
);
CvMat
c_objPt
=
objPt
,
c_imgPt
=
imgPt
,
c_npoints
=
npoints
;
...
...
@@ -3226,31 +3238,26 @@ double cv::calibrateCamera( InputArrayOfArrays _objectPoints,
CvMat
c_rvecM
=
rvecM
,
c_tvecM
=
tvecM
;
double
reprojErr
=
cvCalibrateCamera2
(
&
c_objPt
,
&
c_imgPt
,
&
c_npoints
,
imageSize
,
&
c_cameraMatrix
,
&
c_distCoeffs
,
&
c_rvecM
,
&
c_tvecM
,
flags
,
criteria
);
&
c_cameraMatrix
,
&
c_distCoeffs
,
rvecs_needed
?
&
c_rvecM
:
NULL
,
tvecs_needed
?
&
c_tvecM
:
NULL
,
flags
,
criteria
);
bool
rvecs_needed
=
_rvecs
.
needed
(),
tvecs_needed
=
_tvecs
.
needed
();
if
(
rvecs_needed
)
_rvecs
.
create
((
int
)
nimages
,
1
,
CV_64FC3
);
if
(
tvecs_needed
)
_tvecs
.
create
((
int
)
nimages
,
1
,
CV_64FC3
);
for
(
i
=
0
;
i
<
(
int
)
nimages
;
i
++
)
for
(
int
i
=
0
;
i
<
nimages
;
i
++
)
{
if
(
rvecs_needed
)
{
_rvecs
.
create
(
3
,
1
,
CV_64F
,
i
,
true
);
Mat
rv
=
_rvecs
.
getMat
(
i
);
memcpy
(
rv
.
ptr
(),
rvecM
.
ptr
<
double
>
(
i
),
3
*
sizeof
(
double
));
memcpy
(
rv
.
ptr
(),
rvecM
.
ptr
(
i
),
3
*
sizeof
(
double
));
}
if
(
tvecs_needed
)
{
_tvecs
.
create
(
3
,
1
,
CV_64F
,
i
,
true
);
Mat
tv
=
_tvecs
.
getMat
(
i
);
memcpy
(
tv
.
ptr
(),
tvecM
.
ptr
<
double
>
(
i
),
3
*
sizeof
(
double
));
memcpy
(
tv
.
ptr
(),
tvecM
.
ptr
(
i
),
3
*
sizeof
(
double
));
}
}
cameraMatrix
.
copyTo
(
_cameraMatrix
);
distCoeffs
.
copyTo
(
_distCoeffs
);
...
...
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