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
bb057491
Commit
bb057491
authored
Aug 08, 2013
by
ozantonkal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create camera from projection matrix (used for getCamera in viz)
parent
71dc5f82
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
6 deletions
+44
-6
types.hpp
modules/viz/include/opencv2/viz/types.hpp
+1
-0
types.cpp
modules/viz/src/types.cpp
+39
-2
viz3d_impl.cpp
modules/viz/src/viz3d_impl.cpp
+4
-4
No files found.
modules/viz/include/opencv2/viz/types.hpp
View file @
bb057491
...
...
@@ -100,6 +100,7 @@ namespace cv
Camera
(
float
f_x
,
float
f_y
,
float
c_x
,
float
c_y
,
const
Size
&
window_size
);
Camera
(
const
Vec2f
&
fov
,
const
Size
&
window_size
);
Camera
(
const
cv
::
Matx33f
&
K
,
const
Size
&
window_size
);
Camera
(
const
cv
::
Matx44f
&
proj
,
const
Size
&
window_size
);
inline
const
Vec2d
&
getClip
()
const
{
return
clip_
;
}
inline
void
setClip
(
const
Vec2d
&
clip
)
{
clip_
=
clip
;
}
...
...
modules/viz/src/types.cpp
View file @
bb057491
...
...
@@ -170,6 +170,43 @@ cv::viz::Camera::Camera(const cv::Matx33f & K, const Size &window_size)
init
(
f_x
,
f_y
,
c_x
,
c_y
,
window_size
);
}
cv
::
viz
::
Camera
::
Camera
(
const
Matx44f
&
proj
,
const
Size
&
window_size
)
{
double
near
=
proj
(
2
,
3
)
/
(
proj
(
2
,
2
)
-
1.0
);
double
far
=
near
*
(
proj
(
2
,
2
)
-
1.0
)
/
(
proj
(
2
,
2
)
+
1.0
);
double
left
=
near
*
(
proj
(
0
,
2
)
-
1
)
/
proj
(
0
,
0
);
double
right
=
2.0
*
near
/
proj
(
0
,
0
)
+
left
;
double
bottom
=
near
*
(
proj
(
1
,
2
)
-
1
)
/
proj
(
1
,
1
);
double
top
=
2.0
*
near
/
proj
(
1
,
1
)
+
bottom
;
if
(
fabs
(
left
-
right
)
<
std
::
numeric_limits
<
double
>::
epsilon
())
{
principal_point_
[
0
]
=
-
1.0
f
;
focal_
[
0
]
=
-
1.0
f
;
}
else
{
principal_point_
[
0
]
=
(
left
*
static_cast
<
float
>
(
window_size
.
width
))
/
(
left
-
right
);
focal_
[
0
]
=
-
near
*
principal_point_
[
0
]
/
left
;
}
if
(
fabs
(
top
-
bottom
)
<
std
::
numeric_limits
<
double
>::
epsilon
())
{
principal_point_
[
1
]
=
-
1.0
f
;
focal_
[
1
]
=
-
1.0
f
;
}
else
{
principal_point_
[
1
]
=
(
top
*
static_cast
<
float
>
(
window_size
.
height
))
/
(
top
-
bottom
);
focal_
[
1
]
=
near
*
principal_point_
[
1
]
/
top
;
}
setClip
(
Vec2d
(
near
,
far
));
// Set the vertical field of view
fov_
[
1
]
=
(
atan2
(
principal_point_
[
1
],
focal_
[
1
])
+
atan2
(
window_size
.
height
-
principal_point_
[
1
],
focal_
[
1
]));
setWindowSize
(
window_size
);
}
void
cv
::
viz
::
Camera
::
init
(
float
f_x
,
float
f_y
,
float
c_x
,
float
c_y
,
const
Size
&
window_size
)
{
CV_Assert
(
window_size
.
width
>
0
&&
window_size
.
height
>
0
);
...
...
@@ -220,7 +257,7 @@ void cv::viz::Camera::computeProjectionMatrix(Matx44f &proj) const
double
left
=
-
(
top
*
window_size_
.
width
)
/
window_size_
.
height
;
double
right
=
-
left
;
double
bottom
=
-
top
;
// If principal point is defined
// If principal point is defined
(i.e intrinsic parameters are known)
if
(
principal_point_
[
0
]
>
0.0
f
)
{
top
=
clip_
[
0
]
*
principal_point_
[
1
]
/
focal_
[
1
];
...
...
@@ -233,7 +270,7 @@ void cv::viz::Camera::computeProjectionMatrix(Matx44f &proj) const
double
temp2
=
1.0
/
(
right
-
left
);
double
temp3
=
1.0
/
(
top
-
bottom
);
double
temp4
=
1.0
/
(
clip_
[
0
]
-
clip_
[
1
]);
proj
=
Matx44d
::
zeros
();
proj
(
0
,
0
)
=
temp1
*
temp2
;
proj
(
1
,
1
)
=
temp1
*
temp3
;
...
...
modules/viz/src/viz3d_impl.cpp
View file @
bb057491
...
...
@@ -577,7 +577,7 @@ void cv::viz::Viz3d::VizImpl::setCamera(const Camera &camera)
// Use the intrinsic parameters of the camera to simulate more realistically
Matx44f
proj_matrix
;
camera
.
computeProjectionMatrix
(
proj_matrix
);
Matx44f
old_proj_matrix
=
convertToMatx
(
active_camera
.
GetProjectionTransformMatrix
(
((
float
)
camera
.
getWindowSize
().
width
)
/
camera
.
getWindowSize
().
height
,
-
1.0
f
,
1.0
f
));
Matx44f
old_proj_matrix
=
convertToMatx
(
active_camera
.
GetProjectionTransformMatrix
(
static_cast
<
float
>
(
camera
.
getWindowSize
().
width
)
/
static_cast
<
float
>
(
camera
.
getWindowSize
().
height
)
,
-
1.0
f
,
1.0
f
));
vtkTransform
*
transform
=
vtkTransform
::
New
();
// This is a hack around not being able to set Projection Matrix
transform
->
SetMatrix
(
convertToVtkMatrix
(
proj_matrix
*
old_proj_matrix
.
inv
()));
...
...
@@ -594,9 +594,9 @@ cv::viz::Camera cv::viz::Viz3d::VizImpl::getCamera() const
Vec2d
clip
(
active_camera
.
GetClippingRange
());
Size
window_size
(
renderer_
->
GetRenderWindow
()
->
GetSize
()[
0
],
renderer_
->
GetRenderWindow
()
->
GetSize
()[
1
]);
Camera
camera
(
fov
,
window_size
);
camera
.
setClip
(
clip
);
Matx44f
old_proj_matrix
=
convertToMatx
(
active_camera
.
GetProjectionTransformMatrix
(((
float
)
window_size
.
width
)
/
window_size
.
height
,
-
1.0
f
,
1.0
f
));
Camera
camera
(
old_proj_matrix
,
window_size
);
//
camera.setClip(clip);
return
camera
;
}
...
...
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