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
a23f1447
Commit
a23f1447
authored
Jan 11, 2014
by
Anatoly Baksheev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor
parent
f930f2f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
24 deletions
+38
-24
precomp.hpp
modules/viz/src/precomp.hpp
+6
-2
shapes.cpp
modules/viz/src/shapes.cpp
+30
-20
tests_simple.cpp
modules/viz/test/tests_simple.cpp
+2
-2
No files found.
modules/viz/src/precomp.hpp
View file @
a23f1447
...
...
@@ -183,10 +183,14 @@ namespace cv
return
isNan
(
data
[
0
])
||
isNan
(
data
[
1
])
||
isNan
(
data
[
2
]);
}
inline
vtkSmartPointer
<
vtkActor
>
getActor
(
const
Widget3D
&
widget
)
{
return
vtkActor
::
SafeDownCast
(
WidgetAccessor
::
getProp
(
widget
));
}
inline
vtkSmartPointer
<
vtkPolyData
>
getPolyData
(
const
Widget3D
&
widget
)
{
vtkSmartPointer
<
vtkProp
>
prop
=
WidgetAccessor
::
getProp
(
widget
);
vtkSmartPointer
<
vtkMapper
>
mapper
=
vtkActor
::
SafeDownCast
(
prop
)
->
GetMapper
();
vtkSmartPointer
<
vtkMapper
>
mapper
=
getActor
(
widget
)
->
GetMapper
();
return
vtkPolyData
::
SafeDownCast
(
mapper
->
GetInput
());
}
...
...
modules/viz/src/shapes.cpp
View file @
a23f1447
...
...
@@ -777,28 +777,34 @@ namespace cv { namespace viz { namespace
return
extract_edges
->
GetOutput
();
}
static
vtkSmartPointer
<
vtkActor
>
projectImage
(
double
fovy
,
double
far_end_height
,
const
Mat
&
image
,
double
scale
,
const
Color
&
color
)
static
vtkSmartPointer
<
vtkActor
>
projectImage
(
vtkSmartPointer
<
vtkPolyData
>
frustum
,
double
far_end_height
,
const
Mat
&
image
,
double
scale
,
const
Color
&
color
)
{
float
aspect_ratio
=
float
(
image
.
cols
)
/
float
(
image
.
rows
);
Mat
color_image
=
image
;
if
(
color_image
.
channels
()
==
1
)
{
color_image
.
create
(
image
.
size
(),
CV_8UC3
);
Vec3b
*
drow
=
color_image
.
ptr
<
Vec3b
>
();
for
(
int
y
=
0
;
y
<
image
.
rows
;
++
y
)
{
const
unsigned
char
*
srow
=
image
.
ptr
<
unsigned
char
>
(
y
);
const
unsigned
char
*
send
=
srow
+
image
.
cols
;
for
(;
srow
<
send
;)
*
drow
++
=
Vec3b
::
all
(
*
srow
++
);
}
}
double
aspect_ratio
=
color_image
.
cols
/
(
double
)
color_image
.
rows
;
// Create the vtk image
vtkSmartPointer
<
vtkImageMatSource
>
source
=
vtkSmartPointer
<
vtkImageMatSource
>::
New
();
source
->
SetImage
(
image
);
source
->
SetImage
(
color_
image
);
source
->
Update
();
vtkSmartPointer
<
vtkImageData
>
vtk_image
=
source
->
GetOutput
();
// Adjust a pixel of the vtk_image
if
(
image
.
channels
()
==
1
)
{
double
gray
=
color
[
2
]
*
0.299
+
color
[
1
]
*
0.578
+
color
[
0
]
*
0.144
;
vtk_image
->
SetScalarComponentFromDouble
(
0
,
0
,
0
,
0
,
gray
);
}
else
{
vtk_image
->
SetScalarComponentFromDouble
(
0
,
0
,
0
,
0
,
color
[
2
]);
vtk_image
->
SetScalarComponentFromDouble
(
0
,
0
,
0
,
1
,
color
[
1
]);
vtk_image
->
SetScalarComponentFromDouble
(
0
,
0
,
0
,
2
,
color
[
0
]);
}
vtk_image
->
SetScalarComponentFromDouble
(
0
,
0
,
0
,
0
,
color
[
2
]);
vtk_image
->
SetScalarComponentFromDouble
(
0
,
0
,
0
,
1
,
color
[
1
]);
vtk_image
->
SetScalarComponentFromDouble
(
0
,
0
,
0
,
2
,
color
[
0
]);
Vec3d
plane_center
(
0.0
,
0.0
,
scale
);
...
...
@@ -824,7 +830,7 @@ namespace cv { namespace viz { namespace
transform_filter
->
SetInputConnection
(
texture_plane
->
GetOutputPort
());
transform_filter
->
SetTransform
(
transform
);
vtkSmartPointer
<
vtkPolyData
>
frustum
=
createFrustum
(
aspect_ratio
,
fovy
,
scale
);
// Frustum needs to be textured or else it can't be combined with image
vtkSmartPointer
<
vtkTextureMapToPlane
>
frustum_texture
=
vtkSmartPointer
<
vtkTextureMapToPlane
>::
New
();
...
...
@@ -901,14 +907,15 @@ cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, double scale, const
cv
::
viz
::
WCameraPosition
::
WCameraPosition
(
const
Matx33d
&
K
,
const
Mat
&
image
,
double
scale
,
const
Color
&
color
)
{
CV_Assert
(
!
image
.
empty
()
&&
image
.
depth
()
==
CV_8U
);
double
f_y
=
K
(
1
,
1
),
c_y
=
K
(
1
,
2
);
// Assuming that this is an ideal camera (c_y and c_x are at the center of the image)
double
fovy
=
2.0
*
atan2
(
c_y
,
f_y
)
*
180.0
/
CV_PI
;
double
far_end_height
=
2.00
*
c_y
*
scale
/
f_y
;
double
aspect_ratio
=
image
.
cols
/
(
double
)
image
.
rows
;
vtkSmartPointer
<
vtkPolyData
>
frustum
=
CameraPositionUtils
::
createFrustum
(
aspect_ratio
,
fovy
,
scale
);
vtkSmartPointer
<
vtkActor
>
actor
=
CameraPositionUtils
::
projectImage
(
f
ovy
,
far_end_height
,
image
,
scale
,
color
);
vtkSmartPointer
<
vtkActor
>
actor
=
CameraPositionUtils
::
projectImage
(
f
rustum
,
far_end_height
,
image
,
scale
,
color
);
WidgetAccessor
::
setProp
(
*
this
,
actor
);
}
...
...
@@ -917,8 +924,11 @@ cv::viz::WCameraPosition::WCameraPosition(const Vec2d &fov, const Mat &image, do
CV_Assert
(
!
image
.
empty
()
&&
image
.
depth
()
==
CV_8U
);
double
fovy
=
fov
[
1
]
*
180.0
/
CV_PI
;
double
far_end_height
=
2.0
*
scale
*
tan
(
fov
[
1
]
*
0.5
);
double
aspect_ratio
=
image
.
cols
/
(
double
)
image
.
rows
;
vtkSmartPointer
<
vtkPolyData
>
frustum
=
CameraPositionUtils
::
createFrustum
(
aspect_ratio
,
fovy
,
scale
);
vtkSmartPointer
<
vtkActor
>
actor
=
CameraPositionUtils
::
projectImage
(
f
ovy
,
far_end_height
,
image
,
scale
,
color
);
vtkSmartPointer
<
vtkActor
>
actor
=
CameraPositionUtils
::
projectImage
(
f
rustum
,
far_end_height
,
image
,
scale
,
color
);
WidgetAccessor
::
setProp
(
*
this
,
actor
);
}
...
...
modules/viz/test/tests_simple.cpp
View file @
a23f1447
...
...
@@ -174,7 +174,7 @@ TEST(Viz, DISABLED_show_trajectories)
viz
.
showWidget
(
"sub1"
,
WTrajectory
(
sub1
,
WTrajectory
::
PATH
,
0.2
,
Color
::
brown
()));
viz
.
showWidget
(
"sub2"
,
WTrajectory
(
sub2
,
WTrajectory
::
FRAMES
,
0.2
));
viz
.
showWidget
(
"sub3"
,
WTrajectory
(
sub3
,
WTrajectory
::
BOTH
,
0.2
,
Color
::
green
()));
viz
.
showWidget
(
"sub4"
,
WTrajectoryFrustums
(
sub4
,
K
,
0.3
));
viz
.
showWidget
(
"sub4"
,
WTrajectoryFrustums
(
sub4
,
K
,
0.3
,
Color
::
yellow
()
));
viz
.
showWidget
(
"sub5"
,
WTrajectoryFrustums
(
sub5
,
Vec2d
(
0.78
,
0.78
),
0.15
));
int
i
=
0
;
...
...
@@ -212,7 +212,7 @@ TEST(Viz, show_camera_positions)
}
Viz3d
viz
(
"show_camera_positions"
);
viz
.
showWidget
(
"sphe"
,
WSphere
(
Point3d
(
0
,
0
,
0
),
1.0
));
viz
.
showWidget
(
"sphe"
,
WSphere
(
Point3d
(
0
,
0
,
0
),
1.0
,
10
,
Color
::
orange_red
()
));
viz
.
showWidget
(
"coos"
,
WCoordinateSystem
(
1.5
));
viz
.
showWidget
(
"pos1"
,
WCameraPosition
(
0.75
),
poses
[
0
]);
viz
.
showWidget
(
"pos2"
,
WCameraPosition
(
Vec2d
(
0.78
,
0.78
),
lena
,
2.2
,
Color
::
green
()),
poses
[
0
]);
...
...
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