viz: move samples/tutorials to opencv_contrib
@@ -87,7 +87,3 @@ As always, we would be happy to hear your comments and receive your contribution
|
||||
- @subpage tutorial_table_of_content_ios
|
||||
|
||||
Run OpenCV and your vision apps on an iDevice
|
||||
|
||||
- @subpage tutorial_table_of_content_viz
|
||||
|
||||
These tutorials show how to use Viz module effectively.
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
Creating Widgets {#tutorial_creating_widgets}
|
||||
================
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn how to
|
||||
|
||||
- Create your own widgets using WidgetAccessor and VTK.
|
||||
- Show your widget in the visualization window.
|
||||
|
||||
Code
|
||||
----
|
||||
|
||||
You can download the code from [here ](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/viz/creating_widgets.cpp).
|
||||
@include samples/cpp/tutorial_code/viz/creating_widgets.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
Here is the general structure of the program:
|
||||
|
||||
- Extend Widget3D class to create a new 3D widget.
|
||||
@code{.cpp}
|
||||
class WTriangle : public viz::Widget3D
|
||||
{
|
||||
public:
|
||||
WTriangle(const Point3f &pt1, const Point3f &pt2, const Point3f &pt3, const viz::Color & color = viz::Color::white());
|
||||
};
|
||||
@endcode
|
||||
- Assign a VTK actor to the widget.
|
||||
@code{.cpp}
|
||||
// Store this actor in the widget in order that visualizer can access it
|
||||
viz::WidgetAccessor::setProp(*this, actor);
|
||||
@endcode
|
||||
- Set color of the widget.
|
||||
@code{.cpp}
|
||||
// Set the color of the widget. This has to be called after WidgetAccessor.
|
||||
setColor(color);
|
||||
@endcode
|
||||
- Construct a triangle widget and display it in the window.
|
||||
@code{.cpp}
|
||||
/// Create a triangle widget
|
||||
WTriangle tw(Point3f(0.0,0.0,0.0), Point3f(1.0,1.0,1.0), Point3f(0.0,1.0,0.0), viz::Color::red());
|
||||
|
||||
/// Show widget in the visualizer window
|
||||
myWindow.showWidget("TRIANGLE", tw);
|
||||
@endcode
|
||||
|
||||
Results
|
||||
-------
|
||||
|
||||
Here is the result of the program.
|
||||
|
||||

|
||||
|
Before Width: | Height: | Size: 10 KiB |
@@ -1,51 +0,0 @@
|
||||
Creating a 3D histogram {#tutorial_histo3D}
|
||||
================
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn how to
|
||||
|
||||
- Create your own callback keyboard function for viz window.
|
||||
- Show your 3D histogram in a viz window.
|
||||
|
||||
Code
|
||||
----
|
||||
|
||||
You can download the code from [here ](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/viz/histo3D.cpp).
|
||||
@include samples/cpp/tutorial_code/viz/histo3D.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
Here is the general structure of the program:
|
||||
|
||||
- You can give full path to an image in command line
|
||||
@snippet histo3D.cpp command_line_parser
|
||||
|
||||
or without path, a synthetic image is generated with pixel values are a gaussian distribution @ref cv::RNG::fill center(60+/-10,40+/-5,50+/-20) in first quadrant,
|
||||
(160+/-20,10+/-5,50+/-10) in second quadrant, (90+/-10,100+/-20,50+/-20) in third quadrant, (100+/-10,10+/-5,150+/-40) in last quadrant.
|
||||
@snippet histo3D.cpp synthetic_image
|
||||
Image tridimensional histogram is calculated using opencv @ref cv::calcHist and @ref cv::normalize between 0 and 100.
|
||||
@snippet histo3D.cpp calchist_for_histo3d
|
||||
channel are 2, 1 and 0 to synchronise color with Viz axis color in objetc cv::viz::WCoordinateSystem.
|
||||
|
||||
A slidebar is inserted in image window. Init slidebar value is 90, it means that only histogram cell greater than 9/100000.0 (23 pixels for an 512X512 pixels) will be display.
|
||||
@snippet histo3D.cpp slide_bar_for_thresh
|
||||
We are ready to open a viz window with a callback function to capture keyboard event in viz window. Using @ref cv::viz::Viz3d::spinOnce enable keyboard event to be capture in @ref cv::imshow window too.
|
||||
@snippet histo3D.cpp manage_viz_imshow_window
|
||||
The function DrawHistogram3D processes histogram Mat to display it in a Viz window. Number of plan, row and column in [three dimensional Mat](@ref CVMat_Details ) can be found using this code :
|
||||
@snippet histo3D.cpp get_cube_size
|
||||
To get histogram value at a specific location we use @ref cv::Mat::at(int i0,int i1, int i2) method with three arguments k, i and j where k is plane number, i row number and j column number.
|
||||
@snippet histo3D.cpp get_cube_values
|
||||
|
||||
- Callback function
|
||||
Principle are as mouse callback function. Key code pressed is in field code of class @ref cv::viz::KeyboardEvent.
|
||||
@snippet histo3D.cpp viz_keyboard_callback
|
||||
|
||||
Results
|
||||
-------
|
||||
|
||||
Here is the result of the program with no argument and threshold equal to 50.
|
||||
|
||||

|
||||
|
Before Width: | Height: | Size: 839 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
@@ -1,64 +0,0 @@
|
||||
Launching Viz {#tutorial_launching_viz}
|
||||
=============
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn how to
|
||||
|
||||
- Open a visualization window.
|
||||
- Access a window by its name.
|
||||
- Start event loop.
|
||||
- Start event loop for a given amount of time.
|
||||
|
||||
Code
|
||||
----
|
||||
|
||||
You can download the code from [here ](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/viz/launching_viz.cpp).
|
||||
@include samples/cpp/tutorial_code/viz/launching_viz.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
Here is the general structure of the program:
|
||||
|
||||
- Create a window.
|
||||
@code{.cpp}
|
||||
/// Create a window
|
||||
viz::Viz3d myWindow("Viz Demo");
|
||||
@endcode
|
||||
- Start event loop. This event loop will run until user terminates it by pressing **e**, **E**,
|
||||
**q**, **Q**.
|
||||
@code{.cpp}
|
||||
/// Start event loop
|
||||
myWindow.spin();
|
||||
@endcode
|
||||
- Access same window via its name. Since windows are implicitly shared, **sameWindow** is exactly
|
||||
the same with **myWindow**. If the name does not exist, a new window is created.
|
||||
@code{.cpp}
|
||||
/// Access window via its name
|
||||
viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");
|
||||
@endcode
|
||||
- Start a controlled event loop. Once it starts, **wasStopped** is set to false. Inside the while
|
||||
loop, in each iteration, **spinOnce** is called to prevent event loop from completely stopping.
|
||||
Inside the while loop, user can execute other statements including those which interact with the
|
||||
window.
|
||||
@code{.cpp}
|
||||
/// Event loop is over when pressed q, Q, e, E
|
||||
/// Start event loop once for 1 millisecond
|
||||
sameWindow.spinOnce(1, true);
|
||||
while(!sameWindow.wasStopped())
|
||||
{
|
||||
/// Interact with window
|
||||
|
||||
/// Event loop for 1 millisecond
|
||||
sameWindow.spinOnce(1, true);
|
||||
}
|
||||
@endcode
|
||||
|
||||
Results
|
||||
-------
|
||||
|
||||
Here is the result of the program.
|
||||
|
||||

|
||||
@@ -1,42 +0,0 @@
|
||||
OpenCV Viz {#tutorial_table_of_content_viz}
|
||||
==========
|
||||
|
||||
- @subpage tutorial_launching_viz
|
||||
|
||||
*Compatibility:* \> OpenCV 3.0.0
|
||||
|
||||
*Author:* Ozan Tonkal
|
||||
|
||||
You will learn how to launch a viz window.
|
||||
|
||||
- @subpage tutorial_widget_pose
|
||||
|
||||
*Compatibility:* \> OpenCV 3.0.0
|
||||
|
||||
*Author:* Ozan Tonkal
|
||||
|
||||
You will learn how to change pose of a widget.
|
||||
|
||||
- @subpage tutorial_transformations
|
||||
|
||||
*Compatibility:* \> OpenCV 3.0.0
|
||||
|
||||
*Author:* Ozan Tonkal
|
||||
|
||||
You will learn how to transform between global and camera frames.
|
||||
|
||||
- @subpage tutorial_creating_widgets
|
||||
|
||||
*Compatibility:* \> OpenCV 3.0.0
|
||||
|
||||
*Author:* Ozan Tonkal
|
||||
|
||||
You will learn how to create your own widgets.
|
||||
|
||||
- @subpage tutorial_histo3D
|
||||
|
||||
*Compatibility:* \> OpenCV 3.0.0
|
||||
|
||||
*Author:* Laurent Berger
|
||||
|
||||
You will learn how to plot a 3D histogram.
|
||||
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 13 KiB |
@@ -1,88 +0,0 @@
|
||||
Transformations {#tutorial_transformations}
|
||||
===============
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn how to
|
||||
|
||||
- How to use makeTransformToGlobal to compute pose
|
||||
- How to use makeCameraPose and Viz3d::setViewerPose
|
||||
- How to visualize camera position by axes and by viewing frustum
|
||||
|
||||
Code
|
||||
----
|
||||
|
||||
You can download the code from [here ](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/viz/transformations.cpp).
|
||||
@include samples/cpp/tutorial_code/viz/transformations.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
Here is the general structure of the program:
|
||||
|
||||
- Create a visualization window.
|
||||
@code{.cpp}
|
||||
/// Create a window
|
||||
viz::Viz3d myWindow("Transformations");
|
||||
@endcode
|
||||
- Get camera pose from camera position, camera focal point and y direction.
|
||||
@code{.cpp}
|
||||
/// Let's assume camera has the following properties
|
||||
Point3f cam_pos(3.0f,3.0f,3.0f), cam_focal_point(3.0f,3.0f,2.0f), cam_y_dir(-1.0f,0.0f,0.0f);
|
||||
|
||||
/// We can get the pose of the cam using makeCameraPose
|
||||
Affine3f cam_pose = viz::makeCameraPose(cam_pos, cam_focal_point, cam_y_dir);
|
||||
@endcode
|
||||
- Obtain transform matrix knowing the axes of camera coordinate system.
|
||||
@code{.cpp}
|
||||
/// We can get the transformation matrix from camera coordinate system to global using
|
||||
/// - makeTransformToGlobal. We need the axes of the camera
|
||||
Affine3f transform = viz::makeTransformToGlobal(Vec3f(0.0f,-1.0f,0.0f), Vec3f(-1.0f,0.0f,0.0f), Vec3f(0.0f,0.0f,-1.0f), cam_pos);
|
||||
@endcode
|
||||
- Create a cloud widget from bunny.ply file
|
||||
@code{.cpp}
|
||||
/// Create a cloud widget.
|
||||
Mat bunny_cloud = cvcloud_load();
|
||||
viz::WCloud cloud_widget(bunny_cloud, viz::Color::green());
|
||||
@endcode
|
||||
- Given the pose in camera coordinate system, estimate the global pose.
|
||||
@code{.cpp}
|
||||
/// Pose of the widget in camera frame
|
||||
Affine3f cloud_pose = Affine3f().translate(Vec3f(0.0f,0.0f,3.0f));
|
||||
/// Pose of the widget in global frame
|
||||
Affine3f cloud_pose_global = transform * cloud_pose;
|
||||
@endcode
|
||||
- If the view point is set to be global, visualize camera coordinate frame and viewing frustum.
|
||||
@code{.cpp}
|
||||
/// Visualize camera frame
|
||||
if (!camera_pov)
|
||||
{
|
||||
viz::WCameraPosition cpw(0.5); // Coordinate axes
|
||||
viz::WCameraPosition cpw_frustum(Vec2f(0.889484, 0.523599)); // Camera frustum
|
||||
myWindow.showWidget("CPW", cpw, cam_pose);
|
||||
myWindow.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
|
||||
}
|
||||
@endcode
|
||||
- Visualize the cloud widget with the estimated global pose
|
||||
@code{.cpp}
|
||||
/// Visualize widget
|
||||
myWindow.showWidget("bunny", cloud_widget, cloud_pose_global);
|
||||
@endcode
|
||||
- If the view point is set to be camera's, set viewer pose to **cam_pose**.
|
||||
@code{.cpp}
|
||||
/// Set the viewer pose to that of camera
|
||||
if (camera_pov)
|
||||
myWindow.setViewerPose(cam_pose);
|
||||
@endcode
|
||||
|
||||
Results
|
||||
-------
|
||||
|
||||
-# Here is the result from the camera point of view.
|
||||
|
||||

|
||||
|
||||
-# Here is the result from global point of view.
|
||||
|
||||

|
||||
|
Before Width: | Height: | Size: 40 KiB |
@@ -1,85 +0,0 @@
|
||||
Pose of a widget {#tutorial_widget_pose}
|
||||
================
|
||||
|
||||
Goal
|
||||
----
|
||||
|
||||
In this tutorial you will learn how to
|
||||
|
||||
- Add widgets to the visualization window
|
||||
- Use Affine3 to set pose of a widget
|
||||
- Rotating and translating a widget along an axis
|
||||
|
||||
Code
|
||||
----
|
||||
|
||||
You can download the code from [here ](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/viz/widget_pose.cpp).
|
||||
@include samples/cpp/tutorial_code/viz/widget_pose.cpp
|
||||
|
||||
Explanation
|
||||
-----------
|
||||
|
||||
Here is the general structure of the program:
|
||||
|
||||
- Create a visualization window.
|
||||
@code{.cpp}
|
||||
/// Create a window
|
||||
viz::Viz3d myWindow("Coordinate Frame");
|
||||
@endcode
|
||||
- Show coordinate axes in the window using CoordinateSystemWidget.
|
||||
@code{.cpp}
|
||||
/// Add coordinate axes
|
||||
myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
|
||||
@endcode
|
||||
- Display a line representing the axis (1,1,1).
|
||||
@code{.cpp}
|
||||
/// Add line to represent (1,1,1) axis
|
||||
viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));
|
||||
axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);
|
||||
myWindow.showWidget("Line Widget", axis);
|
||||
@endcode
|
||||
- Construct a cube.
|
||||
@code{.cpp}
|
||||
/// Construct a cube widget
|
||||
viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());
|
||||
cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);
|
||||
myWindow.showWidget("Cube Widget", cube_widget);
|
||||
@endcode
|
||||
- Create rotation matrix from rodrigues vector
|
||||
@code{.cpp}
|
||||
/// Rotate around (1,1,1)
|
||||
rot_vec.at<float>(0,0) += CV_PI * 0.01f;
|
||||
rot_vec.at<float>(0,1) += CV_PI * 0.01f;
|
||||
rot_vec.at<float>(0,2) += CV_PI * 0.01f;
|
||||
|
||||
...
|
||||
|
||||
Mat rot_mat;
|
||||
Rodrigues(rot_vec, rot_mat);
|
||||
@endcode
|
||||
- Use Affine3f to set pose of the cube.
|
||||
@code{.cpp}
|
||||
/// Construct pose
|
||||
Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
|
||||
myWindow.setWidgetPose("Cube Widget", pose);
|
||||
@endcode
|
||||
- Animate the rotation using wasStopped and spinOnce
|
||||
@code{.cpp}
|
||||
while(!myWindow.wasStopped())
|
||||
{
|
||||
...
|
||||
|
||||
myWindow.spinOnce(1, true);
|
||||
}
|
||||
@endcode
|
||||
|
||||
Results
|
||||
-------
|
||||
|
||||
Here is the result of the program.
|
||||
|
||||
\htmlonly
|
||||
<div align="center">
|
||||
<iframe width="420" height="315" src="https://www.youtube.com/embed/22HKMN657U0" frameborder="0" allowfullscreen></iframe>
|
||||
</div>
|
||||
\endhtmlonly
|
||||