Add next and previous navigation links to all tutorials
[platform/upstream/opencv.git] / doc / tutorials / viz / histo3D / histo3D.markdown
1 Creating a 3D histogram {#tutorial_histo3D}
2 ================
3
4 @prev_tutorial{tutorial_creating_widgets}
5
6 Goal
7 ----
8
9 In this tutorial you will learn how to
10
11 -   Create your own callback keyboard function for viz window.
12 -   Show your 3D histogram in a viz window.
13
14 Code
15 ----
16
17 You can download the code from [here ](https://github.com/opencv/opencv/tree/3.4/samples/cpp/tutorial_code/viz/histo3D.cpp).
18 @include samples/cpp/tutorial_code/viz/histo3D.cpp
19
20 Explanation
21 -----------
22
23 Here is the general structure of the program:
24
25 -   You can give full path to an image in command line
26     @snippet histo3D.cpp command_line_parser
27
28     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,
29     (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.
30     @snippet histo3D.cpp synthetic_image
31     Image tridimensional histogram is calculated using opencv @ref cv::calcHist and @ref cv::normalize between 0 and 100.
32     @snippet histo3D.cpp calchist_for_histo3d
33     channel are 2, 1 and 0 to synchronise color with Viz axis color in objetc cv::viz::WCoordinateSystem.
34
35     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.
36     @snippet histo3D.cpp slide_bar_for_thresh
37     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.
38     @snippet histo3D.cpp manage_viz_imshow_window
39     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 :
40     @snippet histo3D.cpp get_cube_size
41     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.
42     @snippet histo3D.cpp get_cube_values
43
44 -   Callback function
45     Principle are as mouse callback function. Key code pressed is in field code of class @ref cv::viz::KeyboardEvent.
46     @snippet histo3D.cpp viz_keyboard_callback
47
48 Results
49 -------
50
51 Here is the result of the program with no argument and threshold equal to 50.
52
53 ![](images/histo50.png)