This section describes 3D visualization window as well as classes and methods that are used to interact with it.
3D visualization window (see Viz3d
) is used to display widgets (see Widget
), and it provides
several methods to interact with scene and widgets.
Takes coordinate frame data and builds transform to global coordinate frame.
Affine3d viz::
makeTransformToGlobal
(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin=Vec3f::all(0))¶Parameters: |
|
---|
This function returns affine transform that describes transformation between global coordinate frame and a given coordinate frame.
Constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation).
Affine3d makeCameraPose
(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir)¶Parameters: |
|
---|
This function returns pose of the camera in global coordinate frame.
Retrieves a window by its name.
Viz3d getWindowByName
(const String& window_name)¶Parameters: |
|
---|
This function returns a Viz3d
object with the given name.
Note
If the window with that name already exists, that window is returned. Otherwise, new window is created with the given name, and it is returned.
Note
Window names are automatically prefixed by “Viz - ” if it is not done by the user.
/// window and window_2 are the same windows.
viz::Viz3d window = viz::getWindowByName("myWindow");
viz::Viz3d window_2 = viz::getWindowByName("Viz - myWindow");
Checks float/double value for nan.
Checks vector for nan.
- C++:
bool
isNan
(const Vec<_Tp, cn>& v)¶
Parameters:
- v – return true if any of the elements of the vector is nan.
Checks point for nan
- C++:
bool
isNan
(const Point3_<_Tp>& p)¶
Parameters:
- p – return true if any of the elements of the point is nan.
Viz3d
¶The Viz3d class represents a 3D visualizer window. This class is implicitly shared.
class CV_EXPORTS Viz3d
{
public:
typedef cv::Ptr<Viz3d> Ptr;
typedef void (*KeyboardCallback)(const KeyboardEvent&, void*);
typedef void (*MouseCallback)(const MouseEvent&, void*);
Viz3d(const String& window_name = String());
Viz3d(const Viz3d&);
Viz3d& operator=(const Viz3d&);
~Viz3d();
void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity());
void removeWidget(const String &id);
Widget getWidget(const String &id) const;
void removeAllWidgets();
void setWidgetPose(const String &id, const Affine3d &pose);
void updateWidgetPose(const String &id, const Affine3d &pose);
Affine3d getWidgetPose(const String &id) const;
void showImage(InputArray image, const Size& window_size = Size(-1, -1));
void setCamera(const Camera &camera);
Camera getCamera() const;
Affine3d getViewerPose();
void setViewerPose(const Affine3d &pose);
void resetCameraViewpoint (const String &id);
void resetCamera();
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
Size getWindowSize() const;
void setWindowSize(const Size &window_size);
String getWindowName() const;
void saveScreenshot (const String &file);
void setWindowPosition (int x, int y);
void setFullScreen (bool mode);
void setBackgroundColor(const Color& color = Color::black());
void spin();
void spinOnce(int time = 1, bool force_redraw = false);
bool wasStopped() const;
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
void setRenderingProperty(const String &id, int property, double value);
double getRenderingProperty(const String &id, int property);
void setRepresentation(int representation);
private:
/* hidden */
};
The constructors.
Viz3d::
Viz3d
(const String& window_name=String())¶Parameters: |
|
---|
Shows a widget in the window.
void Viz3d::
showWidget
(const String& id, const Widget& widget, const Affine3d& pose=Affine3d::Identity())¶Parameters: |
|
---|
Removes a widget from the window.
void removeWidget
(const String& id)¶Parameters: |
|
---|
Retrieves a widget from the window. A widget is implicitly shared; that is, if the returned widget is modified, the changes will be immediately visible in the window.
Widget getWidget
(const String& id) const
¶Parameters: |
|
---|
Removed all widgets and displays image scaled to whole window area.
void showImage
(InputArray image, const Size& window_size=Size(-1, -1))¶Parameters: |
|
---|
Sets pose of a widget in the window.
void setWidgetPose
(const String& id, const Affine3d& pose)¶Parameters: |
|
---|
Updates pose of a widget in the window by pre-multiplying its current pose.
void updateWidgetPose
(const String& id, const Affine3d& pose)¶Parameters: |
|
---|
Returns the current pose of a widget in the window.
Affine3d getWidgetPose
(const String& id) const
¶Parameters: |
|
---|
Sets the intrinsic parameters of the viewer using Camera.
void setCamera
(const Camera& camera)¶Parameters: |
|
---|
Returns a camera object that contains intrinsic parameters of the current viewer.
Camera getCamera
() const
¶Returns the current pose of the viewer.
..ocv:function:: Affine3d getViewerPose()
Sets pose of the viewer.
void setViewerPose
(const Affine3d& pose)¶Parameters: |
|
---|
Resets camera viewpoint to a 3D widget in the scene.
void resetCameraViewpoint
(const String& id)¶Parameters: |
|
---|
Transforms a point in world coordinate system to window coordinate system.
void convertToWindowCoordinates
(const Point3d& pt, Point3d& window_coord)¶Parameters: |
|
---|
Transforms a point in window coordinate system to a 3D ray in world coordinate system.
void converTo3DRay
(const Point3d& window_coord, Point3d& origin, Vec3d& direction)¶Parameters: |
|
---|
Sets the size of the window.
void setWindowSize
(const Size& window_size)¶Parameters: |
|
---|
Returns the name of the window which has been set in the constructor.
String getWindowName
() const
¶Saves screenshot of the current scene.
void saveScreenshot
(const String& file)¶Parameters: |
|
---|
Sets the position of the window in the screen.
void setWindowPosition
(int x, int y)¶Parameters: |
|
---|
Sets or unsets full-screen rendering mode.
void setFullScreen
(bool mode)¶Parameters: |
|
---|
Sets background color.
void setBackgroundColor
(const Color& color=Color::black())¶Starts the event loop for a given time.
void spinOnce
(int time=1, bool force_redraw=false)¶Parameters: |
|
---|
Sets keyboard handler.
Parameters: |
|
---|
Sets mouse handler.
Parameters: |
|
---|
Sets rendering property of a widget.
void setRenderingProperty
(const String& id, int property, double value)¶Parameters: |
|
---|
Rendering property can be one of the following:
POINT_SIZE
OPACITY
LINE_WIDTH
FONT_SIZE
1
.0
.Returns rendering property of a widget.
double getRenderingProperty
(const String& id, int property)¶Parameters: |
|
---|
Rendering property can be one of the following:
POINT_SIZE
OPACITY
LINE_WIDTH
FONT_SIZE
1
.0
.Sets geometry representation of the widgets to surface, wireframe or points.
void setRepresentation
(int representation)¶Parameters: |
|
---|
Color
¶This class a represents BGR color.
class CV_EXPORTS Color : public Scalar
{
public:
Color();
Color(double gray);
Color(double blue, double green, double red);
Color(const Scalar& color);
static Color black();
static Color blue();
static Color green();
static Color cyan();
static Color red();
static Color magenta();
static Color yellow();
static Color white();
static Color gray();
};
Mesh
¶This class wraps mesh attributes, and it can load a mesh from a ply
file.
class CV_EXPORTS Mesh
{
public:
Mat cloud, colors, normals;
//! Raw integer list of the form: (n,id1,id2,...,idn, n,id1,id2,...,idn, ...)
//! where n is the number of points in the poligon, and id is a zero-offset index into an associated cloud.
Mat polygons;
//! Loads mesh from a given ply file
static Mesh load(const String& file);
};
Loads a mesh from a ply
file.
static Mesh load
(const String& file)¶Parameters: |
|
---|
KeyboardEvent
¶This class represents a keyboard event.
class CV_EXPORTS KeyboardEvent
{
public:
enum { ALT = 1, CTRL = 2, SHIFT = 4 };
enum Action { KEY_UP = 0, KEY_DOWN = 1 };
KeyboardEvent(Action action, const String& symbol, unsigned char code, int modifiers);
Action action;
String symbol;
unsigned char code;
int modifiers;
};
Constructs a KeyboardEvent.
KeyboardEvent
(Action action, const String& symbol, unsigned char code, Modifiers modifiers)¶Parameters: |
|
---|
MouseEvent
¶This class represents a mouse event.
class CV_EXPORTS MouseEvent
{
public:
enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ;
enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ;
MouseEvent(const Type& type, const MouseButton& button, const Point& pointer, int modifiers);
Type type;
MouseButton button;
Point pointer;
int modifiers;
};
Constructs a MouseEvent.
Parameters: |
|
---|
Camera
¶This class wraps intrinsic parameters of a camera. It provides several constructors
that can extract the intrinsic parameters from field of view
, intrinsic matrix
and
projection matrix
.
class CV_EXPORTS Camera
{
public:
Camera(double f_x, double f_y, double c_x, double c_y, const Size &window_size);
Camera(const Vec2d &fov, const Size &window_size);
Camera(const Matx33d &K, const Size &window_size);
Camera(const Matx44d &proj, const Size &window_size);
inline const Vec2d & getClip() const;
inline void setClip(const Vec2d &clip);
inline const Size & getWindowSize() const;
void setWindowSize(const Size &window_size);
inline const Vec2d & getFov() const;
inline void setFov(const Vec2d & fov);
inline const Vec2d & getPrincipalPoint() const;
inline const Vec2d & getFocalLength() const;
void computeProjectionMatrix(Matx44d &proj) const;
static Camera KinectCamera(const Size &window_size);
private:
/* hidden */
};
Constructs a Camera.
Camera
(double f_x, double f_y, double c_x, double c_y, const Size& window_size)¶Parameters: |
|
---|
Camera
(const Vec2d& fov, const Size& window_size)¶Parameters: |
|
---|
Principal point is at the center of the window by default.
Camera
(const Matx33d& K, const Size& window_size)¶Parameters: |
|
---|
Camera
(const Matx44d& proj, const Size& window_size)¶Parameters: |
|
---|